diff --git a/.github/workflows/json-validator.yml b/.github/workflows/json-validator.yml index a726236d040..01911cc1730 100644 --- a/.github/workflows/json-validator.yml +++ b/.github/workflows/json-validator.yml @@ -13,9 +13,9 @@ jobs: - uses: actions/checkout@v4 - name: json-yaml-validate - uses: GrantBirki/json-yaml-validate@v3.0.0 + uses: GrantBirki/json-yaml-validate@v5 id: json-yaml-validate with: json_schema: Pagetual/pagetual.schema.json files: | - Pagetual/pagetualRules.json \ No newline at end of file + Pagetual/pagetualRules.json diff --git a/BingBgForBaidu/BingBgForBaidu.user.js b/BingBgForBaidu/BingBgForBaidu.user.js index 6c86b1050dd..ba0fa832396 100644 --- a/BingBgForBaidu/BingBgForBaidu.user.js +++ b/BingBgForBaidu/BingBgForBaidu.user.js @@ -2,7 +2,7 @@ // @name 百Bing图 // @name:en BingBgForBaidu // @namespace hoothin -// @version 2.3.44 +// @version 2.3.45 // @description 给百度首页换上Bing的背景图,并添加背景图链接与日历组件 // @description:en Just change the background image of baidu.com to bing.com // @author hoothin @@ -124,7 +124,10 @@ } }; var skinContainer=document.getElementsByTagName("body")[0]; - GM_addStyle(".s-news-rank-content{max-height: 180px; width: 99%; overflow-y: auto; overflow-x: hidden;}.s-top-right .ai-entry-right-nologin,.s-top-right .operate-wrapper-nologin{right:362px;}.hot-refresh{padding-bottom:7px;}.hot-title>div,.hot-refresh{border-radius: 3px 3px 0 0}.s-hotsearch-title>a,.s-hotsearch-title>a>div{padding: 5px;background-color: #f0f8ff95;border-radius: 5px;}.s-hotsearch-content{position: absolute; background-color: #f0f8ff95; border-radius: 5px;padding: 5px;}.s_ipt{margin:0!important;}.s_ipt_wr{border-radius: 10px 4px 4px 10px;border-radius: 10px 0 0 10px;background: #fff!important;}#qrcodeCon{display:none}body{position:fixed;_position:absolute;top:0;left:0;height:100%;width:100%;min-width:1000px;z-index:-10;background-position:center 0;background-repeat:no-repeat;background-size:cover;-webkit-background-size:cover;-o-background-size:cover;zoom:1;}"); + if (!document.querySelector(".aigc-skin-bg,#s_mancard_main")) { + GM_addStyle(".s-news-rank-content{max-height: 180px; width: 99%; overflow-y: auto; overflow-x: hidden;}.s-top-right .ai-entry-right-nologin,.s-top-right .operate-wrapper-nologin{right:362px;}.hot-refresh{padding-bottom:7px;}.hot-title>div,.hot-refresh{border-radius: 3px 3px 0 0}.s-hotsearch-title>a,.s-hotsearch-title>a>div{padding: 5px;background-color: #f0f8ff95;border-radius: 5px;}.s-hotsearch-content{position: absolute; background-color: #f0f8ff95; border-radius: 5px;padding: 5px;}"); + } + GM_addStyle(".s_ipt{margin:0!important;}.s_ipt_wr{border-radius: 10px 4px 4px 10px;border-radius: 10px 0 0 10px;background: #fff!important;}#qrcodeCon{display:none}body{position:fixed;_position:absolute;top:0;left:0;height:100%;width:100%;min-width:1000px;z-index:-10;background-position:center 0;background-repeat:no-repeat;background-size:cover;-webkit-background-size:cover;-o-background-size:cover;zoom:1;}"); var inputsu=document.querySelector("input#su"); var clickHandler=e=>{ if(skinContainer)skinContainer.style.backgroundImage=""; diff --git a/Pagetual/README.md b/Pagetual/README.md index c58d65bd3fc..40854710e73 100644 --- a/Pagetual/README.md +++ b/Pagetual/README.md @@ -1,8 +1,8 @@ -[☯️](https://greasyfork.org/scripts/438684 "Install from greasyfork")東方永頁機 [v.1.9.37.127](https://hoothin.github.io/UserScripts/Pagetual/pagetual.user.js "Latest version") +[☯️](https://greasyfork.org/scripts/438684 "Install from greasyfork")東方永頁機 [v.1.9.37.131](https://hoothin.github.io/UserScripts/Pagetual/pagetual.user.js "Latest version") == *Pagetual - Perpetual pages. Auto loading paginated web pages for 90% of all web sites !* -🔧CONFIGURATION PAGE +🔧CONFIGURATION PAGE

@@ -30,10 +30,7 @@ https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRu
         Send 📧email
     
     
-        Made with ❤️ by Hoothin
-    
-    
-        
+        
Made with ❤️ by Hoothin diff --git a/Pagetual/pagetual.user.js b/Pagetual/pagetual.user.js index ddc0c1d1acf..ae4b3ad94f3 100644 --- a/Pagetual/pagetual.user.js +++ b/Pagetual/pagetual.user.js @@ -31,7 +31,7 @@ // @name:da Pagetual // @name:fr-CA Pagetual // @namespace hoothin -// @version 1.9.37.127 +// @version 1.9.37.132 // @description Perpetual pages - powerful auto-pager script. Auto fetching next paginated web pages and inserting into current page for infinite scroll. Support thousands of web sites without any rule. // @description:zh-CN 终极自动翻页 - 加载并拼接下一分页内容至当前页尾,智能适配任意网页 // @description:zh-TW 終極自動翻頁 - 加載並拼接下一分頁內容至當前頁尾,智能適配任意網頁 @@ -137,6 +137,9 @@ if (document.body && getComputedStyle(document.body).display === 'none') { document.body.style.display = 'block'; } + Element.prototype.scrollIntoView = function() { + console.log('ScrollIntoView blocked.'); + }; return; } @@ -4166,12 +4169,199 @@ } } + function requestWithFetch(f, onFetchError) { + function getHeaderValue(headers, name) { + if (!headers || !name) return ""; + let lowerName = String(name).toLowerCase(); + if (typeof Headers !== "undefined" && headers instanceof Headers) { + return headers.get(lowerName) || ""; + } + if (typeof headers === "object") { + for (let key in headers) { + if (Object.prototype.hasOwnProperty.call(headers, key) && String(key).toLowerCase() === lowerName) { + return headers[key] || ""; + } + } + } + return ""; + } + function extractCharsetFromContentType(contentType) { + if (!contentType || typeof contentType !== "string") return ""; + let match = contentType.match(/charset\s*=\s*["']?([^;"'\s]+)/i); + return match && match[1] ? match[1].trim() : ""; + } + function decodeArrayBufferByCharset(buffer, preferredCharset) { + let bytes = new Uint8Array(buffer); + let decoderList = []; + let normalize = label => String(label || "").trim().toLowerCase(); + let addAlias = (name, aliases) => { + if (aliases.indexOf(normalizedPreferred) !== -1) { + pushDecoder(name); + for (let i = 0; i < aliases.length; i++) { + pushDecoder(aliases[i]); + } + } + }; + let pushDecoder = label => { + let raw = String(label || "").trim(); + if (raw && decoderList.indexOf(raw) === -1) { + decoderList.push(raw); + } + }; + let normalizedPreferred = normalize(preferredCharset).replace(/["']/g, ""); + pushDecoder(preferredCharset); + pushDecoder(normalizedPreferred); + pushDecoder(normalizedPreferred.replace(/_/g, "-")); + pushDecoder(normalizedPreferred.replace(/-/g, "_")); + addAlias("shift_jis", ["shiftjis", "shift-jis", "sjis", "ms_kanji", "windows-31j", "cp932", "ms932"]); + addAlias("euc-jp", ["eucjp"]); + addAlias("iso-2022-jp", ["iso2022jp", "jis"]); + addAlias("gb18030", ["gbk", "gb2312", "x-gbk", "cp936", "ms936", "windows-936"]); + addAlias("big5", ["big-5", "cn-big5", "x-x-big5"]); + addAlias("euc-kr", ["euckr", "ks_c_5601-1987", "ksc5601", "windows-949", "cp949"]); + addAlias("windows-1251", ["cp1251"]); + addAlias("windows-1252", ["cp1252", "iso-8859-1", "latin1", "latin-1"]); + pushDecoder("utf-8"); + for (let i = 0; i < decoderList.length; i++) { + try { + return new TextDecoder(decoderList[i]).decode(bytes); + } catch (e) {} + } + try { + return new TextDecoder().decode(bytes); + } catch (e) { + return ""; + } + } + function detectCharsetFromHtmlHead(buffer) { + if (!buffer || !buffer.byteLength) return ""; + let scanLen = Math.min(buffer.byteLength, 16384); + let bytes = new Uint8Array(buffer, 0, scanLen); + let ascii = ""; + for (let i = 0; i < bytes.length; i++) { + let code = bytes[i]; + ascii += code < 128 ? String.fromCharCode(code) : " "; + } + let charsetMatch = ascii.match(/]*charset\s*=\s*["']?\s*([a-zA-Z0-9._-]+)/i); + if (!charsetMatch) { + charsetMatch = ascii.match(/]*content\s*=\s*["'][^"']*charset\s*=\s*([a-zA-Z0-9._-]+)/i); + } + return charsetMatch && charsetMatch[1] ? charsetMatch[1].trim() : ""; + } + function isUtf8Charset(label) { + let normalized = String(label || "").trim().toLowerCase().replace(/_/g, "-"); + return !normalized || normalized === "utf-8" || normalized === "utf8"; + } + if (!f || !f.url || typeof fetch === "undefined") { + if (onFetchError) { + onFetchError({error: "Fetch not available"}); + } else if (f && f.onerror) { + f.onerror({error: "Fetch not available"}); + } + return; + } + let method = (f.method || "GET").toUpperCase(); + let timeoutId = null; + let controller = typeof AbortController !== "undefined" ? new AbortController() : null; + if (f.timeout > 0 && controller) { + timeoutId = setTimeout(() => { + controller.abort(); + }, f.timeout); + } + let options = { + method: method, + headers: f.headers || {} + }; + if (controller) options.signal = controller.signal; + if (method !== "GET" && method !== "HEAD" && typeof f.data !== "undefined") { + options.body = f.data; + } + fetch(f.url, options).then(async response => { + if (timeoutId) clearTimeout(timeoutId); + let responseCharset = extractCharsetFromContentType(response.headers.get("content-type") || ""); + let overrideCharset = extractCharsetFromContentType(f.overrideMimeType || ""); + let requestCharset = extractCharsetFromContentType(getHeaderValue(options.headers, "content-type")); + let text; + let charsetFromHeaders = responseCharset || overrideCharset || requestCharset; + if (charsetFromHeaders) { + if (isUtf8Charset(charsetFromHeaders)) { + text = await response.text(); + } else { + text = decodeArrayBufferByCharset(await response.arrayBuffer(), charsetFromHeaders); + } + } else { + let rawBuffer = await response.arrayBuffer(); + let metaCharset = detectCharsetFromHtmlHead(rawBuffer); + let targetCharset = metaCharset || charset || "utf-8"; + if (isUtf8Charset(targetCharset)) { + text = new TextDecoder("utf-8").decode(new Uint8Array(rawBuffer)); + } else { + text = decodeArrayBufferByCharset(rawBuffer, targetCharset); + } + } + let headers = ""; + response.headers.forEach((value, key) => { + headers += key + ": " + value + "\r\n"; + }); + if (f.onload) { + f.onload({ + response: text, + responseText: text, + status: response.status, + statusText: response.statusText, + finalUrl: response.url, + responseHeaders: headers + }); + } + }).catch(error => { + if (timeoutId) clearTimeout(timeoutId); + if (error && error.name === "AbortError" && f.ontimeout) { + f.ontimeout(error); + return; + } + if (onFetchError) { + onFetchError(error); + } else if (f.onerror) { + f.onerror(error); + } + }); + } + function isSameOriginRequest(f) { + if (!f || !f.url || typeof location === "undefined") return false; + try { + return new URL(f.url, location.href).origin === location.origin; + } catch (e) { + return false; + } + } + let nativeGMRequest = null; if (typeof GM_xmlhttpRequest !== 'undefined') { - _GM_xmlhttpRequest = GM_xmlhttpRequest; + nativeGMRequest = GM_xmlhttpRequest; } else if (typeof GM !== 'undefined' && typeof GM.xmlHttpRequest !== 'undefined') { - _GM_xmlhttpRequest = GM.xmlHttpRequest; + nativeGMRequest = GM.xmlHttpRequest; + } + if (nativeGMRequest) { + _GM_xmlhttpRequest = function(f) { + if (!f) return nativeGMRequest(f); + if (isSameOriginRequest(f)) { + requestWithFetch(f); + return; + } + let originalOnerror = f.onerror; + let request = Object.assign({}, f); + request.onerror = function(gmError) { + requestWithFetch(f, function(fetchError) { + if (originalOnerror) { + originalOnerror(fetchError || gmError || {error: "Request failed"}); + } + }); + }; + return nativeGMRequest(request); + }; } else { - _GM_xmlhttpRequest = (f) => {fetch(f.url, {method: f.method || 'GET', body: f.data, headers: f.headers}).then(response => response.text()).then(data => {f.onload && f.onload({response: data})}).catch(f.onerror && f.onerror())}; + _GM_xmlhttpRequest = function(f) { + requestWithFetch(f); + }; } if (typeof GM_registerMenuCommand !== 'undefined') { _GM_registerMenuCommand = GM_registerMenuCommand; @@ -4208,7 +4398,7 @@ } else { _GM_addStyle = cssStr => { let styleEle = document.createElement("style"); - styleEle.innerHTML = cssStr; + setHTML(styleEle, cssStr); document.head.appendChild(styleEle); return styleEle; }; @@ -4320,8 +4510,10 @@ "https://github.com/hoothin/UserScripts/tree/master/Pagetual", "https://hoothin.github.io/UserScripts/Pagetual/"]; const firstRunPage = "https://pagetual.hoothin.com/firstRun"; + const wedataRulesUrl = "http://wedata.net/databases/AutoPagerize/items_all.json"; + const wedataMirrorRulesUrl = "https://hoothin.github.io/UserScripts/Pagetual/items_all.json"; const guidePage = /^https?:\/\/.*pagetual.*rule\.html/i; - const ruleImportUrlReg = /greasyfork\.org\/.*scripts\/438684(\-[^\/]*)?(\/discussions|\/?$|\/feedback)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)|^https:\/\/pagetual\.hoothin\.com\/.*firstRun\.html/i; + const ruleImportUrlReg = /greasyfork\.org\/.*scripts\/438684(\-[^\/]*)?(\/discussions|\/?$|\/feedback)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)|^https:\/\/pagetual\.hoothin\.com\/.*first(Run|-run)\.html/i; const allOfBody = "body>*"; const mainSel = ["article,.article","[role=main],main,.main,#main","#results"]; const nextTextReg1 = new RegExp("\u005e\u7ffb\u003f\u005b\u4e0b\u540e\u5f8c\u6b21\u005d\u005b\u4e00\u30fc\u2500\u0031\u005d\u003f\u005b\u9875\u9801\u5f20\u5f35\u005d\u007c\u005e\u006e\u0065\u0078\u0074\u005b\u005c\u0073\u005f\u002d\u005d\u003f\u0070\u0061\u0067\u0065\u005c\u0073\u002a\u005b\u203a\u003e\u2192\u00bb\u005d\u003f\u0024\u007c\u6b21\u306e\u30da\u30fc\u30b8\u007c\u005e\u6b21\u3078\u0024\u007c\u0412\u043f\u0435\u0440\u0435\u0434\u007c\u005e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435", "i"); @@ -4562,139 +4754,211 @@ return segs.length ? '/' + segs.join('/') : null; } - function parseTrustedTypes(cspString) { - const policies = new Set(); - let allowDuplicates = false; - let ttDirectiveFound = false; - const ttRegex = /trusted-types\s+([^;]+)/gi; + function createHTML(html, doc) { + const targetDoc = doc || document; + const fragment = targetDoc.createDocumentFragment(); + if (html === null || html === undefined || html === '') return fragment; + parseHTMLToFragment(String(html), fragment, targetDoc); + return fragment; + } + let canDirectSetHTML = true; + let canPolicySetHTML = true; + let escapeHTMLPolicy; + let escapeHTMLCreator; + const MY_POLICY_NAME = 'pagetual_default'; + const SVG_NS = 'http://www.w3.org/2000/svg'; + const VOID_TAGS = { + area: true, + base: true, + br: true, + col: true, + embed: true, + hr: true, + img: true, + input: true, + link: true, + meta: true, + param: true, + source: true, + track: true, + wbr: true + }; + const RAW_TEXT_TAGS = { + script: true, + style: true, + textarea: true, + title: true, + xmp: true, + plaintext: true, + noscript: true + }; + const HTML_ENTITIES = { + amp: '&', + lt: '<', + gt: '>', + quot: '"', + apos: "'", + nbsp: '\u00A0' + }; + function decodeEntities(text) { + return text.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, function(_, code) { + if (code[0] === '#') { + const isHex = code[1] === 'x' || code[1] === 'X'; + const num = parseInt(code.slice(isHex ? 2 : 1), isHex ? 16 : 10); + if (!isNaN(num)) { + try { return String.fromCodePoint(num); } catch(e) {} + } + return '&' + code + ';'; + } + const key = code.toLowerCase(); + return (key in HTML_ENTITIES) ? HTML_ENTITIES[key] : '&' + code + ';'; + }); + } + function parseHTMLToFragment(html, fragment, doc) { + const stack = [fragment]; + const tokenRe = /|]*>|<\/?[a-zA-Z][^>]*>|[^<]+/gi; let match; - - while ((match = ttRegex.exec(cspString)) !== null) { - ttDirectiveFound = true; - - const policyNames = match[1].trim().split(/\s+/); - for (const name of policyNames) { - if (name === "'allow-duplicates'") { - allowDuplicates = true; - } else if (name !== "'none'") { - policies.add(name.replace(/'/g, '')); - } + while ((match = tokenRe.exec(html))) { + const token = match[0]; + if (token[0] !== '<') { + const text = decodeEntities(token); + if (text) stack[stack.length - 1].appendChild(doc.createTextNode(text)); + continue; } - } - return { names: policies, allowDuplicates: allowDuplicates, ttDirectiveFound: ttDirectiveFound }; - } - - async function getCspTrustedTypesInfo() { - const combinedPolicies = new Set(); - let combinedAllowDuplicates = false; - let combinedTtDirectiveFound = false; - - const meta = document.querySelector('meta[http-equiv="Content-Security-Policy"]'); - if (meta) { - const metaResult = parseTrustedTypes(meta.content); - metaResult.names.forEach(name => combinedPolicies.add(name)); - if (metaResult.allowDuplicates) { - combinedAllowDuplicates = true; + if (token.indexOf('|]*>|<\/?[a-zA-Z][^>]*>|[^<]+/gi; + let match; + while ((match = tokenRe.exec(html))) { + const token = match[0]; + if (token[0] !== '<') { + const text = decodeEntities(token); + if (text) stack[stack.length - 1].appendChild(doc.createTextNode(text)); + continue; + } + if (token.indexOf('|]*>|<\/?[a-zA-Z][^>]*>|[^<]+/gi; + let match; + while ((match = tokenRe.exec(html))) { + const token = match[0]; + if (token[0] !== '<') { + const text = decodeEntities(token); + if (text) stack[stack.length - 1].appendChild(doc.createTextNode(text)); + continue; + } + if (token.indexOf('