翻页提醒

翻页提醒,当用Space或PageDown翻页时,记录上一页最后一行的位置.

目前为 2024-06-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         翻页提醒
// @namespace    https://greasyfork.org/zh-CN/scripts/436765-%E7%BF%BB%E9%A1%B5%E6%8F%90%E9%86%92
// @version      1.2461
// @description  翻页提醒,当用Space或PageDown翻页时,记录上一页最后一行的位置.
// @author       zbhover
// @match        *://*/*
// @require      http://libs.baidu.com/jquery/2.1.4/jquery.min.js
// @require      https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @require           https://registry.npmmirror.com/sweetalert2/10.16.6/files/dist/sweetalert2.min.js
// @resource          swalStyle https://registry.npmmirror.com/sweetalert2/10.16.6/files/dist/sweetalert2.min.css
// @license      MIT
// @grant             GM_getValue
// @grant             GM_setValue
// @grant             GM_registerMenuCommand
// @grant             GM_getResourceText
// ==/UserScript==

(function() {
    'use strict';
    //新建一个div,用于显示一条线
    var newDiv = document.createElement("div");
    newDiv.id="mkLineDiv"
    document.body.appendChild(newDiv);
    $(document).keydown(function(event){
        //翻页按键.Page Down或者SpaceBar
        if(event.keyCode == 34 || event.keyCode==32){
            MarkLine();
        }
    });



    let util = {
        getValue(name) {
            return GM_getValue(name);
        },
        setValue(name, value) {
            GM_setValue(name, value);
        },

    };

    let main = {
        initValue() {
            let value = [{
                name: 'allow_debug',
                value: 'false'
            }, {
                name: 'line_position',
                value: '50'
            }, {
                name: 'line_size',
                value: 32
            }, {
                name: 'line_color',
                value: '#ff0000'
            }, {
                name: 'exclude_list',
                value: []
            }];

            value.forEach((v) => {
                util.getValue(v.name) === undefined && util.setValue(v.name, v.value);
            });
        },

        registerMenuCommand() {
            if (this.isTopWindow()) {
                let whiteList = util.getValue('exclude_list');
                let host = location.host;
                if (whiteList.includes(host)) {
                    GM_registerMenuCommand(' 当前网站:❌', () => {
                        let index = whiteList.indexOf(host);
                        whiteList.splice(index, 1);
                        util.setValue('exclude_list', whiteList);
                        history.go(0);
                    });
                } else {
                    GM_registerMenuCommand(' 当前网站:✔️', () => {
                        whiteList.push(host);
                        util.setValue('exclude_list', Array.from(new Set(whiteList)));
                        history.go(0);
                    });
                }

            GM_registerMenuCommand(' 设置', () => {
                let dom = `<div style="font-size: 1em;">
                              <label class="instant-setting-label">允许 debug:<input type="checkbox" id="S-debug" ${util.getValue('allow_debug',true) ? 'checked' : 'false'} class="instant-setting-checkbox"></label>
                              <label class="instant-setting-label">线的位置 <input type="number" min="1" max="100" id="Line-position" value="${util.getValue('line_position')}" class="instant-setting-input"></label>
                              <label class="instant-setting-label"><span >线长(%)<small id="currentSize">当前:${util.getValue('line_size')}</small></span>
                              <input id="Line-size" type="range" class="instant-setting-label" min="1" max="100" step="2" value="${util.getValue('line_size')}">
                              </label>
                              <label class="instant-setting-label">线的颜色 <input type="color"  id="Line-color" value="${util.getValue('line_color')}"
                              class="instant-setting-input"></label>
                              <label class="instant-setting-label-col">排除下列网址 <textarea placeholder="例如:www.baidu.com" id="Line-exclude" class="instant-setting-textarea">${util.getValue('exclude_list')}</textarea></label>
                              </div>`;
                Swal.fire({
                    title: '翻页提醒配置',
                    html: dom,
                    showCloseButton: true,
                    confirmButtonText: '保存',
                    customClass: {
                        popup: 'instant-popup',
                    },
                }).then((res) => {
                    if (res.isConfirmed) {
                        history.go(0);
                    }
                });

                document.getElementById('S-debug').addEventListener('change', (e) => {
                    util.setValue('allow_debug', e.currentTarget.checked);
                });
                document.getElementById('Line-position').addEventListener('change', (e) => {
                    util.setValue('line_position', e.currentTarget.value);
                    });

                document.getElementById('Line-size').addEventListener('change', (e) => {
                        util.setValue('line_size', e.currentTarget.value);
                        document.getElementById('currentSize').innerText = '当前:' + e.currentTarget.value;
                    });
                document.getElementById('Line-color').addEventListener('change', (e) => {
                    util.setValue('line_color', e.currentTarget.value);
                });
                document.getElementById('Line-exclude').addEventListener('change', (e) => {
                    util.setValue('exclude_list', e.currentTarget.value);
                });
  
            });
            }
        },

        isTopWindow() {
            return window.self === window.top;
        },


        isInExcludeList() {
            return util.getValue('exclude_list').includes(location.host);
        },

        isFullScreen() {
            return document.fullscreenElement;
        },

        isFirefox() {
            return /Firefox/i.test(navigator.userAgent);
        },


        init() {
            this.initValue();
            this.registerMenuCommand();
   //         if(this.isInExcludeList()) return;

        }
    };
    main.init();
    // 标记上一页阅读
function    MarkLine(){
        var htmlHeight = window.pageYOffset + window.innerHeight ;
        var tempStyle="position:absolute;border: 1px solid "+GM_getValue("line_color")+";left:"+GM_getValue("line_position")+"%;top:"+(htmlHeight)+"px;width:"+GM_getValue("line_size")+"%;transform:translate(-50%,-50%);z-index:999999;overflow: visible;";
        var tempStyle2="";
     if (main.isInExcludeList()) return;
 if($(window).scrollTop() + $(window).height() == $(document).height()){
        $("#mkLineDiv").attr("style",tempStyle2);
     return ;
 }
        $("#mkLineDiv").attr("style",tempStyle)
    if(GM_getValue("allow_debug")){
        console.log(tempStyle);
        console.log("当前window.pageYOffset..." + window.pageYOffset);
        console.log("当前document.body.clientHeight..." + document.body.clientHeight);
        console.log("当前window.innerHeight..." + window.innerHeight);
    }
}
})();