// ==UserScript==
// @name 手机助手
// @namespace http://tampermonkey.net/
// @version 10.0.1.28
// @description 自动滚动,嗅探图片、视频,字体放大,去除广告浮动
// @author You
// @match *://*/*
// @run-at document-start
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// @license MIT
// @downloadURL none
// ==/UserScript==
{
'use strict';
const hengPin = screen.orientation.lock;
(function() {
const isInIframe = () => {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
};
if (document.querySelector('.JQMA-btn-all')) return;
if (isInIframe()) {
const getSrc = el => el.currentSrc || el.src;
let lastEntryCount = 0;
function getIframe() {
// 获取当前性能条目
const currentEntries = performance.getEntries();
// 判断条目是否增加(与上次比较)
const entryCount = currentEntries.length;
if(entryCount > lastEntryCount){
lastEntryCount = entryCount;
const videos = [],
imgs = [];
// 处理所有video元素
document.querySelectorAll('video').forEach(v => {
const src = getSrc(v);
if (src) videos.push(src);
if (v.poster) imgs.push(v.poster);
v.querySelectorAll('source').forEach(s => {
const src = getSrc(s);
if (src) videos.push(src);
});
});
// 处理所有img元素
document.querySelectorAll('img').forEach(img => {
const src = getSrc(img);
if (src) imgs.push(src);
});
const nowIframe = {
url: window.location.href,
html: document.documentElement.outerHTML,
entries: currentEntries.map(e => e.name),
videos,
imgs
};
// 发送到顶级页面
window.top.postMessage({
type: 'JQMA-iframe-data',
data: nowIframe
}, '*');
}
}
setInterval(getIframe, 2000, 700);
return;
}
const iframeData = {}; // 字典变量
window.addEventListener('message', function(e) {
if (e.data.type === 'JQMA-iframe-data') {
iframeData[e.data.data.url] = e.data.data;
}
});
const currentDomain = location.hostname;
const docSltAll = selector => {
const doms = [...document.querySelectorAll(selector)];
document.querySelectorAll('iframe').forEach(iframe => {
try {
const doc = iframe.contentDocument || iframe.contentWindow.document;
doms.push(...doc.querySelectorAll(selector));
} catch {}
});
return doms;
};
const simulateClick = element => {
try {
const event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
composed: true,
});
element.dispatchEvent(event);
} catch (error) {
element.click();
}
};
const createElement = (tagName, attributes = null, content = null) => {
const element = document.createElement(tagName);
attributes && Object.entries(attributes).forEach(([key, value]) => {
element.setAttribute(key, value);
});
if (content !== null) {
element.textContent = content;
}
return element;
};
function getDataValue(gValName, _default) {
const _data = GM_getValue(gValName, {});
const keys = Object.keys(_data);
if (keys.length > 50) {
delete _data[keys[0]];
GM_setValue(gValName, _data);
}
return [_data, _data[currentDomain] ?? _default];
}
let [txtToCData, txtToC] = getDataValue("txtToCData", "");
let [cssToCData, cssToC] = getDataValue("cssToCData", "");
let [clickNumData, clickNum] = getDataValue("clickNumData", 1);
let [scriptEnabledData, scriptEnabled] = getDataValue('scriptEnabledData', true);
const scalable = ",user-scalable=1,maximum-scale=10.0";
function autoChangeScale() {
if (!scriptEnabled) return;
const meta = document.querySelector('meta[name=viewport]');
if (!meta) return;
const content = meta.getAttribute('content');
if (!content.includes('scalable')) {
meta.setAttribute('content', (content + scalable).replace(/, ?,/, ','));
}
}
let clickNextTime = GM_getValue("clickNextTime", new Date().getTime() - 2000);
function clickElsByTextSel(_tToC, _cToC) {
if (new Date().getTime() - clickNextTime >= 2000) {
if (_tToC.length) {
const regex = new RegExp('^\s*(' + _tToC + ')');
[...document.querySelectorAll('*')].forEach(el => {
if (regex.test(el.textContent)) {
for (let i = 0; i < clickNum; i++) simulateClick(el);
}
});
}
if (_cToC.length) {
document.querySelectorAll(_cToC).forEach(el => {
for (let i = 0; i < clickNum; i++) simulateClick(el);
});
}
GM_setValue("clickNextTime", new Date().getTime());
}
}
function removeShadowRoot() {
const hasShadowRoot = [...document.querySelectorAll('div')].some(div =>
div.shadowRoot && (div.replaceWith(...div.shadowRoot.childNodes) || true)
);
alert(`#shadow-root ${hasShadowRoot ? '已移除' : '不存在'}`);
}
function checkImgExists(imgurl, timeout = 8000) {
return new Promise(function(resolve, reject) {
const img = new Image();
let resolved = false;
const cleanup = () => {
img.onload = null;
img.onerror = null;
if (timer) clearTimeout(timer);
};
const timer = setTimeout(() => {
if (resolved) return;
resolved = true;
cleanup();
reject(new Error('Image load timeout'));
}, timeout);
img.onload = function() {
if (resolved) return;
resolved = true;
cleanup();
resolve(this);
};
img.onerror = function(err) {
if (resolved) return;
resolved = true;
cleanup();
reject(err);
};
img.src = imgurl;
});
}
const getTouchSite = (el, e) => {
const r = el.getBoundingClientRect();
const t = e.touches[0];
const h = el.offsetHeight;
return [t.clientX - r.left - h / 2, t.clientY - r.top - h / 2, h];
};
const getSelector = (el, max = 3) => {
const parts = [];
for (let i = 0, cur = el; i < max && cur && cur.nodeType === 1; i++, cur = cur.parentNode) {
if (cur.nodeName === 'BODY') break;
let sel = cur.nodeName.toLowerCase();
if (cur.id) sel += `#${cur.id}`;
if (cur.classList.length) {
const cls = [...cur.classList].filter(c => !/^\d/.test(c)).slice(0, 2).map(c => `.${c.replace(/([.#:()[\]/~>+*])/g,'\\$1')}`).join('');
if (cls) sel += cls;
}
parts.unshift(sel);
}
return parts.join(' > ');
};
const getCommonSelector=(selector1, selector2)=> {
// 用正则分割,保留分隔符
const tokens1 = selector1.split(/(?])/g);
const tokens2 = selector2.split(/(?])/g);
if(tokens1.length != tokens2.length){return selector2;}
// 逐个比较并拼接相同的token
let commonSelector = '';
const minLength = Math.min(tokens1.length, tokens2.length);
for (let i = 0; i < minLength; i++) {
if (tokens1[i] == tokens2[i]) {
commonSelector += tokens1[i];
}
}
return commonSelector.replace(/[#.](?=[# .>]|$)/g,'');
};
let addCss = GM_getValue("addCss", "");
let [addWordData, addWord] = getDataValue("addWordData", false);
let [addPicData, addPic] = getDataValue("addPicData", false);
let [DtransformData, Dtransform] = getDataValue("DtransformData", 0);
let [nextpageData, nextpage] = getDataValue("nextpageData", 1);
let btnPosition = GM_getValue("btnPosition", 1);
GM_registerMenuCommand("显示菜单", function() {
const options = [
`1、显隐按钮`,
`2、去浮动 ${Dtransform ? "已开启" : "已关闭"}`,
`3、点击翻页 ${nextpage ? "已开启" : "已关闭"}`,
`4、按钮位置`,
`5、添加css ${addCss}`,
`6、启用缩放 ${scriptEnabled ? '已开启' : '已关闭'}`,
`7、加载后自动点击 ${clickNum}次 ${txtToC} ${cssToC}`
];
const inputNum = window.prompt(options.join('\n'), 1);
const actions = {
"1": () => {
const el = document.querySelector(".JQMA-btn-del");
const isHide = getComputedStyle(el).display === "none";
document.head[isHide ? 'removeChild' : 'appendChild'](hideAllBtn);
},
"2": btnTransfClick,
"3": () => {
if (nextpage) {
nextpage = 0;
nextpageData[currentDomain] = nextpage;
} else {
nextpage = 1;
delete nextpageData[currentDomain];
}
GM_setValue("nextpageData", nextpageData);
},
"4": () => {
btnPosition ^= 1;
GM_setValue("btnPosition", btnPosition);
location.reload(false);
},
"5": () => {
waitClick(function(event) {
const css = prompt(`${getSelector(event.target,6)} 输入css:`, addCss);
css !== null && (GM_setValue("addCss", css), location.reload(false));
});
},
"6": () => {
scriptEnabledData[currentDomain] = scriptEnabled = !scriptEnabled;
GM_setValue('scriptEnabledData', scriptEnabledData);
scriptEnabled ? autoChangeScale() : location.reload();
},
"7": () => {
const menu = prompt(`1、输入起始文本 ${txtToC}\n2、输入css选择器 ${cssToC}\n3、点击次数 ${clickNum}次`, 1);
const handleOption = (key, promptText, dataStore, defaultValue, dataKey, transform = v => v) => {
const input = prompt(promptText, defaultValue);
if (input === "") {
defaultValue = key === "clickNum" ? 1 : "";
delete dataStore[currentDomain];
} else if (input !== null) {
defaultValue = transform(input);
dataStore[currentDomain] = input;
}
GM_setValue(`${dataKey}Data`, dataStore);
};
if (menu === "1") {
handleOption("txt", '加载点击 输入起始文本 分隔|(正则特殊字符转义)', txtToCData, txtToC, "txtToC");
} else if (menu === "2") {
handleOption("css", '加载点击 输入css选择器 分隔 ,(半角)', cssToCData, cssToC, "cssToC");
} else if (menu === "3") {
handleOption("clickNum", '页面加载点击 输入点击次数', clickNumData, clickNum, "clickNum", Number);
}
}
};
actions[inputNum]?.();
});
const changeDataFunc = (data, def) => {
const input = prompt("请修改:", JSON.stringify(data));
if (!input) return false;
try {
const parsed = JSON.parse(input);
if (typeof parsed === "object") {
alert(input);
return [parsed, currentDomain in parsed ? parsed[currentDomain] : def];
}
} catch { }
return false;
};
const html_style = '';
let inner_style = `
.JQMA-btn-all,
.JQMA-inner-all,
.JQMA-inner-all *,
.JQMA-mark-innerBtn{
min-width:none!important;
max-width:none!important;
min-height:none!important;
max-height:none!important;
margin:0!important;
border:0!important;
padding:0!important;
box-sizing:border-box!important;
border-radius:0!important;
float:none!important;
opacity:1!important;
filter:none!important;
-webkit-filter:none!important;
pointer-events: auto!important;
}
.JQMA-inner-all{
border-bottom:calc(.8vh + .8vw) solid black!important;
position:fixed!important;
top:calc(3.2vh + 3.2vw)!important;
left:0!important;
height:auto!important;
max-height:calc(70vh + 10vw)!important;
width:100vw!important;
overflow:scroll!important;
z-index:2147483646!important;
background:black!important;
display:block!important;
scroll-behavior:auto!important;
}
.JQMA-inner-word,
.JQMA-inner-word>p{
color:#FEFEFE!important;
text-align:left!important;
font-size:calc(2.1vh + 2.1vw)!important;
text-indent:0!important;
letter-spacing:normal!important;
line-height:normal!important;
white-space:pre-line!important;
overflow-x:hidden!important;
}
.JQMA-inner-word>p{
width:100%!important;
}
.JQMA-inner-all *::before,
.JQMA-inner-all *::after{
display:none!important;
}
.JQMA-inner-pic{
text-align:center!important;
}
.JQMA-inner-pic>img{
width:auto!important;
min-width:12.5%!important;
max-width:100%!important;
height:auto!important;
min-height:calc(3.5vh + 3.5vw)!important;
object-fit:contain!important;
background:gray!important;
}
.JQMA-inner-pic>img.JQMA-css-smallPic{
max-width:33.3%!important;
max-height:calc(10vh + 10vw)!important;
}
.JQMA-inner-pic>*{
display:inline-block!important;
vertical-align:top!important;
overflow:hidden!important;
}
.JQMA-inner-pic>a{
width:12.5%!important;
margin-left:-12.5%!important;
font-size:calc(1.5vh + 1.5vw)!important;
height:calc(3.5vh + 3.5vw)!important;
color:#FEFEFE!important;
background:rgba(0,0,0,.2)!important;
line-height:1.1!important;
}
.JQMA-mark-pageNum,
.JQMA-mark-pageNum>*{
background:green!important;
color:#FEFEFE!important;
font-size:calc(1.6vh + 1.6vw)!important;
line-height:1.7!important;
white-space:normal!important;
}
.JQMA-mark-pageNum{
width:100%!important;
height:calc(2.7vh + 2.7vw)!important;
text-align:center!important;
}
.JQMA-btn-all{
overflow:hidden!important;
background:rgba(0,0,0,.4)!important;
color:#FEFEFE!important;
display:none!important;
text-align:center!important;
text-indent:0!important;
line-height:2.8!important;
user-select:none!important;
z-index:999999999999!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:.4!important;
}
.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-mark-innerBtn{
background:rgba(0,0,0,.4)!important;
color:#FEFEFE!important;
width:calc(3.2vh + 3.2vw)!important;
height:calc(3.2vh + 3.2vw)!important;
position:fixed!important;
top:0!important;
z-index:2147483646!important;
font-size:calc(1.5vh + 1.5vw)!important;
line-height:2.3!important;
text-align:center!important;
white-space:normal!important;
}` + addCss;
function getValLoc(gValName, _default) {
if (currentDomain == GM_getValue(gValName + "_locH")) {
return GM_getValue(gValName, _default);
} else {
return _default;
}
}
function setValLoc(gValName, value) {
GM_setValue(gValName, value);
GM_setValue(gValName + "_locH", currentDomain);
}
let scrollJu = GM_getValue("scrollJu", 5);
let defDSI = GM_getValue("defDSI", "1");
let [DSImgData, DSImg] = getDataValue("DSImgData", defDSI);
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 [backcolordata, backcolor] = getDataValue("backcolordata", 0);
function addInput(class1, value1, style1) {
document.documentElement.appendChild(createElement('p', {
class: "JQMA-btn-all " + class1
}, value1));
inner_style += `.JQMA-btn-all.${class1} {${style1}!important;${btnPosition ? "left" : "right"}: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', scrollJu, "top:calc(50vh - 8vh - 8vw)");
addInput('JQMA-btn-width', widthN ? (backcolor ? "#" : "") + widthN : "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)");
document.head.appendChild(createElement('style', null, html_style + inner_style));
openBlk && document.querySelector(".JQMA-btn-blank").style.setProperty("color", "green", "important");
Dtransform && document.querySelector(".JQMA-btn-transform").style.setProperty("color", "green", "important");
Drotate && document.querySelector(".JQMA-btn-scrollDiv").style.setProperty("color", "green", "important");
delHide();
}
let Dhide = getValLoc("Dhide", 1);
const publicStyle = createElement("style");
setTimeout(function() {
Dtransform && applyClear();
clickElsByTextSel(txtToC, cssToC);
firstRun();
addWord && endAppendWord();
addPic && endImgInterFn();
autoChangeScale();
document.addEventListener('touchstart', e => e.touches.length > 1 && autoChangeScale());
document.addEventListener('touchend', function handler(e) {
Dscroll && (Dscroll = 0, scrollRun());
Drotate && (fullScreen(),Drotate=false);
e.currentTarget.removeEventListener(e.type, handler);
});
document.head.appendChild(publicStyle);
}, 800);
let _lastTouchTime = 0;
function touchRun() {
if (Date.now() - _lastTouchTime > 3000) {
firstRun();
_lastTouchTime = Date.now();
}
}
const htmlTouch = e => {
if (!Dscroll || pauseScroll) return;
const target = e.target;
if (target.matches(".JQMA-btn-Ju")) return;
scrollRun();
if (!target.matches(".JQMA-btn-down")) {
pauseScroll = true;
}
};
let returnTop;
function firstRun() {
if (!document.querySelector('.JQMA-btn-all')) {
addAllBtn();
}
(widthN || backcolor) && fontInterFn();
document.querySelector(".JQMA-inner-pic") && imgInterFn();
openBlk && aOpenBlank();
!Dhide && xiuTan();
document.querySelector(".JQMA-inner-word") && innerWordAdd();
docSltAll("html:not([JQMA-mark-htmlFunc])").forEach(function(elet) {
elet.setAttribute('JQMA-mark-htmlFunc', true);
elet.addEventListener('click', function(event) {
const _target = event.target;
if (_target.matches("#JQMA-mark-lastOne")) {
const innerTop=document.querySelector(".JQMA-inner-pic").scrollTop;
if(innerTop) returnTop=innerTop;
document.querySelector(".JQMA-inner-pic>:last-child").scrollIntoView({
behavior: 'auto',
block: 'start'
});
} else if (_target.matches("#JQMA-mark-pageNext_0,#JQMA-mark-pageNext_1,#JQMA-mark-pageNext_2")) {
const innerTop=document.querySelector(".JQMA-inner-pic").scrollTop;
if(innerTop) returnTop=innerTop;
document.querySelector("." + _target.id).scrollIntoView({
behavior: 'auto',
block: 'start'
});
} else if (_target.matches("a,a *")) {
setTimeout(function() {
if (Dscroll) {
scrollRun();
pauseScroll = true;
}
}, 210);
} else if (nextpage && !this.matches("html *") && _target.matches("picture,img,canvas,.JQMA-inner-pic") &&
_target.offsetWidth > window.innerWidth * 0.45) {
const direction = event.clientY < window.innerHeight * 0.11 ? -1 : 1;
autoScrollBy(findScrollParent(_target, direction > 0 ? 'bottom' : 'top'), direction * window.innerHeight * (document.fullscreenElement?0.65:0.45));
}
if (nextScrollTop) {
autoScrollBy(visibleDiv(), nextScrollTop, "to");
}
});
elet.addEventListener('touchstart', function(event) {
htmlTouch(event);
});
elet.addEventListener('touchmove', function(event) {
htmlTouch(event);
});
elet.addEventListener("touchend", function() {
touchRun();
stopPause();
});
});
}
let pauseScroll;
const stopPause = () => setTimeout(() => {
if (!pauseScroll) return;
pauseScroll = false;
!Dscroll && scrollRun();
}, 200);
const onLongPress = (el, callback, timeout = 600) => {
let timer;
let canTrigger = true;
el.addEventListener('touchstart', e => {
timer = setTimeout(() => canTrigger && callback(e), timeout);
setTimeout(() => {canTrigger = true}, timeout);
});
el.addEventListener('touchend', () => clearTimeout(timer));
el.addEventListener('touchmove', e => {
clearTimeout(timer);
if (canTrigger && e.touches.length > 1) {
canTrigger = false;
}
});
};
const onSlideScreen = (el, callback, timeout = 600) => {
let timer;
el.addEventListener('touchmove', e => {
clearTimeout(timer);
timer = setTimeout(() => callback(e), timeout);
});
};
let savedScroll=0;
document.addEventListener('scroll', (e) => {
if (document.fullscreenElement && e.target === document.fullscreenElement &&
document.fullscreenElement.matches(Drotate_W)) {
const t = e.target.scrollTop;
if(t > savedScroll + 200)savedScroll = t;
}
}, true);
function btnScrollDivClick() {
if(document.fullscreenElement){
Drotate = false;
document.exitFullscreen();
publicStyle.textContent = publicStyle.textContent.replace(fullBodyText, "");
document.querySelector(".JQMA-btn-scrollDiv").style.setProperty("color", null, "important");
setValLoc("Drotate", Drotate);
return;
}
waitClick(function(event) {
const width = prompt(`${getSelector(event.target,6)} 全屏元素:`, Drotate_W);
if (width === null) {
Drotate = false;
document.exitFullscreen();
publicStyle.textContent = publicStyle.textContent.replace(fullBodyText, "");
} else {
Drotate = true;
Drotate_W = width;
if(Drotate_W == 'html'){
delete Drotate_Wdata[currentDomain];
}else{
Drotate_Wdata[currentDomain] = Drotate_W;
}
GM_setValue("Drotate_Wdata", Drotate_Wdata);
fullScreen();
setTimeout(()=>{
const fullElement=document.fullscreenElement;
if(fullElement && savedScroll){
autoScrollBy(fullElement, savedScroll, 'to');
}
},800);
}
document.querySelector(".JQMA-btn-scrollDiv").style.setProperty("color", Drotate ? "green" : null, "important");
setValLoc("Drotate", Drotate);
});
}
let pageX = [];
let [widthNdata, widthN] = getDataValue("widthNdata", 0);
let [openBlkData, openBlk] = getDataValue("openBlkData", 0);
let preIframes = new Set();
let Dscroll = getValLoc("Dscroll", 0);
let timeDown;
let [textSltData, textSlt] = getDataValue("textSltData", "");
let [imgSltData, imgSlt] = getDataValue("imgSltData", "");
let currentStr = 0;
document.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(event);
} 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 hideAllBtn = createElement("style", null, `html .JQMA-btn-all {display:none!important;}`);
onSlideScreen(document, 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 || offsetX < -thisHeight) {
scrollJu += 1;
} else {
btnJuClick();
return;
}
document.querySelector(".JQMA-btn-Ju").textContent = 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 || offsetX < -thisHeight) {
document.head.appendChild(hideAllBtn);
waitClick(function(event) {
const originalTarget = event.target;
const isInput = originalTarget.matches("a") || originalTarget.closest("a") ? "a" : "input";
const lastTarget = originalTarget.closest(isInput);
if (lastTarget) {
let allNum = 0;
const stopNum = parseInt(prompt("数量", 10)) + 1;
const fragment = document.createDocumentFragment();
docSltAll(prompt("修改选择器:", getSelector(lastTarget))).forEach(el => {
if (el == lastTarget) allNum++;
if (!allNum) return;
allNum++;
if (allNum <= stopNum) {
if (isInput == "input") {
el.checked = !el.checked;
} else if (el.href && !preIframes.has(el.href)) {
preIframes.add(el.href);
const 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 = () => {
setTimeout(() => {
if (iframe.contentDocument) {
const clonedBody = document.importNode(iframe.contentDocument.body, true);
iframe.parentNode.replaceChild(clonedBody, iframe);
}
}, 800);
};
fragment.appendChild(createElement('p', {
class: "pagetual_pageBar"
}));
fragment.appendChild(iframe);
}
}
});
document.body.appendChild(fragment);
} else {
alert("请点击链接或复选框!");
}
});
} else {
btnBlankClick();
}
} else if (eventClass.contains('JQMA-btn-del')) {
let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event);
if (offsetX > thisHeight || offsetY > thisHeight || offsetY < -thisHeight || offsetX < -thisHeight) {
return;
} 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 || offsetX < thisHeight * -3) {
btnPicwhClick();
} else if (offsetY > thisHeight) {
if (minPicwh < picwh && picwh < minPicwh + 100) {
picwh = minPicwh;
} else if (picwh <= minPicwh) {
picwh = 0
} else {
picwh -= 100;
}
picImgFilter();
} else if (offsetY < -thisHeight || offsetX > thisHeight || offsetX < -thisHeight) {
if (picwh == 0) {
picwh = minPicwh;
} else {
picwh += 100;
}
picImgFilter();
} else {
btnPicClick(event);
}
} 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 || offsetX < thisHeight * -3) {
} else if (offsetY > thisHeight) {
if (minOuterSz < outerSz && outerSz < minOuterSz + 10) {
outerSz = minOuterSz;
} else if (outerSz <= minOuterSz) {
outerSz = 0;
} else {
outerSz -= 10;
}
} else if (offsetY < -thisHeight || offsetX > thisHeight || offsetX < -thisHeight) {
if (outerSz === 0) {
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 || offsetX > 3 * thisHeight || offsetX < thisHeight * -3) {
if(textSlt.length){
document.querySelector(".JQMA-inner-word")?.remove();
document.querySelector(".JQMA-mark-pageNum")?.remove();
docSltAll("[JQMA-mark-word]").forEach(function(element) {
element.removeAttribute("JQMA-mark-word");
});
event.target.style.setProperty("color", "green", "important");
endAppendWord();
}
}else if (offsetY < -3 * thisHeight) {
if (!document.querySelector(".JQMA-inner-word") && textSlt.length) {
event.target.style.setProperty("color", "green", "important");
endAppendWord();
}
setTimeout(function() {
readPause();
}, 1000);
return;
} else if (offsetY > thisHeight) {
widthN = widthN ? widthN - 1 : 9;
} else if (offsetY < -thisHeight || offsetX > thisHeight || offsetX < -thisHeight) {
widthN = widthN ? widthN + 1 : 9;
} 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 || offsetX < -thisHeight) {
removeShadowRoot();
} else {
btnScrollDivClick();
}
} else if (eventClass.contains('JQMA-btn-down')) {
let [offsetX, offsetY, thisHeight] = getTouchSite(event.target, event);
if (offsetY > thisHeight * 3) {
const visDiv = visibleDiv('top');
pageX.unshift(visDiv.scrollTop);
autoScrollBy(visDiv, 0, "to");
document.querySelector(".JQMA-btn-down").textContent = "♢";
} else if (offsetY < thisHeight * -3 || offsetX > thisHeight * 3 || offsetX < thisHeight * -3) {
const visDiv = visibleDiv('bottom');
pageX.unshift(visDiv.scrollTop);
autoScrollBy(visDiv, visDiv.scrollHeight, "to");
document.querySelector(".JQMA-btn-down").textContent = "♢";
} else if (offsetY > thisHeight) {
pageNextFunc("up");
} else if (offsetY < -thisHeight || offsetX > thisHeight || offsetX < -thisHeight) {
pageNextFunc("down");
} else {
btnDownClick();
}
}
});
onLongPress(document, function(event) {
const eventClass = event.target.classList;
if (eventClass.contains('JQMA-btn-Ju')) {
let inputNum = window.prompt("请输入滚动速度:" + scrollJu, 5);
if (Number(inputNum)) {
scrollJu = Number(inputNum);
document.querySelector(".JQMA-btn-Ju").textContent = scrollJu;
GM_setValue("scrollJu", scrollJu);
}
} else if (eventClass.contains('JQMA-btn-del')) {
let newHref = [];
[
/(?<=[^a-z]page)([=/])(?=\d)/,
/([^\d])(?=\d+(?:\.html|\/)?$)/,
/([/_\-])(?=\d+\/\?)/
].forEach(pattern => {
let split = location.href.split(pattern);
split.length > 1 && newHref.push(getNextPage(split));
});
!newHref.length && newHref.push(location.href.replace(/\/?$/i, "/2/"));
let pageEnter, twoHref;
const maoHref = location.href.replace(/\/?#?$/i, "/#");
const allA = docSltAll("a").reverse();
for (const _this of allA) {
if (!twoHref && /^\s*0?2\s*$/.test(_this.textContent)) {
twoHref = _this.href;
break;
} else if (/^\s*(?:(?:>|次のページ|下.?[章页頁]|下[一—].)\s*$|下[一—].[::]|next\s*(page\s*)?$)/i.test(_this.textContent)) {
pageEnter = true;
if (_this.href && _this.href != location.href && _this.href != maoHref) {
openHref(_this.href);
} else {
simulateClick(_this);
}
break;
} else if (newHref.includes(_this.href)) {
pageEnter = true;
openHref(_this.href);
break;
}
}!pageEnter && twoHref && openHref(twoHref);
} else if (eventClass.contains('JQMA-btn-outerSz')) {
const menuNum = prompt(`图片集功能:1、可见 2、深度 3、所有\n123(全部)\n@(修改默认 ${defDSI})`, DSImg);
if (menuNum == "@") {
const promptNum = prompt("默认开启:1、可见 2、深度 3、所有", defDSI);
if (promptNum && promptNum != defDSI) {
defDSI = promptNum;
GM_setValue("defDSI", defDSI);
}
} else if (menuNum && DSImg != menuNum) {
DSImg = menuNum;
if (document.querySelector(".JQMA-inner-pic")) {
removePicClass();
endImgInterFn();
}
}
if (DSImg == defDSI) {
delete DSImgData[currentDomain];
} else {
DSImgData[currentDomain] = DSImg;
}
GM_setValue("DSImgData", DSImgData);
} else if (eventClass.contains('JQMA-btn-pic')) {
let inputNum = window.prompt("请输入图片链接替换(`分隔,@开头:正则且数字->[0-9]):", picReplace);
if (inputNum == "所有域名") {
let resultData = changeDataFunc(picRepData, "");
if (resultData)[picRepData, picReplace] = resultData;
} else if (typeof inputNum === "string") {
picReplace = inputNum;
if (picReplace === "") {
delete picRepData[currentDomain];
} else {
picRepData[currentDomain] = picReplace;
if (document.querySelector(".JQMA-inner-pic")) {
removePicClass();
endImgInterFn();
}
}
}
GM_setValue("picRepData", picRepData);
} else if (eventClass.contains('JQMA-btn-width')) {
const innerWord = document.querySelector(".JQMA-inner-word");
const btn = event.target;
if (innerWord) {
innerWord.remove();
document.querySelector(".JQMA-mark-innerBtn")?.remove();
docSltAll("[JQMA-mark-word]").forEach(function(element) {
element.removeAttribute("JQMA-mark-word");
});
} else {
if (textSlt.length) {
endAppendWord();
return;
}
}
waitClick(function(event) {
let _target = event.target;
while (_target && _target !== document.body) {
if (_target.textContent.length > 9) break;
_target = _target.parentNode;
}
const selector = getSelector(_target);
const inputNum = window.prompt(`修改选择器:${selector}`, textSlt.length ? textSlt : selector);
if (inputNum == "所有域名") {
const resultData = changeDataFunc(textSltData, "");
if (resultData)[textSltData, textSlt] = resultData;
} else if (typeof inputNum === "string") {
textSlt = inputNum;
if (textSlt === "") {
delete textSltData[currentDomain];
} else {
textSltData[currentDomain] = textSlt;
}
} else if (inputNum === null) {
btn.style.setProperty("color", "white", "important");
return;
}
GM_setValue("textSltData", textSltData);
endAppendWord();
});
} else if (eventClass.contains('JQMA-btn-down')) {
let menuNum = window.prompt(`1:跳转节点 2:保存位置 ${nextScrollTop}`, 1);
if (menuNum === "1") {
let inputNum = window.prompt("跳转第几个节点:");
if (Number(inputNum) || inputNum === "0") {
let nextNum = Number(inputNum);
pageNextFunc(nextNum);
}
} else if (menuNum === "2") {
let inputNum = window.prompt(`是否保存滚动位置?(取消关闭)${nextScrollTop}`, parseInt(visibleDiv().scrollTop));
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链接,加载页面
100:
==点击:开关图片集
==短滑:上/下 加/减
==长滑:修改过滤尺寸
==长按:输入图片链接替换规则
10:
==点击:点击元素,修改过滤尺寸
==短滑:上/下 加/减
==长滑:滚动加载图片集
==长按:修改图片搜索`);
}
});
function btnDownClick() {
if (pageX.length) {
pageX = Array.from(new Set(pageX));
if (typeof pageX[0] === "number") {
autoScrollBy(visibleDiv(), pageX[0], "to");
} else {
pageX[0].scrollIntoView({
block: "center",
behavior: 'auto'
});
}
pageX.splice(0, 1);
document.querySelector(".JQMA-btn-down").textContent = "♢";
}
}
function pageNextFunc(nextNum) {
pageX.unshift(visibleDiv().scrollTop);
let pageDom = Array.from(document.querySelectorAll(".pagetual_pageBar,.JQMA-mark-pageNext,.JQMA-inner-all>:last-child,.JQMA-inner-word>p[style*=green],video"));
if (Number(nextNum) && nextNum >= pageDom.length) {
pageDom.pop().scrollIntoView({
behavior: 'auto',
block: 'start'
});
document.querySelector(".JQMA-btn-down").textContent = pageDom.length - 1;
return;
}
if (nextNum == "up") pageDom.reverse();
let index = 0;
for (const dom of pageDom) {
index++;
const offsetD = dom.getBoundingClientRect().top;
if (nextNum == index || (nextNum == "up" && offsetD < -.25 * window.innerHeight) ||
(nextNum == "down" && offsetD > .25 * window.innerHeight)) {
dom.scrollIntoView({
behavior: 'auto',
block: 'start'
});
document.querySelector(".JQMA-btn-down").textContent = nextNum == "up" ? pageDom.length - index - 1 : index;
break;
}
}
}
let clearText;
function applyClear() {
clearText = `
html{
overflow-y:visible!important;
}
body{
transform:translate(0%, 0%)!important;
padding:${Dtransform}vh 0!important;
height:auto!important;
max-height:none!important;
}
[JQMA-css-fixed_hide]{
opacity:.3!important;
}`;
publicStyle.textContent += clearText;
setTimeout(function() {
document.querySelectorAll(':not(.JQMA-btn-all)').forEach(el => {
const style = getComputedStyle(el);
if (/sticky|fixed/.test(style.position) && el.offsetHeight < window.innerHeight * 0.5) {
el.setAttribute('JQMA-css-fixed_hide', '1');
}
});
}, 400);
}
function btnTransfClick() {
const _prompt = prompt("请输入上下边距:(取消=关闭)", Dtransform ? Dtransform : "1");
if (_prompt === null) {
Dtransform = 0;
} else {
Dtransform = _prompt > 0 ? _prompt : 1;
}
document.querySelector(".JQMA-btn-transform").style.setProperty("color", Dtransform ? "green" : null, "important");
if (Dtransform) {
applyClear();
DtransformData[currentDomain] = Dtransform;
} else {
publicStyle.textContent = publicStyle.textContent.replace(clearText, "");
delete DtransformData[currentDomain];
}
GM_setValue("DtransformData", DtransformData);
}
let scrollHtmlBody;
let [picRepData, picReplace] = getDataValue("picRepData", "");
function isScrollAt(el, position = 'bottom') {
if(el.matches("html,body")){
if(!scrollHtmlBody && el.scrollTop > 1){
scrollHtmlBody = el;
}
if(el != scrollHtmlBody) return false;
}
const { scrollTop, scrollHeight, clientHeight } = el;
const notTop = scrollTop > 1;
const notBottom = scrollHeight - scrollTop - clientHeight > 1;
return position === 'top' ? notTop :
position === 'bottom' ? notBottom :
notTop || notBottom;
}
const canScroll = (el, testSteps = 'all') => {
const { clientHeight, scrollHeight } = el;
const windowHeight = window.innerHeight;
return clientHeight > 0.6 * windowHeight &&
scrollHeight > Math.max(1.2 * windowHeight, 1.2 * clientHeight) &&
window.getComputedStyle(el).overflowY !== 'hidden' &&
isScrollAt(el, testSteps);
};
let fallbackCallCount = 0;
const findScrollParent = (element, d) => {
let el = element;
while (el && el != document.documentElement) {
if (canScroll(el, d)) {
return el;
}
el = el.parentElement;
}
for (const elem of document.querySelectorAll('*')) {
if (canScroll(elem, d)) {
return elem;
}
}
fallbackCallCount++;
return fallbackCallCount % 2 == 1 ? document.documentElement : document.body;
};
function visibleDiv(_zfs = 'all') {
for (const elem of document.querySelectorAll(":not(.JQMA-inner-all)")) {
if (canScroll(elem, _zfs)) {
return elem;
}
}
fallbackCallCount++;
return fallbackCallCount % 2 == 1 ? document.documentElement : document.body;
}
function autoScrollBy(element, value, mode = "by", direction = "scrollTop") {
if (!element) return;
if (mode === "by") {
element[direction] += value;
} else {
element[direction] = value;
}
}
function downloadTxt(filename, textContent) {
const objectURL = URL.createObjectURL(new Blob([textContent], {
type: "text/plain;charset=utf-8"
}));
const a = createElement('a', {
href: objectURL,
download: filename,
style: "display:none!important;"
});
document.body.appendChild(a);
simulateClick(a);
document.body.removeChild(a);
setTimeout(function() {
URL.revokeObjectURL(objectURL);
}, 2000);
}
function changeStyle(_id, _style) {
docSltAll("head").forEach(function(elet) {
let styleElement = elet.querySelector("style#" + _id);
if (!styleElement) {
elet.appendChild(createElement('style', {
id: _id
}, _style));
} else {
if (styleElement.textContent != _style) {
styleElement.textContent = _style;
}
}
});
}
let defWidthN = GM_getValue("defWidthN", 24);
function fontInterFn() {
changeStyle("JQMA-css-textBig", (widthN ? `
.JQMA-inner-word>p{
font-size:${widthN}px!important;
}
html>body *,html>body [class] *,
html>body [class] [class]{
font-size:${widthN}px!important;
letter-spacing:normal!important;
line-height:normal!important;
}` : "") + (backcolor ? `
html,html>body{
background:#000000!important;
color:#FEFEFE!important;
}
html>body :not(a,a *,button,button *),
html>body [class] :not(a,a *,button,button *) {
background:transparent!important;
color:#FEFEFE!important;
}` : ""));
}
function btnWidthClick() {
let inputNum = window.prompt(`请输入字体大小:(@=修改默认,${defWidthN};#开头=黑色背景)`, widthN ? (backcolor ? "#" : "") + widthN : defWidthN);
if (inputNum && inputNum.startsWith("#")) {
backcolor = 1;
backcolordata[currentDomain] = backcolor;
inputNum = inputNum.replace("#", "");
} else {
backcolor = 0;
delete backcolordata[currentDomain];
}
GM_setValue("backcolordata", backcolordata);
if (inputNum === "@") {
inputNum = window.prompt("请修改默认字体大小:", defWidthN);
defWidthN = Number(inputNum) ? Number(inputNum) : 24;
GM_setValue("defWidthN", defWidthN);
return;
}
widthN = Number(inputNum) ? Number(inputNum) : 0;
widthNFunc();
}
function widthNFunc() {
if (widthN > 0) {
widthNdata[currentDomain] = widthN;
} else {
delete widthNdata[currentDomain];
widthN = 0;
}
fontInterFn();
document.querySelector(".JQMA-btn-width").textContent = widthN ? (backcolor ? "#" : "") + widthN : "W";
GM_setValue("widthNdata", widthNdata);
}
let speakRate = GM_getValue("speakRate", 1);
function readStr() {
const synth = window.speechSynthesis;
synth.cancel();
const speakNext = (index) => {
const wordParagraphs = document.querySelectorAll(".JQMA-inner-word > p");
if (index >= wordParagraphs.length) return;
const paragraph = wordParagraphs[index];
const utterThis = new SpeechSynthesisUtterance(paragraph.textContent);
utterThis.rate = speakRate;
utterThis.onstart = () => {
currentStr = index;
wordParagraphs.forEach(p => p.removeAttribute('style'));
paragraph.style.cssText = "color:green!important;";
innerWordAdd();
if (index > wordParagraphs.length - 5) {
scrollEnd();
}
};
utterThis.onend = () => {
speakNext(index + 1);
};
synth.speak(utterThis);
};
speakNext(currentStr);
}
function readPause() {
try {
new SpeechSynthesisUtterance();
} catch (e) {
alert("浏览器不支持JS朗读!");
return;
}
let readbtn = document.querySelector("#JQMA-mark-readBtn");
if (readbtn.textContent == "暂停") {
readbtn.textContent = "朗读";
window.speechSynthesis.cancel();
} else {
readbtn.textContent = "暂停";
readStr();
}
}
function innerWordAdd() {
const textParts = [];
docSltAll(textSlt).forEach(el => {
if (!el.hasAttribute('JQMA-mark-word')) {
const clone = el.cloneNode(true);
clone.querySelectorAll('style, script, noscript').forEach(tag => tag.remove());
// 替换所有
标签为文本节点
const brElements = clone.querySelectorAll('br');
brElements.forEach(br => {
br.parentNode.replaceChild(document.createTextNode('\n'), br);
});
textParts.push(clone.textContent);
el.setAttribute('JQMA-mark-word', true);
}
});
const processedStr = textParts.join('\n\u3000').replace(/(?:\u00A0| |\t)+|
]*>/g, ' ').replace(/(?:\n\u3000* *)+/g, '\n\u3000');
const allStrlist = processedStr.split(/([\S\s]{1,120}(?:$|[^[一-龟0-9A-Za-z\/、“「\u3000 ]))/);
const endElement = document.querySelector('.JQMA-mark-wordEnd');
const fragment = document.createDocumentFragment();
allStrlist.forEach(text => {
text.replace(/\s+/g, '').length && fragment.appendChild(createElement('p', null, text));
});
endElement.parentNode.insertBefore(fragment, endElement);
}
const htmlVisText = "html {overflow-y: visible!important;}";
function endAppendWord() {
scrollEnd();
setTimeout(()=>appendWord(),500);
}
function appendWord() {
const pOuter = createElement('p', {
class: "JQMA-inner-word JQMA-inner-all"
});
publicStyle.textContent += htmlVisText;
pOuter.addEventListener("click", function(event) {
if (event.target.tagName === "P" && document.querySelector("#JQMA-mark-readBtn")?.textContent != "朗读") {
currentStr = [...event.target.parentElement.children]
.slice(0, [...event.target.parentElement.children].indexOf(event.target))
.filter(el => el.tagName === "P").length;
readStr();
}
});
[
['下载', downloadInnerText],
['朗读', readPause],
[`${speakRate}`, changeRate],
[addWord?'开':`关`, null],
['隐', null]
].forEach(([text, handler],index) => {
const btn = createElement('a', {
style: `left:calc(${3.2*index}vh + ${3.2*index}vw)!important;`,
class: 'JQMA-mark-innerBtn'
}, text);
if(text=='隐'){
btn.onclick=()=>{
const v = pOuter.style.visibility;
pOuter.style.visibility = v == 'hidden' ? 'visible' : 'hidden';
};
document.documentElement.appendChild(btn);
}else if(text==(addWord?'开':`关`)){
btn.onclick=()=>{
addWord = !addWord;
if(addWord){
btn.textContent='开';
addWordData[currentDomain]=addWord
}else{
btn.textContent='关';
delete addWordData[currentDomain];
}
GM_setValue("addWordData", addWordData);
};
pOuter.appendChild(btn);
}else{
if(text=='朗读'){
btn.id='JQMA-mark-readBtn';
}
btn.addEventListener('click', handler === readPause ? handler : (e) => handler(e, btn));
pOuter.appendChild(btn);
}
});
const endOne=createElement('p', {
class: "JQMA-mark-wordEnd"
}, "!阅读结束!")
endOne.onclick=()=>{
scrollEnd();
};
pOuter.appendChild(endOne);
document.documentElement.appendChild(pOuter);
innerWordAdd();
}
function downloadInnerText(event, btn) {
const text = [...document.querySelectorAll(".JQMA-inner-word > p")]
.map(p => p.textContent).join('');
const fileName = document.title.replace(/[\/:*?"<>|]/g, ' ').trim() + '.txt';
downloadTxt(fileName, text);
}
function changeRate(event, btn) {
const input = window.prompt("输入语速:", speakRate);
if (input === null) return;
speakRate = input;
btn.textContent = speakRate;
GM_setValue("speakRate", speakRate);
if(document.querySelector("#JQMA-mark-readBtn")?.textContent != "朗读")readStr();
}
let whProp = GM_getValue("whProp", 3.9);
function picSizeOut(_this) {
const {
naturalWidth: natureW,
naturalHeight: natureH
} = _this;
const imgOuterWH = _this.getAttribute("img-outerWH") || 100;
return Math.min(natureW, natureH) >= picwh &&
natureW / natureH <= whProp && imgOuterWH >= outerSz;
}
function formatStr(_url) {
if (typeof _url === "string") {
return _url.trim().replace(/&/g, "&").replace(/\\u002F/g, "/").replace(/\\[/]/g, "/");
} else {
return "";
}
}
function decodeStr(_url) {
if (_url.startsWith('http%') || _url.startsWith('https%')) {
try {
return decodeURIComponent(_url);
} catch (e) {
return _url;
}
}
return _url;
}
function delHttp(_url) {
let httpParams = [];
try {
new URL(_url).searchParams.forEach((value) => {
if (value.startsWith('http')) {
httpParams.push(decodeStr(value));
}
});
} catch (e) {
return httpParams;
}
return httpParams;
}
const preMatchesO = new Set();
const preMatchesT = new Set();
let firstSpan, twoSpan, pAll;
const QUOTE_REGEX = /"|['']/g;
const videoRegex = /https?[:%][^"<>\s|]+\.(?:avi|mp4|mov|m4v|m3u8|wmv|flv|f4v)(?:[?!/&%][^"<>\s|]+)?(?=["<>\s一-龟|]|https?[:%]|$)/gi;
const videoUrlReg = /(\.|%2E)(avi|m3u8|mp4|mov|m4v|wmv|flv|f4v)([?!/&%#]|$)/i;
function xiuTan() {
if (!document.querySelector(".JQMA-btn-hrefAll")) {
const styles = `
.JQMA-btn-hrefSpan{
margin-left:auto!important;
height:calc(1vh + 1vw)!important;
width:calc(1vh + 1vw)!important;
line-height:.8!important;
background:red!important;
position:static!important;
}.JQMA-btn-hrefAll{
background:none!important;
overflow:scroll!important;
height:auto!important;
width:auto!important;
max-height:calc(8vh + 8vw)!important;
max-width:calc(10vw + 10vh)!important;
bottom:2px!important;
right:0!important;
}.JQMA-btn-hrefAll::-webkit-scrollbar{
display: none!important;
}.JQMA-btn-href{
text-align:left!important;
position:static!important;
width:calc(10vw + 10vh)!important;
white-space:nowrap!important;
}`;
const spans = ['1', '2', ''].map(i =>
createElement('span', {
class: `JQMA-btn-all JQMA-btn-hrefSpan`
}, i)
);
[pAll, firstSpan, twoSpan] = [
createElement('p', { class: 'JQMA-btn-all JQMA-btn-hrefAll' }),
spans[1],
spans[2]
];
pAll.append(
createElement('style', null, styles),
...spans
);
document.documentElement.appendChild(pAll);
}
const collectVideoUrls = () => {
const playSet = new Set();
const videoSet = new Set();
docSltAll("video,video>source").forEach(element => {
const src = element.currentSrc || element.src;
src && videoSet.add(src);
});
window.performance.getEntries()
.filter(entry => videoUrlReg.test(entry.name))
.forEach(entry => playSet.add(entry.name));
const iframeContents = [];
Object.values(iframeData).forEach(outerhtml => {
outerhtml.videos.forEach(v => v && videoSet.add(v));
outerhtml.entries
.filter(entry => videoUrlReg.test(entry))
.forEach(entry => playSet.add(entry));
iframeContents.push(outerhtml.html);
});
const pageSource = document.documentElement.outerHTML + iframeContents.join('');
const matches = new Set(pageSource.replace(QUOTE_REGEX, '"').match(videoRegex) || []);
return { playSet, videoSet, matches };
};
const processVideos = (urlSet, beforeElement, preMatches) => {
const newVideoSet = [...urlSet]
.map(url => formatStr(url))
.filter(url => url.replace(/[\s/]/g, "").length && !/^(?!https?:)[a-z]{3,15}:/.test(url))
.flatMap(url => {
const delHtList = delHttp(url);
return [
url,
...delHtList
];
});
const fragment = document.createDocumentFragment();
const videoNum = pAll.children.length;
let _index = 0;
newVideoSet.forEach(url => {
const processedUrl = addLocation(decodeStr(url));
if (preMatches.has(processedUrl)) return;
preMatches.add(processedUrl);
_index++;
const fileName = processedUrl.replace(/.+\/(?=[^/])|(?<=m3u8)\?.+/g, "");
const displayText = `${videoNum + _index - 4} ${fileName} ${document.title}`;
fragment.append(
createElement('a', {
href: processedUrl,
target: '_blank',
class: "JQMA-btn-all JQMA-btn-href",
}, displayText)
);
});
pAll.insertBefore(fragment, beforeElement);
};
const { playSet, videoSet, matches } = collectVideoUrls();
[[playSet, firstSpan, preMatchesO], [videoSet, twoSpan, preMatchesT], [matches, twoSpan, preMatchesT]].forEach(([urlSet, span, preM]) => {
processVideos(urlSet, span, preM);
});
}
function getMinPicwh(_this) {
return Math.min(_this.naturalWidth, _this.naturalHeight);
}
function getPercentW(_this) {
return parseInt(_this.offsetWidth / window.innerWidth * 100);
}
function waitClick(afterFunc) {
document.head.appendChild(hideAllBtn);
setTimeout(function() {
docSltAll("body:not(body *)").forEach(_this =>{
_this.addEventListener('touchstart', tempClickFunc, {passive: false});
});
function tempClickFunc(event) {
event.preventDefault();
docSltAll("body").forEach(function(_this) {
_this.removeEventListener('touchstart', tempClickFunc);
});
document.head.removeChild(hideAllBtn);
afterFunc(event);
}
}, 100);
}
function btnOuterSzClick() {
let inputNum = window.prompt(`请输入过滤尺寸:${outerSz}`);
if (Number(inputNum) || inputNum === "0") {
outerSz = Number(inputNum);
if (outerSz < minOuterSz) outerSz = minOuterSz;
outerSz_run();
}
}
function outerSz_run() {
if (outerSz < 0) outerSz = 0;
picImgFilter();
document.querySelector(".JQMA-btn-outerSz").textContent = outerSz;
setValLoc("outerSz", outerSz);
}
function btnPicwhClick() {
let inputNum = window.prompt(`请输入 过滤尺寸:(@ = 修改默认,${picwh})`);
if (/^\d+$/.test(inputNum)) {
picwh = Number(inputNum);
if (picwh < minPicwh) picwh = minPicwh;
picImgFilter();
} else if (inputNum === "@") {
inputNum = window.prompt(`请输入 过滤宽高比,最小过滤尺寸,最小过滤宽度,最大转高清尺寸:(推荐: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 (document.querySelector(".JQMA-inner-pic")) {
document.querySelectorAll(".JQMA-inner-pic > .JQMA-mark-imgLoaded").forEach((_this) => {
_this.classList.toggle("JQMA-css-smallPic", !picSizeOut(_this));
});
}
document.querySelector(".JQMA-btn-pic").textContent = picwh;
setValLoc("picwh", picwh);
}
function btnPicClick(event) {
const btn = event.target;
const innerPic = document.querySelector(".JQMA-inner-pic");
if (innerPic) {
innerPic.remove();
removePicClass();
waitClick(function(event) {
let _target = event.target;
let _this = _target;
const srcArr = new Set();
const getImgSrc = el => {
if (el.matches('img')) srcArr.add(el.currentSrc || el.src);
if (el.matches('video') && el.poster) srcArr.add(el.poster);
const bgUrls = getComputedStyle(el).backgroundImage.matchAll(/url\(['"]?(.*?)['"]?\)/g);
[...bgUrls].forEach(match => match[1] && srcArr.add(match[1]));
};
getImgSrc(_this);
if(srcArr.size==0){
[..._this. querySelectorAll("*")].forEach(getImgSrc);
}else{
_this=_this.parentElement;
}
for(let i=0;!srcArr.size && _this.parentElement && i<3;i++){
_this=_this.parentElement;
[..._this.querySelectorAll("*")].forEach(getImgSrc);
}
const selector = getSelector(srcArr.size ? _this : _target, 5);
const inputNum = window.prompt(`空白=全选\n修改选择器:${selector}`,imgSlt ? getCommonSelector(selector,imgSlt) : selector);
if (inputNum == "所有域名") {
const resultData = changeDataFunc(imgSltData, "");
if (resultData)[imgSltData, imgSlt] = resultData;
} else if (typeof inputNum === "string") {
imgSlt = inputNum;
if (imgSlt === "") {
delete imgSltData[currentDomain];
} else {
imgSltData[currentDomain] = imgSlt;
}
endImgInterFn();
} else if (inputNum === null) {
return;
}
GM_setValue("imgSltData", imgSltData);
});
} else {
endImgInterFn();
}
}
function scrollEnd() {
const visDiv = visibleDiv('bottom');
pageX.unshift(visDiv.scrollTop);
autoScrollBy(visDiv, visDiv.scrollHeight, "to");
}
function scrollPicLoad() {
}
function removePicClass() {
document.querySelectorAll(".pagetual_pageBar").forEach((_this) => {
_this.classList.remove("JQMA-mark-pageNext");
});
preImgArr = [new Set(), new Set(), new Set()];
document.querySelector(".JQMA-inner-pic")?.remove();
document.querySelector(".JQMA-mark-innerBtn")?.remove();
}
function addLocation(_href) {
try {
return new URL(_href, currentDomain).href;
} catch (e) {
return _href;
}
}
function getImgList(dataObj, _this, preImgNum) {
const imgList = [];
dataObj.forEach(item => {
item = formatStr(item);
if (!item.replace(/[\s/]/g, "").length) return;
item = addLocation(decodeStr(item));
if (preImgArr[preImgNum].has(item)) return;
preImgArr[preImgNum].add(item);
const newImg = createElement('img', {
src: item,
loading: 'lazy',
width: '300',
height: '100',
decoding: 'async'
});
const _newA = document.createElement('a');
newImg.addEventListener('load', function() {
imgLoadError(newImg, _newA, preImgNum);
newImg.classList.add("JQMA-mark-imgLoaded");
});
newImg.addEventListener('error', function() {
imgLoadError(newImg, _newA, preImgNum);
});
imgList.push(newImg);
if (_this) {
newImg.setAttribute('img-outerWH', getPercentW(_this));
_this.addEventListener('load', function() {
const _percW = getPercentW(_this);
newImg.setAttribute('img-outerWH', _percW);
_newA.textContent = `${getMinPicwh(newImg)} ${_percW}`;
newImg.classList.toggle("JQMA-css-smallPic", !picSizeOut(newImg));
});
_newA.addEventListener("click", () => scrollOrClick(_this));
} else {
newImg.setAttribute('img-outerWH', 10);
}
imgList.push(_newA);
});
return imgList;
}
function scrollOrClick(_this) {
_this.scrollIntoView({
block: "end",
behavior: 'auto'
});
}
let [moodNumData, moodNum] = getDataValue("moodNumData", "auto");
let moodText;
let preImgArr = [new Set(), new Set(), new Set()];
const imgRegex_1 = /https?[:%][^"<>\s|]+\.(?:xbm|tif|pjp|jpe?g|tiff|gif|jfif|webp|png|bmp|pjpeg|avif)(?:[?!/&%][^"<>\s|]+)?(?=["<>\s一-龟|]|https?[:%]|$)/gi
const imgRegex_2 = /((?<=")[a-z]*\/|https?[:%])[^"<>\s|]+\.(?:xbm|tif|pjp|jpe?g|tiff|gif|jfif|webp|png|bmp|pjpeg|avif)(?:[?!/&%][^"<>\s|]+)?(?=["<>\s|]|https?[:%]|$)/i
let pageNext_0, pageNext_1, pageNext_2, innerPic;
function endImgInterFn() {
scrollPicLoad();
setTimeout(()=>imgInterFn(),500);
}
function imgInterFn() {
if (!document.querySelector(".JQMA-inner-pic")) {
const newP = createElement('p', {
class: "JQMA-inner-pic JQMA-inner-all"
});
publicStyle.textContent += htmlVisText;
[
{ id: "JQMA-mark-moodNum", text: moodNum},
{ id: "JQMA-mark-pageNext_0", text: `顶`},
{ id: "JQMA-mark-returnTop", text: "回"},
{ id: "JQMA-mark-picAdd", text: addPic?'开':'关'},
{ id: "JQMA-mark-picVisible", text: "隐"}
].forEach((t, index) => {
const p=createElement('p', {
style: `left:calc(${3.2*index}vh + ${3.2*index}vw)!important;`,
class: `JQMA-mark-innerBtn`,
id: t.id
}, t.text);
if(index==0){
if (moodNum != "auto") {
moodText = `html .JQMA-inner-pic>img{width:${moodNum}!important;}`;
publicStyle.textContent += moodText;
}
p.addEventListener("click", function() {
const theStr = prompt(`${moodText} 默认:auto 可选:1~100%`, moodNum);
if (!theStr) return;
moodNum = theStr;
publicStyle.textContent = publicStyle.textContent.replace(moodText, "");
if (moodNum != "auto") {
moodNum = moodNum.replace(/%?$/,"%");
moodText = `html .JQMA-inner-pic>img{width:${moodNum}!important;}`;
publicStyle.textContent += moodText;
moodNumData[currentDomain] = moodNum;
} else {
delete moodNumData[currentDomain];
}
p.textContent = moodNum;
GM_setValue("moodNumData", moodNumData);
});
}
if(t.id=='JQMA-mark-picVisible'){
p.onclick=()=>{
const v=newP.style.visibility;
newP.style.visibility=v=='hidden'?'visible':'hidden';
};
document.documentElement.appendChild(p);
}else{
if(t.id=='JQMA-mark-returnTop'){
p.onclick=()=>{
if(returnTop)newP.scrollTop = returnTop;
};
}else if(t.id=='JQMA-mark-picAdd'){
p.onclick=()=>{
addPic = !addPic;
if(addPic){
p.textContent='开';
addPicData[currentDomain]=addPic
}else{
p.textContent='关';
delete addPicData[currentDomain];
}
GM_setValue("addPicData", addPicData);
};
}
newP.appendChild(p);
}
});
["深度搜索", "可见元素", "所有图片"].forEach((textContent, index) => {
newP.appendChild(createElement('p', {
class: `JQMA-mark-pageNext JQMA-mark-pageNext_${index} JQMA-mark-pageNum`
}, textContent));
});
document.documentElement.appendChild(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");
innerPic = document.querySelector(".JQMA-inner-pic");
const imgArr_0 = [];
const imgArr_1 = [];
docSltAll(imgSlt + " *").forEach(function(_this) {
if (_this.classList.contains("pagetual_pageBar")) {
if (!_this.classList.contains("JQMA-mark-pageNext")) {
_this.classList.add("JQMA-mark-pageNext");
if (DSImg.includes('1') && (!imgArr_0.length || !imgArr_0[imgArr_0.length - 1].classList.contains('JQMA-mark-pageNext'))) {
imgArr_0.push(createElement('p', {
class: "JQMA-mark-pageNext"
}));
}
if (DSImg.includes('2') && (!imgArr_1.length || !imgArr_1[imgArr_1.length - 1].classList.contains('JQMA-mark-pageNext'))) {
imgArr_1.push(createElement('p', {
class: "JQMA-mark-pageNext"
}));
}
}
return true;
}
const srcArr = [];
if (_this.matches("img:not(.JQMA-inner-pic>*)")) {
srcArr.push(_this.currentSrc || _this.src);
} else if (_this.matches("video")) {
if (_this.poster) srcArr.push(_this.poster);
}
const bgUrls = window.getComputedStyle(_this).backgroundImage
.matchAll(/url\(['"]?(.*?)['"]?\)/g);
Array.from(bgUrls).forEach(match => match[1] && srcArr.push(match[1]));
if (srcArr.length) {
if (DSImg.includes('1')) {
const imgList = getImgList(srcArr, _this, 0);
if (imgList.length) imgArr_0.push(...imgList);
}
if (DSImg.includes('2')) {
const fragmentParts = [];
const parentLink = _this.closest('a');
if (parentLink) {
const linkClone = parentLink.cloneNode();
linkClone.style.cssText = '';
fragmentParts.push(linkClone.outerHTML);
}
const elementClone = _this.cloneNode();
['style', 'src', 'poster'].forEach(attr => elementClone.removeAttribute(attr));
fragmentParts.push(elementClone.outerHTML);
const imageUrlMatch = fragmentParts.join('').replace(QUOTE_REGEX, '"').match(imgRegex_2)?.[0];
if (imageUrlMatch) {
const newImages = getImgList([imageUrlMatch], _this, 1);
if (newImages.length) imgArr_1.push(...newImages);
}
}
}
});
if (imgArr_0.length) {
const fragment0 = document.createDocumentFragment();
imgArr_0.forEach(imgElement => fragment0.appendChild(imgElement));
pageNext_2.parentNode.insertBefore(fragment0, pageNext_2);
}
if (imgArr_1.length) {
const fragment1 = document.createDocumentFragment();
imgArr_1.forEach(imgElement => fragment1.appendChild(imgElement));
pageNext_1.parentNode.insertBefore(fragment1, pageNext_1);
}
if (DSImg.includes('3')) {
const htmlArray = Object.values(iframeData);
const imageUrls = htmlArray.flatMap(data => data.imgs);
const allHtmlContent = document.documentElement.outerHTML +
htmlArray.map(data => data.html || '').join('');
const allHtmlImg = allHtmlContent.replace(QUOTE_REGEX, '"').match(imgRegex_1);
if (allHtmlImg) imageUrls.push(...allHtmlImg);
const imgList = getImgList(imageUrls, false, 2);
if (imgList.length) {
const fragment = document.createDocumentFragment();
imgList.forEach(_img => fragment.appendChild(_img));
innerPic.appendChild(fragment);
}
}
picImgCount(pageNext_0, pageNext_1, pageNext_2);
}
function imgLoadError(elet, _newA, preImgNum) {
picImgCount(pageNext_0, pageNext_1, pageNext_2);
let oldNatureH = elet.naturalHeight;
let oldNatureW = elet.naturalWidth;
let minWH = Math.min(oldNatureW, oldNatureH);
if (minWH < minPicHD) {
const srcList = picHD(elet.currentSrc).filter(src=>{
if(!preImgArr[preImgNum].has(src)){
preImgArr[preImgNum].add(src);
return true;
}
return false;
});
const promises = srcList.map(src => checkImgExists(src).catch(() => {}));
Promise.all(promises).then(data => {
const betterImg = data.find(img => img.naturalHeight > oldNatureH || img.naturalWidth > oldNatureW);
if (betterImg) {
elet.src = betterImg.src;
}
});
}
setTimeout(function() {
elet.classList.toggle("JQMA-css-smallPic", !picSizeOut(elet));
if (_newA) _newA.textContent = `${minWH} ${elet.getAttribute("img-outerWH")}`;
}, 100);
}
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;
}
let picImgTime;
function picImgCount(pageNext_0, pageNext_1, pageNext_2) {
clearTimeout(picImgTime);
picImgTime = setTimeout(function() {
const picImgLen = document.querySelectorAll(".JQMA-inner-pic > img:not(.JQMA-css-smallPic)").length;
const keJian_Img = prevAll(pageNext_1, "img:not(.JQMA-css-smallPic)").length;
const search_len = prevAll(pageNext_2, "img:not(.JQMA-css-smallPic)").length;
pageNext_0.textContent = `深度:${keJian_Img} `;
const texts = [
{ id: "JQMA-mark-pageNext_1", text: `可见:${search_len - keJian_Img} ` },
{ id: "JQMA-mark-pageNext_2", text: `所有:${picImgLen - search_len} ` },
{ id: "JQMA-mark-lastOne", text: "最后" }
];
texts.forEach(item => {
pageNext_0.appendChild(createElement("a", { id: item.id }, item.text));
});
}, 400);
}
function picHD(oldSrc) {
const thisSrcList = new Set();
if (picReplace.indexOf("`") != -1) {
const numberToRe = /^@/.test(picReplace) ? 1 : 0,
picRepArr = picReplace.replace(/^@/, "").split("`");
let thisSrc = oldSrc;
for (let i = 0; i < parseInt(picRepArr.length / 2); i++) {
thisSrc = thisSrc.replace(numberToRe ? new RegExp(picRepArr[2 * i].replace(/(? thisSrcList.add(src));
if (!/.https?[:%]/.test(oldSrc)) {
thisSrcList.add(oldSrc.replace(/^([^?]+?)&.*$/, "$1"));
}
return [...thisSrcList];
}
const picAimgText1 = `
html .JQMA-inner-pic>a{
height:0!important;
border:0!important;
}`;
const picAimgText2 = `
html .JQMA-btn-all{
display:block!important;
}html .JQMA-btn-del{
opacity:1!important;
}`;
function delHide() {
if (Dhide) {
if (publicStyle.textContent.includes(picAimgText2)) {
publicStyle.textContent = publicStyle.textContent.replace(picAimgText2, picAimgText1);
} else {
publicStyle.textContent += picAimgText1;
}
} else {
if (publicStyle.textContent.includes(picAimgText1)) {
publicStyle.textContent = publicStyle.textContent.replace(picAimgText1, picAimgText2);
} else {
publicStyle.textContent += picAimgText2;
}
xiuTan();
}
}
function btnDelClick() {
Dhide = Dhide ? 0 : 1;
delHide();
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) {
try {
const a = document.createElement('a');
a.href = newHref; a.target = '_blank';
a.rel = 'noopener noreferrer';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} catch {
GM_openInTab(newHref);
}
}
function aOpenBlank() {
docSltAll("head").forEach(function(elet) {
const baseId = "JQMA-mark-openNew";
!elet.querySelector(`#${baseId}`) && elet.appendChild(createElement('base', {id:baseId,target:"_blank",rel:"noopener noreferrer"}));
});
docSltAll('a[target]').forEach(link => {
link.removeAttribute('target');
});
}
function btnBlankClick() {
openBlk = openBlk ? 0 : 1;
document.querySelector(".JQMA-btn-blank").style.setProperty("color", openBlk ? "green" : null, "important");
if (openBlk) {
aOpenBlank();
openBlkData[currentDomain] = openBlk;
} else {
delete openBlkData[currentDomain];
docSltAll("head > base#JQMA-mark-openNew").forEach(_this => _this.remove());
}
setValLoc("openBlkData", openBlkData);
}
let fullBodyText;
function fullScreen() {
if (document.fullscreenElement) return;
fullBodyText = `
${Drotate_W}{
overflow:auto!important;
}
body{
min-width:100%!important;
}`;
publicStyle.textContent += fullBodyText;
document.querySelector(Drotate_W)?.requestFullscreen();
screen.orientation.lock('landscape').catch(e => {
screen.orientation.lock = hengPin;
screen.orientation.lock('landscape');
});
}
let Drotate = getValLoc("Drotate", 0);
let [Drotate_Wdata, Drotate_W] = getDataValue("Drotate_Wdata", 'html');
function scrollRun() {
Dscroll = Dscroll ? 0 : 1;
clearInterval(timeDown);
document.querySelector(".JQMA-btn-Ju").style.setProperty("color", Dscroll ? "green" : null, "important");
if (Dscroll) {
timeDown = setInterval(function() {
let inner = document.fullscreenElement || document.querySelector(".JQMA-inner-all");
if (inner?.style.visibility == 'hidden') {
inner = null;
}
autoScrollBy(findScrollParent(inner, scrollJu>0?'bottom':'top'), scrollJu * window.innerHeight * .05);
}, 800);
}
}
function btnJuClick() {
scrollRun();
setValLoc("Dscroll", Dscroll);
}
})();
}