// ==UserScript== // @name 翻页提醒 // @namespace https://greasyfork.org/zh-CN/scripts/436765-%E7%BF%BB%E9%A1%B5%E6%8F%90%E9%86%92 // @version 1.2464 // @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 // @downloadURL none // ==/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 = `
`; Swal.fire({ title: '翻页提醒配置', html: dom, showCloseButton: true, confirmButtonText: '保存', }).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;"; if (main.isInExcludeList()) return; if($(window).scrollTop() + $(window).height() == $(document).height()){ $("#mkLineDiv").attr("style",""); 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); } } })();