// ==UserScript== // @name 手机助手 // @namespace http://tampermonkey.net/ // @version 9.500.19.5 // @description 自动滚动,嗅探图片、视频,字体放大,去除广告浮动 // @author You // @match *://*/* // @run-at document-start // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @license MIT // @downloadURL none // ==/UserScript== { 'use strict'; let hengPin = screen.orientation.lock; (function() { if (document.querySelector('.JqMA-btn-all') || window.frames.length != parent.frames.length) { return; } const currentDomain = window.location.hostname; function docSltAll(selectPath) { let doms = Array.from(document.querySelectorAll(selectPath)); document.querySelectorAll('iframe').forEach(function(iframe) { try { const contentDocument = iframe.contentDocument || iframe.contentWindow.document; if (contentDocument) { const selectedElements = Array.from(contentDocument.querySelectorAll(selectPath)); doms.push(...selectedElements); } } catch (error) { console.error('An error occurred while accessing the iframe:', error); } }); return doms; } function createElement(tagName, attributes = {}, content = '') { let element = document.createElement(tagName); for (var attr in attributes) { if (attributes.hasOwnProperty(attr)) { element.setAttribute(attr, attributes[attr]); } } if (content !== undefined) { element.innerHTML = content; } return element; } function getNextAll(element, _tagName, limit) { let siblings = Array.from(element.parentNode.children); let index = siblings.indexOf(element); let nextAllALtCustom = siblings.slice(index + 1).filter(function(sibling) { return sibling.tagName === _tagName; }); if (limit) { nextAllALtCustom = nextAllALtCustom.slice(0, limit); } return nextAllALtCustom; } let [txtToCData, txtToC] = getDataValue("txtToCData", ""); let [cssToCData, cssToC] = getDataValue("cssToCData", ""); GM_registerMenuCommand('加载点击 查找文本、css 分隔`', function() { const _menu = prompt("1、输入文本\n2、输入css选择器", 1); if (_menu == "1") { const _prot = prompt('页面加载点击 输入文本 分隔`', txtToC); if (_prot === "") { txtToC = ""; delete txtToCData[currentDomain]; } else if (_prot !== null) { txtToC = _prot; txtToCData[currentDomain] = _prot; } GM_setValue("txtToCData", txtToCData); } else if (_menu == "2") { const _prot = prompt('页面加载点击 输入css选择器 分隔`', cssToC); if (_prot === "") { cssToC = ""; delete cssToCData[currentDomain]; } else if (_prot !== null) { cssToC = _prot; cssToCData[currentDomain] = _prot; } GM_setValue("cssToCData", cssToCData); } }); function clickElementsWithTextsOrSelectors(_tToC, _cToC) { if (_tToC.length) { const texts = _tToC.split('`'); for (let i = 0; i < texts.length; i++) { const elements = document.body.getElementsByTagName('*'); for (let j = 0; j < elements.length; j++) { const element = elements[j]; if (element.textContent.includes(texts[i])) { simulateClick(element); element.click(); } } } } if (_cToC.length) { const selectors = _cToC.split('`'); for (let i = 0; i < selectors.length; i++) { const elements = document.querySelectorAll(selectors[i]); for (let j = 0; j < elements.length; j++) { simulateClick(elements[j]); elements[j].click(); } } } } function simulateClick(element) { const event = new MouseEvent('click'); element.dispatchEvent(event); } function removeShadowRoot() { let hasShadowRoot; const divs = document.querySelectorAll('div'); for (let i = 0; i < divs.length; i++) { let _this = divs[i]; if (_this.shadowRoot) { _this.replaceWith(..._this.shadowRoot.childNodes); hasShadowRoot = true; } } alert(hasShadowRoot ? "#shadow-root 已移除" : "#shadow-root 不存在"); } function checkImgExists(imgurl) { return new Promise(function(resolve, reject) { var ImgObj = new Image(); ImgObj.src = imgurl; ImgObj.onload = function(res) { resolve(this); } ImgObj.onerror = function(err) { reject(err) } }); } function getTouchSite(_element, event) { let rect = _element.getBoundingClientRect(); let offsetY = event.touches[0].clientY - rect.top - _element.offsetHeight / 2; let offsetX = event.touches[0].clientX - rect.left - _element.offsetHeight / 2; return [offsetX, offsetY, _element.offsetHeight]; } function getSelector(element) { let path = "", index = 0; while (index < 3 && element && element.nodeType == Node.ELEMENT_NODE) { let selector = element.nodeName.toLowerCase(); if (selector == "body") { break; } if (element.id) { selector += "#" + element.id; } else if (element.classList.length > 0) { selector += "." + Array.from(element.classList).join("."); } path = selector + " > " + path; element = element.parentNode; index++; } return path.replace(/[> ]+$/, ""); } function documentCopy(copyText) { let _input = createElement('input', { style: 'position:fixed!important;clip:rect(0 0 0 0)!important;top:10px!important;', value: copyText }); document.body.appendChild(_input); _input.select(); document.execCommand('copy'); document.body.removeChild(_input); } function copyToClipboard(copyText) { try { navigator.clipboard.writeText(copyText).catch(() => { documentCopy(copyText); }); } catch (error) { documentCopy(copyText); } } function getDataValue(gValName, _default) { let _data = GM_getValue(gValName, {}); let keys = Object.keys(_data); if (keys.length > 200) { delete _data[keys[0]]; GM_setValue(gValName, _data); } return [_data, _data.hasOwnProperty(currentDomain) ? _data[currentDomain] : _default]; } let addCss = GM_getValue("addCss", ""); let hidePagetual = GM_getValue("hidePagetual", 0) GM_registerMenuCommand("1:隐藏按钮 2:隐藏东方 3:添加css", function() { const element = document.querySelector(".JqMA-btn-del"); const isHide = window.getComputedStyle(element).display === "none"; let inputNum = window.prompt("1:" + (isHide ? "显示" : "隐藏") + "按钮 2:" + (hidePagetual ? "显示" : "隐藏") + "东方按钮 3:添加css", 1); if (inputNum === "1") { if (isHide) { document.querySelectorAll(Dhide ? ".JqMA-btn-del" : ".JqMA-btn-all").forEach(function(elet) { elet.style.cssText += "display:block!important;" + (Dhide ? "opacity:0.5!important;" : ""); }); } else { document.querySelectorAll(".JqMA-btn-all").forEach(function(elet) { elet.style.cssText += "display:none!important;"; }); } } else if (inputNum === "2") { hidePagetual = hidePagetual ? 0 : 1; GM_setValue("hidePagetual", hidePagetual); location.reload(false); } else if (inputNum === "3") { inputNum = window.prompt("输入css内容:", addCss); if (inputNum !== null) { GM_setValue("addCss", inputNum); location.reload(false); } } }); function changeDataFunc(_data, _default) { var changeData = window.prompt("请修改:", JSON.stringify(_data)); if (typeof JSON.parse(changeData) == "object") { changeData && alert(changeData); changeData = JSON.parse(changeData) return [changeData, changeData.hasOwnProperty(locHost()) ? changeData[locHost()] : _default] } else { return false; } } var html_style = `html,body { overflow-wrap: break-word!important; scroll-behavior: auto!important; min-height: 100vh!important; }`; var inner_style = `.JqMA-inner-all{ position: relative !important; z-index: 2147483646 !important; margin: 10vh 0 5vh 0!important; border: 0 !important; padding: 0 !important; width: 100% !important; height: auto !important; background: black !important; display: block !important; } .JqMA-inner-all, .JqMA-inner-word *, .JqMA-inner-pic * { box-sizing: border-box !important; border-radius: 0 !important; float: none !important; opacity: 1 !important; visibility: visible !important; overflow-wrap: break-word !important; filter: none!important; -webkit-filter: none!important; } .JqMA-inner-word, .JqMA-inner-word > p { color: #FEFEFE!important; text-align: left!important; font-size: calc(2.3vh + 2.3vw)!important; text-indent: 0!important; } .JqMA-inner-word > p { width: 100%!important; } .JqMA-inner-pic { text-align: center !important; font: 0 "Fira Sans", sans-serif !important; } .JqMA-inner-word *, .JqMA-inner-pic *{ margin: 0 !important; padding: 0 !important; border: 0 !important; position: static !important; } .JqMA-inner-pic *::before, .JqMA-inner-pic *::after { display: none !important; } .JqMA-inner-pic img { display: inline-block !important; width: 100% !important; height: auto !important; object-fit: contain !important; background: gray !important; } .JqMA-inner-pic > *{ vertical-align: top !important; overflow: hidden !important; } .JqMA-inner-word a, .JqMA-inner-pic a, .JqMA-mark-pageNum { background: none!important; color: #FEFEFE!important; height: calc(2.7vh + 2.7vw)!important; font-size: calc(1.7vh + 1.7vw)!important; line-height: 1.4!important; text-align: center!important; } .JqMA-mark-pageNum { width: 100%!important; } html .JqMA-inner-pic > img + a { margin-top: calc(-5.4vh - 5.4vw)!important; } html .JqMA-inner-pic > img + a + a{ margin-top: calc(-2.7vh - 2.7vw)!important; } .JqMA-inner-pic img.JqMA-css-smallPic { width: 12.5%!important; height: 8vw!important; } .JqMA-inner-pic p > a{ display: inline!important; } .JqMA-inner-word > a{ display: inline-block!important; width: 100%!important; } .JqMA-inner-pic > a { display: inline-block!important; width: 12.5%!important; margin-right: 43.75%!important; margin-left: 43.75%!important; background: rgba(0,0,0,0.2)!important; } .JqMA-inner-pic > a.JqMA-css-smallPic { display: none!important; } .JqMA-btn-all, .JqMA-inner-all, .JqMA-inner-pic * { min-width:none!important; max-width:none!important; min-height:none!important; max-height:none!important; } .JqMA-btn-all { overflow: hidden!important; opacity: 1!important; background: rgba(0,0,0,0.4)!important; color: #FEFEFE!important; display: none!important; text-align: center!important; text-indent: 0!important; line-height: 2.8!important; border-radius: 0!important; user-select: none!important; z-index: 999999999999!important; margin: 0!important; padding: 0!important; border: 0!important; font-weight: bold!important; position: fixed!important; font-size: calc(1.2vh + 1.2vw)!important; height: calc(3.2vh + 3.2vw)!important; width: calc(3.2vh + 3.2vw)!important; } html .JqMA-btn-del { display: block!important; opacity: 0.4!important; } `; var css_style = `.JqMA-mark-pageNext:not(.JqMA-mark-pageNum) { display: inline-block !important; height: 0 !important; min-height: none !important; margin: 0 !important; border: 0 !important; padding: 0 !important; overflow: hidden !important; } .JqMA-inner-word,.JqMA-inner-word > p { letter-spacing: normal !important; line-height: normal !important; overflow-wrap: break-word !important; } .JqMA-css-fixed_hide { display: none !important; } .JqMA-css-overY_auto{ overflow-y: auto!important; } .JqMA-css-transform { transform: translate(0%, 0%) !important; padding: 50vh 0!important; height: auto !important; max-height: none !important; }` + addCss; if (hidePagetual) { css_style += `.pagetual_pageBar,#pagetual-sideController { display: inline-block !important; height: 0 !important; min-height: none !important; margin: 0 !important; border: 0 !important; padding: 0 !important; overflow: hidden !important;}`; } function locHost() { return currentDomain; } function getValLoc(gValName, _default) { if (locHost() == GM_getValue(gValName + "_locH")) { return GM_getValue(gValName, _default); } else { return _default; } } function setValLoc(gValName, value) { GM_setValue(gValName, value); GM_setValue(gValName + "_locH", locHost()); } let scrollJu = Math.abs(GM_getValue("scrollJu", 5)); var [DSImgData, DSImg] = getDataValue("DSImgData", 1); let minPicHD = GM_getValue("minPicHD", 500); let minPicwh = GM_getValue("minPicwh", 100), picwh = getValLoc("picwh", minPicwh); let minOuterSz = GM_getValue("minOuterSz", 10), outerSz = getValLoc("outerSz", minOuterSz); let smoothScroll = GM_getValue("smoothScroll", 0); var direction = 1; function addInput(class1, value1, style1) { document.documentElement.appendChild(createElement('p', { class: "JqMA-btn-all " + class1 }, value1)); inner_style += ".JqMA-btn-all." + class1 + "{" + style1 + "!important;left: 0!important;}"; } function addAllBtn() { addInput('JqMA-btn-del', 'X', "top:calc(50vh - 1.6vh - 1.6vw)"); addInput('JqMA-btn-down', '♢', "top:calc(50vh - 4.8vh - 4.8vw)"); addInput('JqMA-btn-Ju', (smoothScroll ? "`" : "") + scrollJu, "top:calc(50vh - 8vh - 8vw)"); addInput('JqMA-btn-width', "W", "top:calc(50vh - 11.2vh - 11.2vw)"); addInput('JqMA-btn-scrollDiv', 'O', "top:calc(50vh - 14.4vh - 14.4vw)"); addInput('JqMA-btn-transform', "T", "top:calc(50vh + 1.6vh + 1.6vw)"); addInput('JqMA-btn-blank ', 'B', "top:calc(50vh + 4.8vh + 4.8vw)"); addInput('JqMA-btn-pic', picwh, "top:calc(50vh + 8vh + 8vw)"); addInput('JqMA-btn-outerSz', outerSz, "top:calc(50vh + 11.2vh + 11.2vw)"); } addAllBtn(); var Dhide = getValLoc("Dhide", 1); delHide(); setTimeout(function() { widthN && document.querySelectorAll(".JqMA-btn-width").forEach(function(element) { element.textContent = widthN; }); picZ && document.querySelectorAll(".JqMA-btn-pic").forEach(function(element) { element.style.setProperty("color", "green", "important"); }); openBlank && document.querySelectorAll(".JqMA-btn-blank").forEach(function(element) { element.style.setProperty("color", "green", "important"); }); DSImg && document.querySelectorAll(".JqMA-btn-outerSz").forEach(function(element) { element.style.setProperty("color", "green", "important"); }); Drotate && document.querySelectorAll(".JqMA-btn-blank").forEach(function(element) { element.textContent = "BF"; }); if (Drotate) { fullScreen(); } if (Dtransform) { applyClearStyle(); document.querySelectorAll(".JqMA-btn-transform").forEach(function(element) { element.style.setProperty("color", "green", "important"); }); } clickElementsWithTextsOrSelectors(txtToC, cssToC); firstRun(); document.documentElement.addEventListener('touchend', function handler(event) { if (Dscroll) { Dscroll = 0; scrollRun(); } event.currentTarget.removeEventListener(event.type, handler); }); }, 800); document.head.appendChild(createElement('style', false, html_style + inner_style + css_style)); document.head.setAttribute("JqMA-mark-addStyle", true); let _timeTouch; function touchRun() { clearTimeout(_timeTouch); _timeTouch = setTimeout(function() { firstRun(); for (let i = 0; i < 12; i++) { setTimeout(function() { _timeTouch && clearTimeout(_timeTouch); }, i * 200); } }, 300); } function htmlTouch(event) { if (Dscroll && !pauseScroll) { let _target = event.target; if (!_target.matches(".JqMA-btn-Ju")) { scrollRun(); if (!_target.matches(".JqMA-btn-down")) { pauseScroll = true; } } } } let oNextScroll; function firstRun() { if (!document.querySelector('.JqMA-btn-all')) { addAllBtn(); } docSltAll("head:not([JqMA-mark-addStyle])").forEach(function(elet) { elet.appendChild(createElement('style', false, css_style)); elet.setAttribute('JqMA-mark-addStyle', true); }); widthN && fontInterFn(); if (picZ) { if (scrollPic && !document.querySelector(".JqMA-inner-pic")) { setTimeout(function() { scrollPicLoad(); }, 500); } else { imgInterFn(); } } openBlank && aOpenBlank(); !Dhide && xiuTan(); document.querySelector(".JqMA-inner-word") && innerWordAdd(); if (!oNextScroll && nextScrollTop) { let element = visibleDiv(); if (element) { autoScrollTo(nextScrollTop); oNextScroll = 1; } } docSltAll("body:not([JqMA-mark-bodyFunc])").forEach(function(elet) { elet.setAttribute('JqMA-mark-bodyFunc', true); elet.addEventListener('click', function(event) { let _target = event.target; if (_target.matches("#JqMA-mark-pageNext_1,#JqMA-mark-pageNext_2")) { pageX.unshift(getScrollTop()); document.querySelector("." + _target.id).scrollIntoView(); } else if (_target.matches("a,a *")) { setTimeout(function() { if (Dscroll) { scrollRun(); pauseScroll = true; } }, 210); } else if (!this.matches("body *") && !_target.matches(pointEle) && _target.offsetWidth > 0.3 * window.innerWidth) { direction = event.clientY < window.innerHeight * 0.2 ? -1 : 1; autoScrollBy(direction * (widthN || Drotate ? 0.9 : 0.45) * window.innerHeight); } if (nextScrollTop) { autoScrollTo(nextScrollTop); } }); }); docSltAll("html:not(html *,[JqMA-mark-htmlFunc])").forEach(function(elet) { elet.setAttribute('JqMA-mark-htmlFunc', true); elet.addEventListener('touchstart', function(event) { htmlTouch(event); }); elet.addEventListener('touchmove', function(event) { htmlTouch(event); }); elet.addEventListener("touchend", function() { touchRun(); stopPause(); }); }); } let pauseScroll; function stopPause() { setTimeout(function() { if (pauseScroll) { pauseScroll = false; Dscroll || scrollRun(); } }, 200); } function onLongPress(element, callback, timeout = 600) { let timer = null; let touchLen = true; element.addEventListener('touchstart', function(event) { timer = setTimeout(function() { if (touchLen) { callback(event); } }, timeout); setTimeout(function() { touchLen = true; }, timeout); }); element.addEventListener('touchend', function() { clearTimeout(timer); }); element.addEventListener('touchmove', function(event) { timer && clearTimeout(timer); if (touchLen && event.touches.length > 1) { touchLen = false; } }); } function onSlideScreen(element, callback, timeout = 600) { let timer = null; element.addEventListener('touchmove', function(event) { timer && clearTimeout(timer); timer = setTimeout(function() { callback(event); }, timeout); }); } let pointEle = GM_getValue("pointEle", ""); if (pointEle === "") { pointEle = "textarea,input,video,button,select"; } function btnScrollDivClick() { const _prot = prompt("点击不下翻元素:", pointEle); if (_prot !== null) { pointEle = _prot; GM_setValue("pointEle", pointEle); } } let pageX = []; let widthN = getValLoc("widthN", 0); let picZ = getValLoc("picZ", 0); let openBlank = getValLoc("openBlank", 0); let preIframes = new Set(); let Dscroll = getValLoc("Dscroll", 0); let timeDown; document.documentElement.addEventListener('click', function(event) { const eventClass = event.target.classList; if (eventClass.contains('JqMA-btn-down')) { btnDownClick(); } else if (eventClass.contains('JqMA-btn-scrollDiv')) { btnScrollDivClick(); } else if (eventClass.contains('JqMA-btn-transform')) { btnTransfClick(); } else if (eventClass.contains('JqMA-btn-width')) { btnWidthClick(); } else if (eventClass.contains('JqMA-btn-outerSz')) { btnOuterSzClick(); } else if (eventClass.contains('JqMA-btn-pic')) { btnPicClick(); } else if (eventClass.contains('JqMA-btn-del')) { btnDelClick(); } else if (eventClass.contains('JqMA-btn-blank')) { btnBlankClick(); } else if (eventClass.contains('JqMA-btn-Ju')) { btnJuClick(); } }); let Dtransform = getValLoc("Dtransform", 0); GM_registerMenuCommand(`去浮动:${Dtransform ? "开": '关'}`, function() { btnTransfClick(); }); onSlideScreen(document.documentElement, function(event) { const eventClass = event.target.classList; if (eventClass.contains('JqMA-btn-Ju')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > thisHeight) { scrollJu -= 1; } else if (offsetY < -thisHeight || offsetX > thisHeight) { scrollJu += 1; } else { btnJuClick(); return; } scrollJu = Math.max(scrollJu, 0); document.querySelector(".JqMA-btn-Ju").forEach(function(_this) { _this.textContent = (smoothScroll ? "`" : "") + scrollJu; }); GM_setValue("scrollJu", scrollJu); } else if (eventClass.contains('JqMA-btn-blank')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > thisHeight || offsetY < -thisHeight || offsetX > thisHeight) { let firstTarget; document.querySelectorAll(".JqMA-btn-all").forEach(function(_this) { _this.style.setProperty("display", "none", "important"); }); setTimeout(function() { docSltAll("body:not(body *)").forEach(function(_this) { _this.addEventListener('click', tempClickFunc); }); function tempClickFunc(event) { event.preventDefault(); if (!firstTarget) { firstTarget = event.target; return; } docSltAll("body").forEach(function(_this) { _this.removeEventListener('click', tempClickFunc); }); document.querySelectorAll(".JqMA-btn-all").forEach(function(_this) { _this.style.setProperty("display", "block", "important"); }); let isInput = firstTarget.matches("a") || firstTarget.closest("a") ? 0 : 1; if (firstTarget === event.target) copyToClipboard(getSelector(event.target)); firstTarget = firstTarget.closest(isInput ? "input" : "a"); let lastTarget = event.target.closest(isInput ? "input" : "a"); if (firstTarget && lastTarget) { let first_aCss; docSltAll(isInput ? "input" : "a").forEach(el => { if (el === firstTarget) first_aCss = true; if (first_aCss) { if (isInput) { el.checked = true; } else if (el.href && !preIframes.has(el.href)) { preIframes.add(el.href); let iframe = createElement("iframe", { src: el.href, scrolling: "no", sandbox: 'allow-scripts allow-same-origin', style: "box-sizing: border-box !important; overflow: hidden !important; width: 100% !important; min-height: 150vh!important;" }); iframe.onload = function() { let _this = this; setTimeout(function() { if (_this.contentDocument.body.childNodes.length) { _this.parentNode.replaceChild(_this.contentDocument.body, _this); } }, 1000); }; document.body.appendChild(createElement('p', { class: "pagetual_pageBar" })); document.body.appendChild(iframe); } if (el === lastTarget) first_aCss = false; } }); } else { alert("请点击链接或复选框!"); } } }, 100); } else { btnBlankClick(); } } else if (eventClass.contains('JqMA-btn-del')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetX > thisHeight || offsetY > thisHeight || offsetY < -thisHeight) { let loadNow = document.querySelector("#pagetual-sideController #loadNow"); if (loadNow) { loadNow.dispatchEvent(new MouseEvent('click')); } else { alert("请启用 东方永夜机 立即翻页"); } } else { btnDelClick(); } } else if (eventClass.contains('JqMA-btn-pic')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > thisHeight * 3 || offsetY < thisHeight * -3 || offsetX > thisHeight * 3) { btnPicwhClick(); } else if (offsetY > thisHeight) { if (minPicwh < picwh && picwh < minPicwh + 40) { picwh = minPicwh; } else if (picwh <= minPicwh) { picwh = 0 } else { picwh -= 40; } picImgFilter(); } else if (offsetY < -thisHeight || offsetX > thisHeight) { if (picwh == 0) { picwh = minPicwh; } else { picwh += 40; } picImgFilter(); } else { btnPicClick(); } } else if (eventClass.contains('JqMA-btn-outerSz')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > thisHeight * 3 || offsetY < thisHeight * -3 || offsetX > thisHeight * 3) { scrollPic = confirm("是否滚动加载图片?"); setValLoc("scrollPic", scrollPic); scrollPic && scrollPicLoad(); } else if (offsetY > thisHeight) { if (minOuterSz < outerSz && outerSz < minOuterSz + 10) { outerSz = minOuterSz; } else if (outerSz <= 1) { outerSz = 0; } else if (outerSz <= minOuterSz) { outerSz = 1; } else { outerSz -= 10; } } else if (offsetY < -thisHeight || offsetX > thisHeight) { if (outerSz === 0) { outerSz = 1; } else if (outerSz === 1) { outerSz = minOuterSz; } else { outerSz += 10; } } else { btnOuterSzClick(); } outerSz_run(); } else if (eventClass.contains('JqMA-btn-width')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > 3 * thisHeight || offsetY < -3 * thisHeight || offsetX > 3 * thisHeight) { readPause(); } else if (offsetY > thisHeight) { widthN -= 1; } else if (offsetY < -thisHeight || offsetX > thisHeight) { widthN += 1; } else { btnWidthClick(); return; } widthNFunc(); } else if (eventClass.contains('JqMA-btn-transform')) { btnTransfClick(); } else if (eventClass.contains('JqMA-btn-scrollDiv')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > thisHeight || offsetY < -thisHeight || offsetX > thisHeight) { removeShadowRoot(); } else { btnScrollDivClick(); } } else if (eventClass.contains('JqMA-btn-down')) { let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event); if (offsetY > thisHeight * 3) { pageX.unshift(getScrollTop()); autoScrollTo(0); document.querySelectorAll(".JqMA-btn-down").forEach(function(elet) { elet.textContent = "♢"; }); } else if (offsetY < thisHeight * -3 || offsetX > thisHeight * 3) { pageX.unshift(getScrollTop()); autoScrollTo(visibleDiv().scrollHeight); document.querySelectorAll(".JqMA-btn-down").forEach(function(elet) { elet.textContent = "♢"; }); } else if (offsetY > thisHeight) { pageNextFunc("up"); } else if (offsetY < -thisHeight || offsetX > thisHeight) { pageNextFunc("down"); } else { btnDownClick(); } } }); onLongPress(document.documentElement, function(event) { const eventClass = event.target.classList; if (eventClass.contains('JqMA-btn-Ju')) { let inputNum = window.prompt("请输入滚动速度(以`开头表间隔):", (smoothScroll ? "`" : "") + scrollJu); smoothScroll = inputNum.startsWith("`") ? 1 : 0; if (Number(inputNum.replace("`", ""))) { scrollJu = Number(inputNum.replace("`", "")); scrollJu = Math.max(scrollJu, 0); document.querySelectorAll(".JqMA-btn-Ju", "all").forEach(function(_this) { _this.textContent = (smoothScroll ? "`" : "") + scrollJu; }); GM_setValue("scrollJu", scrollJu); GM_setValue("smoothScroll", smoothScroll); } } else if (eventClass.contains('JqMA-btn-blank')) { Drotate = Drotate ? 0 : 1; if (Drotate) { let width = prompt("页面宽度:", Drotate_W); if (width === null) return Drotate_W = Number(width); setValLoc("Drotate_W", Drotate_W); fullScreen(); } else { document.exitFullscreen(); docSltAll("style#fullScreenBody").forEach(function(_this) { _this.innerHTML = ""; }); } document.querySelectorAll(".JqMA-btn-blank").forEach(function(_this) { _this.textContent = Drotate ? "BF" : "B"; }); setValLoc("Drotate", Drotate); } else if (eventClass.contains('JqMA-btn-del')) { let newHref; if (/[^a-z]page[=/]\d+(?=$|&)/.test(location.href)) { let hrefSplit = location.href.split(/(?<=[^a-z]page)([=/])(?=\d)/); openHref(getNextPage(hrefSplit)); return; } else if (/[/_\-]\d+(\.html)?$/.test(location.href)) { let hrefSplit = location.href.split(/([/_\-])(?=\d+(?:\.html)?$)/); newHref = getNextPage(hrefSplit); } let pageEnter; let allA = docSltAll("a"); allA.reverse(); for (let i = 0; i < allA.length; i++) { let _this = allA[i]; if (/^\s*2\s*$/.test(_this.textContent) && /[^a-z]page[=/]\d+(?=$|&)/.test(_this.href)) { pageEnter = 1; openHref(_this.href); break; } else if (/^\s*(>|次のページ|下.?[章页]|下[一—].)\s*$|^\s*next\s*(page\s*)?$/i.test(_this.textContent)) { pageEnter = 1; _this.click(); break; } else if (newHref && _this.href === newHref) { pageEnter = 1; openHref(newHref); break; } } if (!pageEnter && /[^a-z\d]\d+$/.test(location.href)) { let hrefSplit = location.href.split(/([^a-z\d])(?=\d+$)/); openHref(getNextPage(hrefSplit)); } } else if (eventClass.contains('JqMA-btn-outerSz')) { DSImg = DSImg ? 0 : 1; document.querySelectorAll(".JqMA-btn-outerSz").forEach(function(_this) { _this.style.setProperty("color", DSImg ? "green" : null, "important"); }); if (picZ) { let _scrollTop = getScrollTop(); removePicClass(); imgInterFn(); setTimeout(function() { autoScrollTo(_scrollTop); }, 400); } if (DSImg) { delete DSImgData[locHost()]; } else { DSImgData[locHost()] = DSImg; } GM_setValue("DSImgData", DSImgData); } else if (eventClass.contains('JqMA-btn-pic')) { waitClick(function(event) { if (event.target.currentSrc && window.confirm("是否复制图片链接?")) copyToClipboard(event.target.currentSrc); setTimeout(function() { var inputNum = window.prompt("请输入图片链接替换(`分隔,@开头:正则且数字->[0-9]):", picReplace); if (inputNum == "所有域名") { var resultData = changeDataFunc(picRepData, ""); if (resultData)[picRepData, picReplace] = resultData; } else if (typeof inputNum === "string") { picReplace = inputNum; if (picReplace === "") { delete picRepData[locHost()]; } else { picRepData[locHost()] = picReplace; if (picZ) { var _scrollTop = getScrollTop(); removePicClass(); imgInterFn(); setTimeout(function() { autoScrollTo(_scrollTop); }, 400); } } } GM_setValue("picRepData", picRepData); }, 200); }); } else if (eventClass.contains('JqMA-btn-width')) { let noFirstR; if (document.querySelector(".JqMA-inner-word")) { document.querySelectorAll(".JqMA-inner-word").forEach(function(element) { element.remove(); }); docSltAll("[JqMA-mark-word]").forEach(function(element) { element.removeAttribute("JqMA-mark-word"); }); noFirstR = 1; } else { document.querySelectorAll('.JqMA-btn-width').forEach(function(_this) { _this.style.setProperty("color", "green", "important"); }); } if (noFirstR || !textSlt.length) { waitClick(function(event) { let _target = event.target; while (true) { if (_target.matches("body") || getText(_target).replace(/\s+/g, "").length > 50) { break; } else { _target = _target.parentNode; } } let selector = getSelector(_target); if (noFirstR) { let inputNum = window.prompt(`修改选择器:${selector}`, textSlt.length ? textSlt : selector); if (inputNum == "所有域名") { let resultData = changeDataFunc(textSltData, ""); if (resultData)[textSltData, textSlt] = resultData; } else if (typeof inputNum === "string") { textSlt = inputNum; if (textSlt === "") { delete textSltData[locHost()]; } else { textSltData[locHost()] = textSlt; } } else if (inputNum === null) { return; } } else if (!textSlt.length) { textSlt = selector; textSltData[locHost()] = textSlt; } GM_setValue("textSltData", textSltData); appendWord(); }); } else { appendWord(); } } else if (eventClass.contains('JqMA-btn-down')) { let menuNum = window.prompt("1:跳转节点 2:保存位置", 1); if (menuNum === "1") { let textContent = getText(document.querySelector(".JqMA-btn-down")); let inputNum = window.prompt("跳转第几个节点:", Number(textContent) ? textContent : 0); if (Number(inputNum) || inputNum === "0") { let nextNum = Number(inputNum); pageNextFunc(nextNum); } } else if (menuNum === "2") { let inputNum = window.prompt("是否保存滚动位置?(取消关闭)", parseInt(getScrollTop())); if (inputNum === null) { nextScrollTop = 0; } else { nextScrollTop = Number(inputNum) } setValLoc("nextScrollTop", nextScrollTop); } } else if (eventClass.contains('JqMA-btn-scrollDiv')) { location.reload(); } else if (eventClass.contains('JqMA-btn-transform')) { alert(`O: ==点击:切换滚动对象 ==滑动:移除#shadow-root ==长按:刷新页面 W: ==点击:输入字体大小 ==滑动:上加下减 ==长按:朗读或下载文字 5: ==点击:启动/停止滚动 ==滑动:上加下减 ==长按:输入滚动速度 ♢: ==点击:回上一位置 ==短滑:上/下:下/上一节点 ==长滑:上/下:到底/顶部 ==长按:记录本域名滚动位置 X: ==点击:隐藏/显示其他按钮 ==滑动:触发 立即翻页 按钮 ==长按:自动点击下一页 T: ==点击:元素取消浮动 ==长按:显示操作清单 B: ==点击:切换a链接打开方式 ==滑动:点击2个a链接,加载页面 ==长按:横屏全屏,返回键退出 120: ==点击:开关页首图片集 ==短滑:上加下减 ==长滑:点击图片,修改过滤尺寸 ==长按:点击图片,输入替换规则 10: ==点击:点击元素,修改过滤尺寸 ==短滑:上加下减 ==长滑:滚动加载图片集 ==长按:开关深度搜索`); } }); onLongPress(document, function(event) { if (pageX.length && event.touches[0].clientY > window.innerHeight * 0.8 && confirm("是否返回?")) { btnDownClick(); } }, 550); function btnDownClick() { if (pageX.length) { pageX = Array.from(new Set(pageX)); if (typeof pageX[0] === "number") { autoScrollTo(pageX[0]); } else { pageX[0].scrollIntoView({ "block": "center" }); } pageX.splice(0, 1); document.querySelectorAll(".JqMA-btn-down").forEach(function(elet) { elet.textContent = "♢"; }); } } function pageNextFunc(nextNum) { pageX.unshift(getScrollTop()); let pageDom = Array.from(document.querySelectorAll(".pagetual_pageBar,.JqMA-mark-pageNext,.JqMA-inner-all,.JqMA-inner-all > :last-child,.JqMA-inner-word > p[style*=green]")); if (Number(nextNum) && nextNum >= pageDom.length) { pageDom.pop().scrollIntoView(); document.querySelectorAll(".JqMA-btn-down").forEach(function(elet) { elet.textContent = pageDom.length - 1; }); return; } if (nextNum == "up") pageDom.reverse(); for (let index = 0; index < pageDom.length; index++) { let dom = pageDom[index]; let offsetD = dom.getBoundingClientRect().top; if (nextNum == index || (nextNum == "up" && offsetD < -0.25 * window.innerHeight) || (nextNum == "down" && offsetD > 0.25 * window.innerHeight)) { dom.scrollIntoView(); document.querySelectorAll(".JqMA-btn-down").forEach(function(elet) { elet.textContent = nextNum == "up" ? pageDom.length - index - 1 : index; }); break; } } } let clearStyle = document.createElement('style'); function applyClearStyle() { clearStyle.innerHTML = `html { overflow-y: auto!important; } body { transform: translate(0%, 0%) !important; padding: 50vh 0!important; height: auto !important; max-height: none !important; } [JqMA-css-fixed_hide] { display: none !important; }`; document.head.appendChild(clearStyle); setTimeout(function() { let elements = document.querySelectorAll(':not(.JqMA-btn-all)'); for (let i = 0; i < elements.length; i++) { const _this = elements[i]; const style = window.getComputedStyle(_this); if (/sticky|fixed/.test(style.position) && _this.offsetHeight < 0.5 * window.innerHeight) { _this.setAttribute("JqMA-css-fixed_hide", "1"); } } }, 400); } function btnTransfClick() { Dtransform = Dtransform ? 0 : 1; document.querySelectorAll(".JqMA-btn-transform").forEach(function(elet) { elet.style.setProperty("color", Dtransform ? "green" : null, "important"); }); if (Dtransform) { applyClearStyle(); } else { document.head.removeChild(clearStyle); } setValLoc("Dtransform", Dtransform); } var [picRepData, picReplace] = getDataValue("picRepData", ""); function getScrollTop() { return visibleDiv().scrollTop; } function visibleDiv(_zf = [9, -9]) { let elements = document.querySelectorAll("*"); for (let i = 0; i < elements.length; i++) { let element = elements[i]; if (element.offsetHeight > 0.6 * window.innerHeight && window.getComputedStyle(element).overflowY !== "hidden") { const oldScrollTop = element.scrollTop; for (let j = 0; j < _zf.length; j++) { element.scrollTop += _zf[j]; if (element.scrollTop !== oldScrollTop) { element.scrollTop -= _zf[j]; return element; } } } } } function xScrollDiv() { let elements = document.querySelectorAll("*"); let scrollEles = []; for (let i = 0; i < elements.length; i++) { let element = elements[i]; if (element.offsetWidth > 0.6 * window.innerWidth && window.getComputedStyle(element).overflowX !== "hidden") { const oldScrollLeft = element.scrollLeft; element.scrollLeft += 9; if (element.scrollLeft > oldScrollLeft) { element.scrollLeft -= 9; scrollEles.push(element); } } } return scrollEles; } function autoScroll(sJu, way = "by", time = 0) { let visDiv = visibleDiv(sJu > 0 ? [9] : [-9]); if (visDiv) { if (way === "by") { if (time) { let totalMoved = 0; const duration = 40; let cishu = time / duration; let distance = Math.max(sJu / cishu, duration * 0.8); const startTime = Date.now(); let _interval = setInterval(function() { visDiv.scrollTop += distance; totalMoved += distance; const currentTime = Date.now(); const elapsedTime = currentTime - startTime; if (elapsedTime >= time || totalMoved >= sJu) { clearInterval(_interval); visDiv.scrollTop += sJu - totalMoved; } }, duration); } else { visDiv.scrollTop += sJu; } } else { visDiv.scrollTop = sJu; } } } function autoScrollBy(scrollBy_Ju, speed = 0) { autoScroll(scrollBy_Ju, "by", speed); } function autoScrollTo(scrollTo_Ju, speed = 0) { let element = visibleDiv(); if (element) { if (speed === 0) { element.scrollTop = scrollTo_Ju; } else { let moveJu = scrollTo_Ju - element.scrollTop; autoScroll(moveJu, "by", speed); } } } function downloadTxt(filename, textContent) { let objectURL = URL.createObjectURL(new Blob([textContent], { type: "text/plain;charset=utf-8" })); let a = createElement('a', { href: objectURL, download: filename, style: "display:none!important;" }); document.body.appendChild(a); a.click(); document.body.removeChild(a); setTimeout(function() { URL.revokeObjectURL(objectURL); }, 2000); } function changeStyle(_id, _style) { docSltAll("head").forEach(function(elet) { if (!elet.querySelector("style#" + _id)) { elet.appendChild(createElement('style', { id: _id }, _style)); } }); docSltAll("style#" + _id).forEach(function(elet) { if ( elet.innerHTML != _style) { elet.innerHTML = _style; } }); } let defWidthN = GM_getValue("defWidthN", 30); function fontInterFn() { changeStyle("JqMA-css-textBig", `* { font-size: ${widthN}px !important; letter-spacing: normal !important; line-height: normal !important; overflow-wrap: break-word !important; }`); } function removeTextClass() { docSltAll("style#JqMA-css-textBig").forEach(function(elet) { elet.innerHTML = ""; }); } function btnWidthClick() { let inputNum = window.prompt("请输入字体大小:(@=修改默认)", widthN ? widthN : defWidthN); if (inputNum === "@") { inputNum = window.prompt("请修改默认字体大小:", defWidthN); defWidthN = Number(inputNum) ? Number(inputNum) : 30; GM_setValue("defWidthN", defWidthN); return; } widthN = Number(inputNum) ? Number(inputNum) : 0; widthNFunc(); } function widthNFunc() { if (widthN > 0) { fontInterFn(); } else { widthN = 0; removeTextClass(); } document.querySelectorAll(".JqMA-btn-width").forEach(function(elet) { elet.textContent = widthN ? widthN : "W"; }); setValLoc("widthN", widthN); } let speakRate = GM_getValue("speakRate", 1); function readStr() { window.speechSynthesis.cancel(); let wordP = document.querySelectorAll(".JqMA-inner-word > p"); for (let i = currentStr; i < wordP.length; i++) { let utterThis = new SpeechSynthesisUtterance(); utterThis.text = getText(wordP[i]); utterThis.rate = speakRate; utterThis.volume = 1.0; window.speechSynthesis.speak(utterThis); utterThis.onstart = function() { currentStr = i; wordP.forEach(function(element) { element.removeAttribute('style'); }); wordP[currentStr].style.cssText = "color:green!important;"; innerWordAdd(); let pLen = document.querySelectorAll(".JqMA-inner-word > p").length; if (currentStr > pLen - 9) { pageX.unshift(getScrollTop()); autoScrollBy(visibleDiv().scrollHeight, 400); setTimeout(function() { btnDownClick(); }, 500); } if (wordP.length < pLen) { readStr(); } } } } function getText(element) { return element.textContent || element.innerText; } function readPause() { try { new SpeechSynthesisUtterance(); } catch (error) { alert("浏览器不支持JS朗读!"); return; } let readbtn = document.querySelectorAll(".JqMA-inner-word > a")[1]; if (getText(readbtn) == "暂停") { readbtn.textContent = "朗读"; window.speechSynthesis.cancel(); } else { readbtn.textContent = "暂停"; readStr(); } } function innerWordAdd() { let allStr = ""; docSltAll(textSlt).forEach(function(element) { if (!element.hasAttribute('JqMA-mark-word')) { allStr += getText(element) + " "; element.setAttribute('JqMA-mark-word', true); } }); allStr = allStr.replace(/\s+/g, " "); let allStrlist = allStr.replace(/<\/?br>/g, "\n").split(/(.{1,150}(?:$|[^一-鿯0-9A-Za-z\/,,、]))/); allStrlist = allStrlist.filter((s) => { return s && s.trim(); }); for (let i = 0; i < allStrlist.length; i++) { let endElement = document.querySelector(".JqMA-mark-wordEnd"); endElement.parentNode.insertBefore(createElement('p', false, allStrlist[i].replace(/\n/g, '
')), endElement); } } var [textSltData, textSlt] = getDataValue("textSltData", ""); let currentStr = 0; function appendWord() { let pOuter = createElement('p', { class: "JqMA-inner-word JqMA-inner-all" }); let pInner = createElement('p', { class: "JqMA-mark-wordEnd" }, "!阅读结束!"); pOuter.appendChild(pInner); document.body.insertBefore(pOuter, document.body.firstChild); innerWordAdd(); document.querySelectorAll(".JqMA-inner-word > p").forEach(function(element) { element.addEventListener("click", function() { if (getText(readbtn) == "朗读") return currentStr = 0; let prevElement = this.previousElementSibling; while (prevElement) { if (prevElement.tagName.toLowerCase() === "p") { currentStr++; } prevElement = prevElement.previousElementSibling; } readStr(); }); }); let readbtn = createElement('a', false, '朗读'); let downbtn = createElement('a', false, '下载'); let ratebtn = createElement('a', false, `语速:${speakRate}`); document.querySelectorAll(".JqMA-inner-word").forEach(function(element) { element.insertBefore(downbtn, element.firstChild); element.insertBefore(readbtn, element.firstChild); element.insertBefore(ratebtn, element.firstChild); }); readbtn.addEventListener("click", readPause); ratebtn.addEventListener("click", function() { let inputNum = window.prompt("输入语速:", speakRate); if (inputNum === null) return; speakRate = inputNum; this.textContent = "语速:" + speakRate; GM_setValue("speakRate", speakRate); if (getText(readbtn) == "朗读") return readStr(); }); downbtn.addEventListener("click", function() { let clonedElement = document.querySelector(".JqMA-inner-word").cloneNode(true); clonedElement.querySelectorAll("a").forEach(function(link) { clonedElement.removeChild(link); }); let textContent = clonedElement.textContent; downloadTxt(document.title.replace(/[\/:*?""<>|]+/g, " ").replace(/^\s+|\s+$/g, "") + ".txt", textContent); }); autoScrollTo(0); } let whProp = GM_getValue("whProp", 3.9); function picSizeOut(_this, picwh_2 = null) { let natureW = _this.naturalWidth; let natureH = _this.naturalHeight; let imgOuterWH = _this.getAttribute("img-outerWH"); let _targetW = imgOuterWH ? imgOuterWH : getPercentW(_this); if (!picwh_2) { picwh_2 = picwh; } return Math.min(natureW, natureH) >= picwh_2 && natureW / natureH <= whProp && _targetW >= outerSz; } function formatStr(_url) { if (typeof _url === "string") { return _url.replace(/^\s+|\s+$/g, "").replace(/&/g, "&").replace(/\\u002F/g, "/").replace(/\\[/]/g, "/"); } else { return ""; } } function decodeStr(_url) { let newI = _url; if (/^https?%/.test(newI)) { try { newI = decodeURIComponent(newI); } catch (error) { console.log(error); } } return newI; } function delHttp(_url) { let newI = []; if (/^(?!blob:|data:).+https?[:%]/.test(_url)) { let _urlSpl = _url.split(/.(?=https?[:%])/); for (let i = 1; i < _urlSpl.length; i++) { if (!/\.html(&|$)/.test(_urlSpl[i])) { newI.push(decodeStr(_urlSpl[i].replace(/^([^?]+?)&.*$/, "$1"))); } } } return newI; } let preMatches = new Set(); const locOrigin = window.location.origin function xiuTan() { if (!document.querySelector(".JqMA-btn-hrefAll")) { const spanStyle = ".JqMA-btn-hrefSpan {margin-left: auto!important; height: 6px!important; line-height: 6px!important;color:red!important;text-align:center!important;position:static!important;}"; const hrefAllStyle = ".JqMA-btn-hrefAll {background: none!important; overflow: scroll!important; height: auto!important; max-height: calc(4vh + 4vw)!important; width: calc(15vw + 15vh)!important; bottom: 4px!important; right: 0!important;}" const hrefStyle = ".JqMA-btn-href {text-align: left!important; position: static!important; width: 100%!important;}" const spanStr = '——'; document.head.appendChild(createElement('style', false, spanStyle + hrefAllStyle + hrefStyle)); document.documentElement.appendChild(createElement('p', { class: 'JqMA-btn-all JqMA-btn-hrefAll' }, spanStr + spanStr)); } let pageSource = ""; docSltAll("html").forEach(function(_this) { pageSource += _this.outerHTML; }); let videoList = []; document.querySelectorAll("iframe").forEach(function(elet) { let srcDomain; try { srcDomain = new URL(elet.src).origin; } catch (error) { console.log(error); } if (srcDomain && srcDomain != locOrigin) { videoList.push(elet.src); } }); docSltAll("video").forEach(function(_this) { videoList.push(_this.currentSrc); }); let regex = /https?[:%][^""<>\s]*?\.(avi|mp4|mov|m4v|m3u8|wmv|flv|f4v|webm)([?!/&%][^""<>\s]*?)?(?=[""<>\s一-鿯]|https?[:%]|$)/gi; let matches = pageSource.replace(/"|['']/g, '"').match(regex); if (matches) videoList.push(...matches); window.performance.getEntries().forEach(function(entry) { if (/\.(avi|m3u8|mp4|mov|m4v|wmv|flv|f4v|webm)([?!/&%]|$)/.test(entry.name)) { videoList.push(entry.name); } }); videoList = Array.from(new Set(videoList)); var newI, newMatches = []; for (let i = 0; i < videoList.length; i++) { newI = formatStr(videoList[i]); if (!newI.replace(/[\s/]/g, "").length || /^(?!https?:)[a-z]{3,15}:/.test(newI)) continue; newMatches.push(newI); let delHtList = delHttp(newI); if (delHtList.length) newMatches.push(...delHtList); } let firstSpan = document.querySelector(".JqMA-btn-hrefAll span"); for (let i = 0; i < newMatches.length; i++) { newI = addLocation(decodeStr(newMatches[i])); if (preMatches.has(newI)) continue; preMatches.add(newI); firstSpan.parentNode.insertBefore(createElement('a', { href: newI, class: "JqMA-btn-all JqMA-btn-href" }, newI.replace(/\/(?=$|\?)/g, "").replace(/^[^?]*[/]/, "").replace(/(?<=[^?/.]{9})[^?/.]+/, "")), firstSpan.nextSibling); } } function getMinPicwh(_this) { return Math.min(_this.naturalWidth, _this.naturalHeight); } function getPercentW(_this) { return parseInt(_this.offsetWidth / window.innerWidth * 100); } function waitClick(afterFunc) { document.querySelectorAll(".JqMA-btn-all").forEach(function(_this) { _this.style.setProperty("display", "none", "important"); }); setTimeout(function() { docSltAll("body:not(body *)").forEach(function(_this) { _this.addEventListener('click', tempClickFunc); }); function tempClickFunc(event) { event.preventDefault(); docSltAll("body").forEach(function(_this) { _this.removeEventListener('click', tempClickFunc); }); document.querySelectorAll(".JqMA-btn-all").forEach(function(_this) { _this.style.setProperty("display", "block", "important"); }); afterFunc(event); } }, 100); } function btnOuterSzClick() { waitClick(function(event) { let _this = event.target; let imgOuterWH = _this.getAttribute("img-outerWH"); let _targetW = imgOuterWH ? imgOuterWH : getPercentW(_this); let inputNum = window.prompt("请输入过滤尺寸:", _targetW - 5); if (Number(inputNum) || inputNum === "0") { outerSz = Number(inputNum); if (outerSz < minOuterSz) outerSz = minOuterSz; outerSz_run(); } }); } function outerSz_run() { if (outerSz < 0) outerSz = 0; if (picZ) { if (outerSz === 0) { let _scrollTop = getScrollTop(); removePicClass(); imgInterFn(); setTimeout(function() { autoScrollTo(_scrollTop); }, 400); } else { picImgFilter(); } } if (widthN) { removeTextClass(); fontInterFn(); } document.querySelectorAll(".JqMA-btn-outerSz").forEach(function(_this) { _this.textContent = outerSz; }); setValLoc("outerSz", outerSz); } function btnPicwhClick() { waitClick(function(event) { let _picwh = event.target.matches("img") ? getMinPicwh(event.target) + 20 : minPicwh, inputNum = window.prompt("请输入 过滤尺寸:(@ = 修改默认)", _picwh); if (/^\d+$/.test(inputNum)) { picwh = Number(inputNum); if (picwh < minPicwh) picwh = minPicwh; picImgFilter(); } else if (inputNum === "@") { let _whProp = parseInt(event.target.naturalWidth / event.target.naturalHeight * 10) / 10; let _this = event.target; let imgOuterWH = _this.getAttribute("img-outerWH"); let _targetW = imgOuterWH ? imgOuterWH : getPercentW(_this); inputNum = window.prompt(`请输入 过滤宽高比,最小过滤尺寸,最小过滤宽度,最大转高清尺寸:(点击元素:${_whProp},${getMinPicwh(_this)},${_targetW} 推荐:3.9,100,10,500)`, [whProp, minPicwh, minOuterSz, minPicHD]); if (/^[\d.,]+$/.test(inputNum)) { whProp = Number(inputNum.split(",")[0]); minPicwh = Number(inputNum.split(",")[1]); minOuterSz = Number(inputNum.split(",")[2]); minPicHD = Number(inputNum.split(",")[3]); picImgFilter(); GM_setValue("whProp", whProp); GM_setValue("minPicwh", minPicwh); GM_setValue("minOuterSz", minOuterSz); GM_setValue("minPicHD", minPicHD); } } }); } function picImgFilter() { if (picwh < 0) picwh = 0; if (picZ) { document.querySelectorAll(".JqMA-inner-pic > a").forEach(function(_this) { _this.classList.add("JqMA-css-smallPic"); }); document.querySelectorAll(".JqMA-inner-pic .JqMA-mark-imgLoaded").forEach(function(_this) { if (picSizeOut(_this)) { _this.classList.remove("JqMA-css-smallPic"); let nextAllLinks = getNextAll(_this, 'A', 2); nextAllLinks.forEach(function(element) { element.classList.remove("JqMA-css-smallPic"); }); } else { _this.classList.add("JqMA-css-smallPic"); } }); } document.querySelectorAll(".JqMA-btn-pic").forEach(function(_this) { _this.textContent = picwh; }); setValLoc("picwh", picwh); } function btnPicClick() { picZ = picZ ? 0 : 1; document.querySelectorAll(".JqMA-btn-pic").forEach(function(_this) { _this.style.setProperty("color", picZ ? "green" : null, "important"); }); setValLoc("picZ", picZ); if (picZ) { if (scrollPic) { scrollPicLoad(); } else { imgInterFn(); } } else { removePicClass(); } } let scrollPic = getValLoc("scrollPic", 0) function scrollPicLoad() { const _scrollTop = getScrollTop(); const _picZ = picZ; picZ = 0; document.querySelectorAll(".JqMA-inner-pic").forEach(function(_this) { _this.remove(); }); autoScrollTo(0); const maxTop = visibleDiv().scrollHeight; autoScrollBy(maxTop, 900); setTimeout(function() { xScrollDiv().forEach(function(elet) { elet.scrollLeft = 10 * window.innerWidth }); autoScrollTo(0, 200); setTimeout(function() { if (_picZ) { picZ = 1; removePicClass(); imgInterFn(); } setTimeout(function() { autoScrollTo(_scrollTop); }, 400); }, 400); }, 1000); } function removePicClass() { document.querySelectorAll(".JqMA-inner-pic").forEach(function(_this) { _this.remove(); }); preImgArr = [new Set(), new Set(), new Set()]; } function addLocation(_href) { try { return new URL(_href, window.location.origin).href; } catch (error) { return _href; } } function getImgList(dataObj, _this, findA, preImgNum) { let imgList = [], imgOuterWH; dataObj.forEach(function(i) { i = formatStr(i); if (!i.replace(/[\s/]/g, "").length) return; i = addLocation(decodeStr(i)); if (!preImgArr[preImgNum].has(i)) { preImgArr[preImgNum].add(i); imgOuterWH = _this ? getPercentW(_this) : minOuterSz; let newImg = createElement('img', { src: i, loading: 'lazy', width: '300', height: '100', 'img-outerWH': imgOuterWH }); onLongPress(newImg, function() { if (confirm("是否滚动到图片位置?")) { pageX.unshift(newImg); _this.scrollIntoView({ "block": "center" }); } }); imgList.push(newImg); } }); if (findA && imgList.length) { let _newA = createElement('a', { class: "JqMA-css-smallPic" }); let _a = _this.closest("a"); let _img_2 = _this; for (let i = 0; i < 3; i++) { if (_a || _img_2.matches("body")) break; _a = _img_2.querySelector("a[href]"); _img_2 = _img_2.parentElement; } const _href = _a ? _a.getAttribute("href") : null; if (_href && !/^(?!https?:)[a-z]{4,15}:|^#/.test(_href)) { _newA.setAttribute("href", _href); const aTarget = _a.getAttribute("target"); aTarget && _newA.setAttribute("target", aTarget); } else { if (!_a) { _a = _this; } _newA.addEventListener("click", function() { _a.click(); }); } let _newA2 = createElement('a', { class: "JqMA-css-smallPic" }, imgOuterWH); _newA2.addEventListener("click", function() { let prevImg = this.previousElementSibling; while (prevImg && prevImg.tagName !== 'IMG') { prevImg = prevImg.previousElementSibling; } if (prevImg) { pageX.unshift(prevImg); } _this.scrollIntoView({ "block": "center" }); }); imgList.push(_newA); imgList.push(_newA2); } return imgList; } var preImgArr = [new Set(), new Set(), new Set()]; var imgRegex_1 = /https?[:%][^""<>\s]*?\.(xbm|tif|pjp|jpg|jpeg|tiff|gif|jfif|webp|png|bmp|pjpeg|avif)([?!/&%][^""<>\s]*?)?(?=[""<>\s一-鿯]|https?[:%]|$)/gi var imgRegex_2 = /((?<=[""])[a-z]*[/]|https?[:%])[^""<>\s]*?\.(xbm|tif|pjp|jpg|jpeg|tiff|gif|jfif|webp|png|bmp|pjpeg|avif)([?!/&%][^""<>\s]*?)?(?=[""<>\s]|https?[:%]|$)/i let pageNext_0, pageNext_1, pageNext_2; const aStr = ''; function imgInterFn() { picaImgHide(); if (!document.querySelector(".JqMA-inner-pic")) { let newP = createElement('p', { class: "JqMA-inner-pic JqMA-inner-all" }); newP.appendChild(createElement('p', { class: "JqMA-mark-pageNext JqMA-mark-pageNext_0 JqMA-mark-pageNum" }, "可见元素")); newP.appendChild(createElement('p', { class: "JqMA-mark-pageNext JqMA-mark-pageNext_1 JqMA-mark-pageNum" }, "深度搜索")); newP.appendChild(createElement('p', { class: "JqMA-mark-pageNext JqMA-mark-pageNext_2 JqMA-mark-pageNum" }, "文字链接")); document.body.prepend(newP); } pageNext_0 = document.querySelector(".JqMA-mark-pageNext_0"); pageNext_1 = document.querySelector(".JqMA-mark-pageNext_1"); pageNext_2 = document.querySelector(".JqMA-mark-pageNext_2"); let imgArr_0 = [], imgArr_1 = []; docSltAll("*").forEach(function(_this) { if (_this.classList.contains("pagetual_pageBar")) { if (!pageNext_1.previousElementSibling.classList.contains('JqMA-mark-pageNext')) { pageNext_1.parentNode.insertBefore(createElement('p', { class: "JqMA-mark-pageNext" }), pageNext_1); } if (DSImg && !pageNext_2.previousElementSibling.classList.contains('JqMA-mark-pageNext')) { pageNext_2.parentNode.insertBefore(createElement('p', { class: "JqMA-mark-pageNext" }), pageNext_2); } return true; } let srcArr = []; if (_this.matches("img:not(.JqMA-inner-pic > *)")) { srcArr.push(_this.currentSrc); } else if (_this.matches("video")) { srcArr.push(_this.poster); } const backImg = window.getComputedStyle(_this).backgroundImage.split('"'); if (backImg.length > 1) { srcArr.push(backImg[1]); } if (srcArr.length && (outerSz === 0 || getPercentW(_this) >= 1)) { let imgList = getImgList(srcArr, _this, true, 0); if (imgList.length) imgArr_0.push(...imgList); if (DSImg) { let _imgHtml = ""; let closA = _this.closest('a'); if (closA) { let clonedA = closA.cloneNode(); clonedA.removeAttribute('style'); _imgHtml = clonedA.outerHTML; } let clonedThis = _this.cloneNode(); clonedThis.removeAttribute('style'); clonedThis.removeAttribute('src'); clonedThis.removeAttribute('poster'); _imgHtml += clonedThis.outerHTML; let _isp = _imgHtml.replace(/"|['']/g, '"').match(imgRegex_2); if (_isp) { imgList = getImgList([_isp[0]], _this, true, 1); if (imgList.length) imgArr_1.push(...imgList); } } } }); imgArr_0.forEach(function(imgElement) { pageNext_1.parentNode.insertBefore(imgElement, pageNext_1); }); imgArr_1.forEach(function(imgElement) { pageNext_2.parentNode.insertBefore(imgElement, pageNext_2); }); if (DSImg) { let _text = ""; docSltAll("body > *").forEach(function(_this) { let clonedElement = _this.cloneNode(true); clonedElement.querySelectorAll('style, script, noscript').forEach(el => el.remove()); let textContent = clonedElement.textContent; _text += textContent; }); _text = _text.replace(/"|['']/g, '"').match(imgRegex_1); if (_text) { _text = getImgList(_text, false, false, 2); let innerPic = document.querySelector(".JqMA-inner-pic"); _text.forEach(function(text) { innerPic.appendChild(text); }); } } picImgCount(pageNext_0, pageNext_1, pageNext_2); document.querySelectorAll(".JqMA-inner-pic > img:not(.JqMA-mark-preAdd)").forEach(function(_this) { _this.classList.add("JqMA-mark-preAdd"); _this.addEventListener('load', function() { imgLoadError(_this); _this.classList.add("JqMA-mark-imgLoaded"); let nextAllLinks = getNextAll(_this, 'A', 1); nextAllLinks.forEach(function(element) { element.textContent = getMinPicwh(_this); }); }); _this.addEventListener('error', function() { imgLoadError(_this); }); }); } function imgLoadError(elet) { picImgCount(pageNext_0, pageNext_1, pageNext_2); let oldNatureH = elet.naturalHeight, oldNatureW = elet.naturalWidth; if (Math.min(oldNatureW, oldNatureH) < minPicHD) { let thisSrcList = picHD(elet.currentSrc), _this = elet, promiseArray = []; for (let i = 0; i < thisSrcList.length; i++) { promiseArray.push(checkImgExists(thisSrcList[i]).catch(err => { console.log(err) })); } Promise.all(promiseArray).then(function(data) { for (let i = 0; i < data.length; i++) { let resH = data[i]; if (resH.naturalHeight > oldNatureH || resH.naturalWidth > oldNatureW) { _this.setAttribute("src", resH.src); _this.setAttribute("JqMA-mark-imgHD", true); return; } } }); } if (picSizeOut(elet)) { elet.classList.remove("JqMA-css-smallPic"); let nextAllLinks = getNextAll(elet, 'A', 2); nextAllLinks.forEach(function(element) { element.classList.remove("JqMA-css-smallPic"); }); } else { elet.classList.add("JqMA-css-smallPic"); } } function prevAll(pageNext_1, _seletor) { let siblings = Array.from(pageNext_1.parentNode.children); let imgElements = siblings.slice(0, siblings.indexOf(pageNext_1)).filter(function(sibling) { return sibling.matches(_seletor); }); return imgElements; } var picImgTime; function picImgCount(pageNext_0, pageNext_1, pageNext_2) { clearTimeout(picImgTime); picImgTime = setTimeout(function() { let picImgLen = document.querySelectorAll(".JqMA-inner-pic > img:not(.JqMA-css-smallPic)").length; let keJian_Img = prevAll(pageNext_1, "img:not(.JqMA-css-smallPic)").length; let search_len = prevAll(pageNext_2, "img:not(.JqMA-css-smallPic)").length; pageNext_0.innerHTML = `可见:${keJian_Img} 深度:${search_len - keJian_Img} 文字:${picImgLen - search_len}`; }, 400); } function picHD(oldSrc) { var thisSrc = oldSrc, thisSrcList = []; if (picReplace.indexOf("`") != -1) { let numberToRe = /^@/.test(picReplace) ? 1 : 0, picRepArr = picReplace.replace(/^@/, "").split("`"); for (let i = 0; i < parseInt(picRepArr.length / 2); i++) { thisSrc = thisSrc.replace(numberToRe ? new RegExp(picRepArr[2 * i].replace(/(?;]+$/, "$1")); let delHtList = delHttp(oldSrc); if (delHtList.length) thisSrcList.push(...delHtList); if (!/.https?[:%]/.test(oldSrc)) { thisSrcList.push(oldSrc.replace(/^([^?]+?)&.*$/, "$1")); } var newSrcList = []; for (let i = 0; i < thisSrcList.length; i++) { thisSrc = thisSrcList[i]; if (thisSrc != oldSrc) { newSrcList.push(thisSrc); } } return newSrcList; } function picaImgHide() { if (Dhide) { changeStyle("JqMA-inner-picaImg", ".JqMA-inner-pic > a {" + "height: 0!important; border: 0!important;}" + ".JqMA-inner-pic > img.JqMA-css-smallPic {" + "height: 0!important; border: 4px solid gray!important;}"); } else { docSltAll("style#JqMA-inner-picaImg").forEach(function(_this) { _this.innerHTML = ""; }); } } function delHide() { document.querySelectorAll(".JqMA-btn-all").forEach(function(_this) { if (_this.matches(".JqMA-btn-del")) { _this.style.cssText += "opacity:" + (Dhide ? "0.5" : "1") + "!important;"; } else { _this.style.cssText += "display:" + (Dhide ? "none" : "block") + "!important;"; } }); } function btnDelClick() { Dhide = Dhide ? 0 : 1; delHide(); picaImgHide(); setValLoc("Dhide", Dhide); } let nextScrollTop = getValLoc("nextScrollTop", 0); function getNextPage(hrefSplit) { let pNumber = Number(hrefSplit[2].split(/[^\d]/)[0]) + 1; let newHref = hrefSplit[0] + hrefSplit[1] + pNumber + hrefSplit[2].replace(/^\d+/, ""); return newHref; } function openHref(newHref) { if (openBlank) { window.open(newHref); } else { location.href = newHref; } } function aOpenBlank() { docSltAll("a:not([JqMA-mark-blank])").forEach(function(_this) { _this.setAttribute("JqMA-mark-blank", true); if (!/^(?!https?:)[a-z]{4,15}:|^#/.test(_this.href)) { _this.setAttribute('target', '_blank'); } }); } function btnBlankClick() { openBlank = openBlank ? 0 : 1; document.querySelectorAll(".JqMA-btn-blank").forEach(function(_this) { _this.style.setProperty("color", openBlank ? "green" : null, "important"); }); if (openBlank) { aOpenBlank(); } else { docSltAll("[JqMA-mark-blank]").forEach(function(_this) { _this.removeAttribute('JqMA-mark-blank'); _this.removeAttribute('target'); }); } setValLoc("openBlank", openBlank); } function fullScreen() { waitClick(function() { document.documentElement.requestFullscreen(); changeStyle("fullScreenBody", "body {width: " + Drotate_W + "vw!important; max-width: none!important; min-width: none!important;}"); screen.orientation.lock = hengPin; screen.orientation.lock('landscape'); }); } let Drotate = getValLoc("Drotate", 0); let Drotate_W = getValLoc("Drotate_W", 100); function scrollRun() { Dscroll = Dscroll ? 0 : 1; clearInterval(timeDown); document.querySelectorAll(".JqMA-btn-Ju").forEach(function(_this) { _this.style.setProperty("color", Dscroll ? "green" : null, "important"); }); if (Dscroll) { timeDown = setInterval(function() { autoScrollBy(direction * scrollJu * window.innerHeight * 0.05, smoothScroll ? 0 : 800); }, 805); GM_setValue("scrollJu", scrollJu); } } function btnJuClick() { scrollRun(); setValLoc("Dscroll", Dscroll); } })(); }