// ==UserScript== // @name 翻页提醒 // @namespace https://greasyfork.org/zh-CN/scripts/436765-%E7%BF%BB%E9%A1%B5%E6%8F%90%E9%86%92 // @version 1.2465 // @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://cdn.jsdelivr.net/npm/sweetalert2@11 // @resource SwalJS https://cdn.jsdelivr.net/npm/sweetalert2@11.7.20/dist/sweetalert2.js // @resource SwalCSS https://cdn.jsdelivr.net/npm/sweetalert2@11.7.20/dist/sweetalert2.min.css // @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); }, addStyle(id, tag, css) { tag = tag || 'style'; let doc = document, styleDom = doc.getElementById(id); if (styleDom) return; let style = doc.createElement(tag); style.rel = 'stylesheet'; style.id = id; tag === 'style' ? style.innerHTML = css : style.href = css; doc.head.appendChild(style); }, }; //======================= 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: '保存', 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); }, addPluginStyle() { let style = ` .instant-popup { font-size: 14px !important; } .instant-setting-label { display: flex;align-items: center;justify-content: space-between;padding-top: 15px; } .instant-setting-label-col { display: flex;align-items: flex-start;;padding-top: 15px;flex-direction:column } .instant-setting-checkbox { width: 16px;height: 16px; } .instant-setting-textarea { width: 100%; margin: 14px 0 0; height: 60px; resize: none; border: 1px solid #bbb; box-sizing: border-box; padding: 5px 10px; border-radius: 5px; color: #666; line-height: 1.2; } .instant-setting-input { border: 1px solid #bbb; box-sizing: border-box; padding: 5px 10px; border-radius: 5px; width: 100px} `; util.addStyle('instant-style', 'style', style); }, init() { this.initValue(); this.addPluginStyle(); this.registerMenuCommand(); // if(this.isInExcludeList()) return; } }; main.init(); GM_registerMenuCommand(' 设置',setup); // 标记上一页阅读 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); } } })();