diff --git "a/packages/CSDN\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/CSDN\344\274\230\345\214\226/SCRIPT_VERSION.json" index a6525058d..0d1410fda 100644 --- "a/packages/CSDN\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/CSDN\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1718792750105, - "version": "2024.6.19" + "time": 1719112425327, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.min.user.js" "b/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.min.user.js" index 01b91efe0..70b48bc3e 100644 --- "a/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.min.user.js" +++ "b/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name CSDN优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转拦截的URL // @license GPL-3.0-only @@ -9,10 +9,10 @@ // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://*.csdn.net/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @grant GM_addStyle // @grant GM_deleteValue // @grant GM_getValue diff --git "a/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.user.js" "b/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.user.js" index d944024e1..385ee272d 100644 --- "a/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.user.js" +++ "b/packages/CSDN\344\274\230\345\214\226/dist/CSDN\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name CSDN优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转拦截的URL // @license GPL-3.0-only @@ -9,10 +9,10 @@ // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://*.csdn.net/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @grant GM_addStyle // @grant GM_cookie // @grant GM_deleteValue diff --git "a/packages/CSDN\344\274\230\345\214\226/package.json" "b/packages/CSDN\344\274\230\345\214\226/package.json" index 522a9771a..dba2fe61f 100644 --- "a/packages/CSDN\344\274\230\345\214\226/package.json" +++ "b/packages/CSDN\344\274\230\345\214\226/package.json" @@ -14,13 +14,13 @@ "clear": "del .\\SCRIPT_VERSION.json && pnpm store prune" }, "dependencies": { - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "qmsg": "^1.1.2" }, "devDependencies": { - "@types/node": "^20.14.5", - "typescript": "^5.4.5", + "@types/node": "^20.14.8", + "typescript": "^5.5.2", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3" } diff --git "a/packages/CSDN\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/CSDN\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index fe5cd5641..2f6a2981e 100644 --- "a/packages/CSDN\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/CSDN\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/GreasyFork\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/GreasyFork\344\274\230\345\214\226/SCRIPT_VERSION.json" index 7eac9c0dc..3517f16be 100644 --- "a/packages/GreasyFork\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/GreasyFork\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1718792796513, - "version": "2024.6.19" + "time": 1719112475415, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.min.user.js" "b/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.min.user.js" index 1ceef7516..9b9f4f335 100644 --- "a/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.min.user.js" +++ "b/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.min.user.js" @@ -2,7 +2,7 @@ // @name GreasyFork优化 // @name:en-US GreasyFork Optimization // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 自动登录账号、快捷寻找自己库被其他脚本引用、更新自己的脚本列表、库、优化图片浏览、美化页面、Markdown复制按钮 // @description:en-US Automatically log in to the account, quickly find your own library referenced by other scripts, update your own script list, library, optimize image browsing, beautify the page, Markdown copy button @@ -11,10 +11,10 @@ // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://greasyfork.org/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.js // @require https://fastly.jsdelivr.net/npm/i18next@23.11.5/i18next.min.js // @resource ViewerCSS https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.css diff --git "a/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.user.js" "b/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.user.js" index 7e93f0025..2f48f48d4 100644 --- "a/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.user.js" +++ "b/packages/GreasyFork\344\274\230\345\214\226/dist/GreasyFork\344\274\230\345\214\226.user.js" @@ -2,7 +2,7 @@ // @name GreasyFork优化 // @name:en-US GreasyFork Optimization // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 自动登录账号、快捷寻找自己库被其他脚本引用、更新自己的脚本列表、库、优化图片浏览、美化页面、Markdown复制按钮 // @description:en-US Automatically log in to the account, quickly find your own library referenced by other scripts, update your own script list, library, optimize image browsing, beautify the page, Markdown copy button @@ -11,10 +11,10 @@ // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://greasyfork.org/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.js // @require https://fastly.jsdelivr.net/npm/i18next@23.11.5/i18next.min.js // @resource ViewerCSS https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.css diff --git "a/packages/GreasyFork\344\274\230\345\214\226/package.json" "b/packages/GreasyFork\344\274\230\345\214\226/package.json" index dda50145a..794bef691 100644 --- "a/packages/GreasyFork\344\274\230\345\214\226/package.json" +++ "b/packages/GreasyFork\344\274\230\345\214\226/package.json" @@ -15,14 +15,14 @@ "clear": "del .\\SCRIPT_VERSION.json && pnpm store prune" }, "dependencies": { - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "i18next": "^23.11.5", "qmsg": "^1.1.2" }, "devDependencies": { - "@types/node": "^20.14.5", - "typescript": "^5.4.5", + "@types/node": "^20.14.8", + "typescript": "^5.5.2", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3" } diff --git "a/packages/GreasyFork\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/GreasyFork\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index fe5cd5641..2f6a2981e 100644 --- "a/packages/GreasyFork\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/GreasyFork\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git a/packages/demo-vite-typescript/SCRIPT_VERSION.json b/packages/demo-vite-typescript/SCRIPT_VERSION.json index 296458952..f779c0122 100644 --- a/packages/demo-vite-typescript/SCRIPT_VERSION.json +++ b/packages/demo-vite-typescript/SCRIPT_VERSION.json @@ -1,4 +1,4 @@ { - "time": 1716963436556, - "version": "2024.5.29" + "time": 1719112527603, + "version": "2024.6.23" } \ No newline at end of file diff --git a/packages/demo-vite-typescript/dist/Demo Script Name.min.user.js b/packages/demo-vite-typescript/dist/Demo Script Name.min.user.js index 44224f0ed..7d5e8287a 100644 --- a/packages/demo-vite-typescript/dist/Demo Script Name.min.user.js +++ b/packages/demo-vite-typescript/dist/Demo Script Name.min.user.js @@ -1,20 +1,19 @@ // ==UserScript== // @name Demo Script Name // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.5.29 +// @version 2024.6.23 // @author WhiteSevs -// @description demo desc +// @description // @license GPL-3.0-only // @icon // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues -// @match *://*/* +// @match // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1384984/pops.js -// @require https://cdn.jsdelivr.net/npm/qmsg@1.1.0/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/utils@1.2.1/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/domutils@1.1.0/dist/index.umd.js -// @resource ElementPlusResourceCSS https://cdn.jsdelivr.net/npm/element-plus@2.7.2/dist/index.min.css -// @connect * +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js +// @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js +// @connect // @grant GM_addStyle // @grant GM_deleteValue // @grant GM_getResourceText @@ -28,9 +27,9 @@ // @run-at document-start // ==/UserScript== -(function (f, E, G) { +(function (m, I, w) { 'use strict'; - var u=typeof GM_getValue<"u"?GM_getValue:void 0,c=typeof GM_info<"u"?GM_info:void 0,$=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,m=typeof GM_setValue<"u"?GM_setValue:void 0,y=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,b=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,a=typeof unsafeWindow<"u"?unsafeWindow:void 0,V=window;const P="Demo Script Name",l=G.noConflict();E.noConflict();const T=V.pops||a.pops,s=new l.Log(c,a.console||V.console);var D;const _=((D=c==null?void 0:c.script)==null?void 0:D.name)||P,v=!1;s.config({debug:v,logMaxCount:2e4,autoClearConsole:!0,tag:!0});f.config({position:"bottom",html:!0,maxNums:5,autoClose:!0,showClose:!1,showReverse:!0});const I=new l.GM_Menu({GM_getValue:u,GM_setValue:m,GM_registerMenuCommand:$,GM_unregisterMenuCommand:y}),L=new l.Httpx(b);L.config({logDetails:v,onabort(){f.warning("请求取消");},ontimeout(){f.error("请求超时");},onerror(e){f.error("请求异常"),s.error(["httpx-onerror 请求异常",e]);}});a.Object.defineProperty,a.Function.prototype.apply,a.Function.prototype.call,a.Element.prototype.appendChild,a.setTimeout;const r="GM_Panel",C="data-key",x="data-default-value",M={$data:{data:new l.Dictionary,oneSuccessExecMenu:new l.Dictionary,onceExec:new l.Dictionary,scriptName:_,key:r,attributeKeyName:C,attributeDefaultValueName:x},$listener:{listenData:new l.Dictionary},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){a.top===a.self&&I.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}}]);},initPanelDefaultValue(){let e=this;function t(i){if(!i.attributes)return;let o=i.attributes[C],d=i.attributes[x];if(o==null){s.warn(["请先配置键",i]);return}e.$data.data.has(o)&&s.warn("请检查该key(已存在): "+o),e.$data.data.set(o,d);}let n=this.getPanelContentConfig();for(let i=0;i450?"80dvh":"450px"},getPanelContentConfig(){return []}};M.init(); + var p=typeof GM_getValue<"u"?GM_getValue:void 0,M=typeof GM_info<"u"?GM_info:void 0,k=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,b=typeof GM_setValue<"u"?GM_setValue:void 0,S=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,N=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,c=typeof unsafeWindow<"u"?unsafeWindow:void 0,y=window;const R={$data:{get enable(){return s.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return s.getValue("httpx-use-document-cookie")},cookieRule:[]},fixCookieSplit(e){return r.isNotNull(e)&&!e.trim().endsWith(";")&&(e+=";"),e},concatCookie(e,t){return r.isNull(e)?t:(e=e.trim(),t=t.trim(),e=this.fixCookieSplit(e),t.startsWith(";")&&(t=t.substring(1)),e.concat(t))},handle(e){if(e.fetch||!this.$data.enable)return;let t="",n=e.url;n.startsWith("//")&&(n=window.location.protocol+n);let o=new URL(n);this.$data.useDocumentCookie&&o.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(t=this.concatCookie(t,document.cookie.trim())),this.$data.cookieRule.forEach(i=>{if(o.hostname.match(i.hostname)){let a=s.getValue(i.key);if(r.isNull(a))return;t=this.concatCookie(t,a);}}),r.isNotNull(t)&&(e.headers&&e.headers.Cookie?e.headers.Cookie=this.concatCookie(e.headers.Cookie,t):e.headers.Cookie=t,f.info(["Httpx => 设置cookie:",e])),e.headers&&e.headers.Cookie!=null&&r.isNull(e.headers.Cookie)&&delete e.headers.Cookie;}},L="Demo Script Name",r=w.noConflict();I.noConflict();const G=y.pops||c.pops,f=new r.Log(M,c.console||y.console);var $;const D=(($=M==null?void 0:M.script)==null?void 0:$.name)||L,T=!1;f.config({debug:T,logMaxCount:1e3,autoClearConsole:!0,tag:!0});m.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return s.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return s.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return s.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let e=w.getMaxZIndex(10),t=G.config.Utils.getPopsMaxZIndex(10).zIndex;return w.getMaxValue(e,t)}}}));const U=new r.GM_Menu({GM_getValue:p,GM_setValue:b,GM_registerMenuCommand:k,GM_unregisterMenuCommand:S}),V=new r.Httpx(N);V.interceptors.request.use(e=>(R.handle(e),e));V.interceptors.response.use(void 0,e=>(f.error(["拦截器-请求错误",e]),e.type==="onabort"?m.warning("请求取消"):e.type==="onerror"?m.error("请求异常"):e.type==="ontimeout"?m.error("请求超时"):m.error("其它错误"),e));V.config({logDetails:T});c.Object.defineProperty,c.Function.prototype.apply,c.Function.prototype.call,c.Element.prototype.appendChild,c.setTimeout;const h="GM_Panel",C="data-key",v="data-default-value",_=function(e,t,n,o,i){let a={text:e,type:"switch",description:i,attributes:{},getValue(){return !!s.getValue(t,n)},callback(d,u){f.success(`${u?"开启":"关闭"} ${e}`),s.setValue(t,!!u);},afterAddToUListCallBack:void 0};return a.attributes&&(a.attributes[C]=t,a.attributes[v]=!!n),a},E=function(e,t,n,o,i,a){let d=[];typeof o=="function"?d=o():d=o;let u={text:e,type:"select",description:a,attributes:{},getValue(){return s.getValue(t,n)},callback(x,g,P){s.setValue(t,g),typeof i=="function"&&i(x,g,P);},data:d};return u.attributes&&(u.attributes[C]=t,u.attributes[v]=n),u},W={id:"component-common",title:"通用",forms:[{text:"Toast配置",type:"forms",forms:[E("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(e,t,n)=>{f.info("设置当前Qmsg弹出位置"+n);},"Toast显示在页面九宫格的位置"),E("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),_("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[_("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),_("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来设置对应的cookie")]}]},l={data:null,oneSuccessExecMenu:null,onceExec:null,listenData:null},s={$data:{get data(){return l.data==null&&(l.data=new r.Dictionary),l.data},get oneSuccessExecMenu(){return l.oneSuccessExecMenu==null&&(l.oneSuccessExecMenu=new r.Dictionary),l.oneSuccessExecMenu},get onceExec(){return l.onceExec==null&&(l.onceExec=new r.Dictionary),l.onceExec},get scriptName(){return D},key:h,attributeKeyName:C,attributeDefaultValueName:v},$listener:{get listenData(){return l.listenData==null&&(l.listenData=new r.Dictionary),l.listenData}},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){c.top===c.self&&U.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}}]);},initPanelDefaultValue(){let e=this;function t(o){if(!o.attributes)return;let i=o.attributes[C],a=o.attributes[v];if(i==null){f.warn(["请先配置键",o]);return}e.$data.data.has(i)&&f.warn("请检查该key(已存在): "+i),e.$data.data.set(i,a);}let n=this.getPanelContentConfig();for(let o=0;o450?"80dvh":"450px"},getPanelContentConfig(){return [W]}};s.init(); })(Qmsg, DOMUtils, Utils); \ No newline at end of file diff --git a/packages/demo-vite-typescript/dist/Demo Script Name.user.js b/packages/demo-vite-typescript/dist/Demo Script Name.user.js index 750c07716..2d93c1f0f 100644 --- a/packages/demo-vite-typescript/dist/Demo Script Name.user.js +++ b/packages/demo-vite-typescript/dist/Demo Script Name.user.js @@ -1,20 +1,19 @@ // ==UserScript== // @name Demo Script Name // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.5.29 +// @version 2024.6.23 // @author WhiteSevs -// @description demo desc +// @description // @license GPL-3.0-only // @icon // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues -// @match *://*/* +// @match // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1384984/pops.js -// @require https://cdn.jsdelivr.net/npm/qmsg@1.1.0/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/utils@1.2.1/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/domutils@1.1.0/dist/index.umd.js -// @resource ElementPlusResourceCSS https://cdn.jsdelivr.net/npm/element-plus@2.7.2/dist/index.min.css -// @connect * +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js +// @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js +// @connect // @grant GM_addStyle // @grant GM_deleteValue // @grant GM_getResourceText @@ -40,6 +39,90 @@ var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)(); var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)(); var _monkeyWindow = /* @__PURE__ */ (() => window)(); + const HttpxCookieManager = { + $data: { + /** 是否启用 */ + get enable() { + return PopsPanel.getValue("httpx-use-cookie-enable"); + }, + /** 是否使用document.cookie */ + get useDocumentCookie() { + return PopsPanel.getValue("httpx-use-document-cookie"); + }, + cookieRule: [] + }, + /** + * 补充cookie末尾分号 + */ + fixCookieSplit(str) { + if (utils.isNotNull(str) && !str.trim().endsWith(";")) { + str += ";"; + } + return str; + }, + /** + * 合并两个cookie + */ + concatCookie(targetCookie, newCookie) { + if (utils.isNull(targetCookie)) { + return newCookie; + } + targetCookie = targetCookie.trim(); + newCookie = newCookie.trim(); + targetCookie = this.fixCookieSplit(targetCookie); + if (newCookie.startsWith(";")) { + newCookie = newCookie.substring(1); + } + return targetCookie.concat(newCookie); + }, + /** + * 处理cookie + * @param details + * @returns + */ + handle(details) { + if (details.fetch) { + return; + } + if (!this.$data.enable) { + return; + } + let ownCookie = ""; + let url = details.url; + if (url.startsWith("//")) { + url = window.location.protocol + url; + } + let urlObj = new URL(url); + if (this.$data.useDocumentCookie && urlObj.hostname.endsWith( + window.location.hostname.split(".").slice(-2).join(".") + )) { + ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); + } + this.$data.cookieRule.forEach((rule) => { + if (urlObj.hostname.match(rule.hostname)) { + let cookie = PopsPanel.getValue(rule.key); + if (utils.isNull(cookie)) { + return; + } + ownCookie = this.concatCookie(ownCookie, cookie); + } + }); + if (utils.isNotNull(ownCookie)) { + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); + } else { + details.headers["Cookie"] = ownCookie; + } + log.info(["Httpx => 设置cookie:", details]); + } + if (details.headers && details.headers.Cookie != null && utils.isNull(details.headers.Cookie)) { + delete details.headers.Cookie; + } + } + }; const _SCRIPT_NAME_ = "Demo Script Name"; const utils = Utils.noConflict(); DOMUtils.noConflict(); @@ -52,18 +135,43 @@ const DEBUG = false; log.config({ debug: DEBUG, - logMaxCount: 2e4, + logMaxCount: 1e3, autoClearConsole: true, tag: true }); - Qmsg.config({ - position: "bottom", - html: true, - maxNums: 5, - autoClose: true, - showClose: false, - showReverse: true - }); + Qmsg.config( + Object.defineProperties( + { + html: true, + autoClose: true, + showClose: false + }, + { + position: { + get() { + return PopsPanel.getValue("qmsg-config-position", "bottom"); + } + }, + maxNums: { + get() { + return PopsPanel.getValue("qmsg-config-maxnums", 5); + } + }, + showReverse: { + get() { + return PopsPanel.getValue("qmsg-config-showreverse", true); + } + }, + zIndex: { + get() { + let maxZIndex = Utils.getMaxZIndex(10); + let popsMaxZIndex = pops.config.Utils.getPopsMaxZIndex(10).zIndex; + return Utils.getMaxValue(maxZIndex, popsMaxZIndex); + } + } + } + ) + ); const GM_Menu = new utils.GM_Menu({ GM_getValue: _GM_getValue, GM_setValue: _GM_setValue, @@ -71,18 +179,25 @@ GM_unregisterMenuCommand: _GM_unregisterMenuCommand }); const httpx = new utils.Httpx(_GM_xmlhttpRequest); - httpx.config({ - logDetails: DEBUG, - onabort() { + httpx.interceptors.request.use((data) => { + HttpxCookieManager.handle(data); + return data; + }); + httpx.interceptors.response.use(void 0, (data) => { + log.error(["拦截器-请求错误", data]); + if (data.type === "onabort") { Qmsg.warning("请求取消"); - }, - ontimeout() { - Qmsg.error("请求超时"); - }, - onerror(response) { + } else if (data.type === "onerror") { Qmsg.error("请求异常"); - log.error(["httpx-onerror 请求异常", response]); + } else if (data.type === "ontimeout") { + Qmsg.error("请求超时"); + } else { + Qmsg.error("其它错误"); } + return data; + }); + httpx.config({ + logDetails: DEBUG }); ({ Object: { @@ -100,23 +215,219 @@ const KEY = "GM_Panel"; const ATTRIBUTE_KEY = "data-key"; const ATTRIBUTE_DEFAULT_VALUE = "data-default-value"; + const UISwitch = function(text, key, defaultValue, clickCallBack, description) { + let result = { + text, + type: "switch", + description, + attributes: {}, + getValue() { + return Boolean(PopsPanel.getValue(key, defaultValue)); + }, + callback(event, value) { + log.success(`${value ? "开启" : "关闭"} ${text}`); + PopsPanel.setValue(key, Boolean(value)); + }, + afterAddToUListCallBack: void 0 + }; + if (result.attributes) { + result.attributes[ATTRIBUTE_KEY] = key; + result.attributes[ATTRIBUTE_DEFAULT_VALUE] = Boolean(defaultValue); + } + return result; + }; + const UISelect = function(text, key, defaultValue, data, callback, description) { + let selectData = []; + if (typeof data === "function") { + selectData = data(); + } else { + selectData = data; + } + let result = { + text, + type: "select", + description, + attributes: {}, + getValue() { + return PopsPanel.getValue(key, defaultValue); + }, + callback(event, isSelectedValue, isSelectedText) { + PopsPanel.setValue(key, isSelectedValue); + if (typeof callback === "function") { + callback(event, isSelectedValue, isSelectedText); + } + }, + data: selectData + }; + if (result.attributes) { + result.attributes[ATTRIBUTE_KEY] = key; + result.attributes[ATTRIBUTE_DEFAULT_VALUE] = defaultValue; + } + return result; + }; + const Component_Common = { + id: "component-common", + title: "通用", + forms: [ + { + text: "Toast配置", + type: "forms", + forms: [ + UISelect( + "Toast位置", + "qmsg-config-position", + "bottom", + [ + { + value: "topleft", + text: "左上角" + }, + { + value: "top", + text: "顶部" + }, + { + value: "topright", + text: "右上角" + }, + { + value: "left", + text: "左边" + }, + { + value: "center", + text: "中间" + }, + { + value: "right", + text: "右边" + }, + { + value: "bottomleft", + text: "左下角" + }, + { + value: "bottom", + text: "底部" + }, + { + value: "bottomright", + text: "右下角" + } + ], + (event, isSelectValue, isSelectText) => { + log.info("设置当前Qmsg弹出位置" + isSelectText); + }, + "Toast显示在页面九宫格的位置" + ), + UISelect( + "最多显示的数量", + "qmsg-config-maxnums", + 3, + [ + { + value: 1, + text: "1" + }, + { + value: 2, + text: "2" + }, + { + value: 3, + text: "3" + }, + { + value: 4, + text: "4" + }, + { + value: 5, + text: "5" + } + ], + void 0, + "限制Toast显示的数量" + ), + UISwitch( + "逆序弹出", + "qmsg-config-showreverse", + false, + void 0, + "修改Toast弹出的顺序" + ) + ] + }, + { + text: "Cookie配置", + type: "forms", + forms: [ + UISwitch( + "启用", + "httpx-use-cookie-enable", + false, + void 0, + "启用后,将根据下面的配置进行添加cookie" + ), + UISwitch( + "使用document.cookie", + "httpx-use-document-cookie", + false, + void 0, + "自动根据请求的域名来设置对应的cookie" + ) + // UITextArea( + // "tieba.baidu.com", + // "httpx-cookie-tieba.baidu.com", + // "", + // void 0, + // void 0, + // "Cookie格式:xxx=xxxx;xxx=xxxx" + // ), + ] + } + ] + }; + const __PopsPanel__ = { + data: null, + oneSuccessExecMenu: null, + onceExec: null, + listenData: null + }; const PopsPanel = { /** 数据 */ $data: { /** * 菜单项的默认值 */ - data: new utils.Dictionary(), + get data() { + if (__PopsPanel__.data == null) { + __PopsPanel__.data = new utils.Dictionary(); + } + return __PopsPanel__.data; + }, /** * 成功只执行了一次的项 */ - oneSuccessExecMenu: new utils.Dictionary(), + get oneSuccessExecMenu() { + if (__PopsPanel__.oneSuccessExecMenu == null) { + __PopsPanel__.oneSuccessExecMenu = new utils.Dictionary(); + } + return __PopsPanel__.oneSuccessExecMenu; + }, /** * 成功只执行了一次的项 */ - onceExec: new utils.Dictionary(), + get onceExec() { + if (__PopsPanel__.onceExec == null) { + __PopsPanel__.onceExec = new utils.Dictionary(); + } + return __PopsPanel__.onceExec; + }, /** 脚本名,一般用在设置的标题上 */ - scriptName: SCRIPT_NAME, + get scriptName() { + return SCRIPT_NAME; + }, /** 菜单项的总值在本地数据配置的键名 */ key: KEY, /** 菜单项在attributes上配置的菜单键 */ @@ -129,7 +440,12 @@ /** * 值改变的监听器 */ - listenData: new utils.Dictionary() + get listenData() { + if (__PopsPanel__.listenData == null) { + __PopsPanel__.listenData = new utils.Dictionary(); + } + return __PopsPanel__.listenData; + } }, init() { this.initPanelDefaultValue(); @@ -382,7 +698,7 @@ * 获取配置内容 */ getPanelContentConfig() { - let configList = []; + let configList = [Component_Common]; return configList; } }; diff --git a/packages/demo-vite-typescript/package.json b/packages/demo-vite-typescript/package.json index ab17d3d0b..58a23af79 100644 --- a/packages/demo-vite-typescript/package.json +++ b/packages/demo-vite-typescript/package.json @@ -14,13 +14,13 @@ "clear": "del .\\SCRIPT_VERSION.json && pnpm store prune" }, "dependencies": { - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "qmsg": "^1.1.2" }, "devDependencies": { - "@types/node": "^20.14.5", - "typescript": "^5.4.5", + "@types/node": "^20.14.8", + "typescript": "^5.5.2", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3" } diff --git a/packages/demo-vite-typescript/src/utils/HttpxCookieManager.ts b/packages/demo-vite-typescript/src/utils/HttpxCookieManager.ts index fe5cd5641..2f6a2981e 100644 --- a/packages/demo-vite-typescript/src/utils/HttpxCookieManager.ts +++ b/packages/demo-vite-typescript/src/utils/HttpxCookieManager.ts @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git a/packages/demo-vue-vite-typescript/SCRIPT_VERSION.json b/packages/demo-vue-vite-typescript/SCRIPT_VERSION.json index be842202d..807c0a26e 100644 --- a/packages/demo-vue-vite-typescript/SCRIPT_VERSION.json +++ b/packages/demo-vue-vite-typescript/SCRIPT_VERSION.json @@ -1,4 +1,4 @@ { - "time": 1716887851533, - "version": "2024.5.28" + "time": 1719112605349, + "version": "2024.6.23" } \ No newline at end of file diff --git a/packages/demo-vue-vite-typescript/dist/Demo Script Name.min.user.js b/packages/demo-vue-vite-typescript/dist/Demo Script Name.min.user.js index 4b60b4fa7..28ca2f422 100644 --- a/packages/demo-vue-vite-typescript/dist/Demo Script Name.min.user.js +++ b/packages/demo-vue-vite-typescript/dist/Demo Script Name.min.user.js @@ -1,24 +1,26 @@ // ==UserScript== // @name Demo Script Name // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.5.28 +// @version 2024.6.23 // @author WhiteSevs -// @description demo desc +// @description // @license GPL-3.0-only // @icon // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues -// @match *://*/* +// @match // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1384463/pops.js -// @require https://cdn.jsdelivr.net/npm/vue@3.4.27/dist/vue.global.prod.js -// @require https://cdn.jsdelivr.net/npm/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js -// @require https://cdn.jsdelivr.net/npm/qmsg@1.1.0/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/utils@1.1.9/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/domutils@1.0.8/dist/index.umd.js -// @resource ElementPlusResourceCSS https://cdn.jsdelivr.net/npm/element-plus@2.7.2/dist/index.min.css -// @connect * +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js +// @require https://fastly.jsdelivr.net/npm/vue@3.4.30/dist/vue.global.prod.js +// @require https://fastly.jsdelivr.net/npm/vue-demi@0.14.8/lib/index.iife.min.js +// @require https://fastly.jsdelivr.net/npm/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js +// @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js +// @resource ElementPlusResourceCSS https://fastly.jsdelivr.net/npm/element-plus@2.7.5/dist/index.min.css +// @connect // @grant GM_addStyle // @grant GM_deleteValue +// @grant GM_getResourceText // @grant GM_getValue // @grant GM_info // @grant GM_registerMenuCommand @@ -29,9 +31,9 @@ // @run-at document-start // ==/UserScript== -(function (vue, u, E, G) { +(function (vue, m, w, I) { 'use strict'; - var d=typeof GM_getValue<"u"?GM_getValue:void 0,f=typeof GM_info<"u"?GM_info:void 0,y=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,m=typeof GM_setValue<"u"?GM_setValue:void 0,b=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,$=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,o=typeof unsafeWindow<"u"?unsafeWindow:void 0,V=window;const P="Demo Script Name",l=E.noConflict();G.noConflict();const T=V.pops||o.pops,c=new l.Log(f,o.console||V.console);var D;const C=((D=f==null?void 0:f.script)==null?void 0:D.name)||P,v=!1;c.config({debug:v,logMaxCount:2e4,autoClearConsole:!0,tag:!0});u.config({position:"bottom",html:!0,maxNums:5,autoClose:!0,showClose:!1,showReverse:!0});const I=new l.GM_Menu({GM_getValue:d,GM_setValue:m,GM_registerMenuCommand:y,GM_unregisterMenuCommand:b}),L=new l.Httpx($);L.config({logDetails:v,onabort(){u.warning("请求取消");},ontimeout(){u.error("请求超时");},onerror(e){u.error("请求异常"),c.error(["httpx-onerror 请求异常",e]);}});o.Object.defineProperty,o.Function.prototype.apply,o.Function.prototype.call,o.Element.prototype.appendChild,o.setTimeout;const r="GM_Panel",w="data-key",x="data-default-value",M={$data:{data:new l.Dictionary,oneSuccessExecMenu:new l.Dictionary,onceExec:new l.Dictionary,scriptName:C,key:r,attributeKeyName:w,attributeDefaultValueName:x},$listener:{listenData:new l.Dictionary},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){o.top===o.self&&I.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}}]);},initPanelDefaultValue(){let e=this;function t(i){if(!i.attributes)return;let a=i.attributes[w],s=i.attributes[x];if(a==null){c.warn(["请先配置键",i]);return}e.$data.data.has(a)&&c.warn("请检查该key(已存在): "+a),e.$data.data.set(a,s);}let n=this.getPanelContentConfig();for(let i=0;i450?"80dvh":"450px"},getPanelContentConfig(){return []}};M.init(); + var p=typeof GM_getValue<"u"?GM_getValue:void 0,M=typeof GM_info<"u"?GM_info:void 0,k=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,b=typeof GM_setValue<"u"?GM_setValue:void 0,S=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,N=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,c=typeof unsafeWindow<"u"?unsafeWindow:void 0,y=window;const R={$data:{get enable(){return s.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return s.getValue("httpx-use-document-cookie")},cookieRule:[]},fixCookieSplit(e){return r.isNotNull(e)&&!e.trim().endsWith(";")&&(e+=";"),e},concatCookie(e,t){return r.isNull(e)?t:(e=e.trim(),t=t.trim(),e=this.fixCookieSplit(e),t.startsWith(";")&&(t=t.substring(1)),e.concat(t))},handle(e){if(e.fetch||!this.$data.enable)return;let t="",n=e.url;n.startsWith("//")&&(n=window.location.protocol+n);let o=new URL(n);this.$data.useDocumentCookie&&o.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(t=this.concatCookie(t,document.cookie.trim())),this.$data.cookieRule.forEach(i=>{if(o.hostname.match(i.hostname)){let a=s.getValue(i.key);if(r.isNull(a))return;t=this.concatCookie(t,a);}}),r.isNotNull(t)&&(e.headers&&e.headers.Cookie?e.headers.Cookie=this.concatCookie(e.headers.Cookie,t):e.headers.Cookie=t,f.info(["Httpx => 设置cookie:",e])),e.headers&&e.headers.Cookie!=null&&r.isNull(e.headers.Cookie)&&delete e.headers.Cookie;}},L="Demo Script Name",r=w.noConflict();I.noConflict();const G=y.pops||c.pops,f=new r.Log(M,c.console||y.console);var $;const D=(($=M==null?void 0:M.script)==null?void 0:$.name)||L,T=!1;f.config({debug:T,logMaxCount:1e3,autoClearConsole:!0,tag:!0});m.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return s.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return s.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return s.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let e=w.getMaxZIndex(10),t=G.config.Utils.getPopsMaxZIndex(10).zIndex;return w.getMaxValue(e,t)}}}));const U=new r.GM_Menu({GM_getValue:p,GM_setValue:b,GM_registerMenuCommand:k,GM_unregisterMenuCommand:S}),V=new r.Httpx(N);V.interceptors.request.use(e=>(R.handle(e),e));V.interceptors.response.use(void 0,e=>(f.error(["拦截器-请求错误",e]),e.type==="onabort"?m.warning("请求取消"):e.type==="onerror"?m.error("请求异常"):e.type==="ontimeout"?m.error("请求超时"):m.error("其它错误"),e));V.config({logDetails:T});c.Object.defineProperty,c.Function.prototype.apply,c.Function.prototype.call,c.Element.prototype.appendChild,c.setTimeout;const h="GM_Panel",C="data-key",v="data-default-value",_=function(e,t,n,o,i){let a={text:e,type:"switch",description:i,attributes:{},getValue(){return !!s.getValue(t,n)},callback(d,u){f.success(`${u?"开启":"关闭"} ${e}`),s.setValue(t,!!u);},afterAddToUListCallBack:void 0};return a.attributes&&(a.attributes[C]=t,a.attributes[v]=!!n),a},E=function(e,t,n,o,i,a){let d=[];typeof o=="function"?d=o():d=o;let u={text:e,type:"select",description:a,attributes:{},getValue(){return s.getValue(t,n)},callback(x,g,P){s.setValue(t,g),typeof i=="function"&&i(x,g,P);},data:d};return u.attributes&&(u.attributes[C]=t,u.attributes[v]=n),u},W={id:"component-common",title:"通用",forms:[{text:"Toast配置",type:"forms",forms:[E("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(e,t,n)=>{f.info("设置当前Qmsg弹出位置"+n);},"Toast显示在页面九宫格的位置"),E("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),_("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[_("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),_("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来设置对应的cookie")]}]},l={data:null,oneSuccessExecMenu:null,onceExec:null,listenData:null},s={$data:{get data(){return l.data==null&&(l.data=new r.Dictionary),l.data},get oneSuccessExecMenu(){return l.oneSuccessExecMenu==null&&(l.oneSuccessExecMenu=new r.Dictionary),l.oneSuccessExecMenu},get onceExec(){return l.onceExec==null&&(l.onceExec=new r.Dictionary),l.onceExec},get scriptName(){return D},key:h,attributeKeyName:C,attributeDefaultValueName:v},$listener:{get listenData(){return l.listenData==null&&(l.listenData=new r.Dictionary),l.listenData}},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){c.top===c.self&&U.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}}]);},initPanelDefaultValue(){let e=this;function t(o){if(!o.attributes)return;let i=o.attributes[C],a=o.attributes[v];if(i==null){f.warn(["请先配置键",o]);return}e.$data.data.has(i)&&f.warn("请检查该key(已存在): "+i),e.$data.data.set(i,a);}let n=this.getPanelContentConfig();for(let o=0;o450?"80dvh":"450px"},getPanelContentConfig(){return [W]}};s.init(); })(Vue, Qmsg, Utils, DOMUtils); \ No newline at end of file diff --git a/packages/demo-vue-vite-typescript/dist/Demo Script Name.user.js b/packages/demo-vue-vite-typescript/dist/Demo Script Name.user.js index 78bee72eb..ac71963f1 100644 --- a/packages/demo-vue-vite-typescript/dist/Demo Script Name.user.js +++ b/packages/demo-vue-vite-typescript/dist/Demo Script Name.user.js @@ -1,24 +1,26 @@ // ==UserScript== // @name Demo Script Name // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.5.28 +// @version 2024.6.23 // @author WhiteSevs -// @description demo desc +// @description // @license GPL-3.0-only // @icon // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues -// @match *://*/* +// @match // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1384463/pops.js -// @require https://cdn.jsdelivr.net/npm/vue@3.4.27/dist/vue.global.prod.js -// @require https://cdn.jsdelivr.net/npm/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js -// @require https://cdn.jsdelivr.net/npm/qmsg@1.1.0/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/utils@1.1.9/dist/index.umd.js -// @require https://cdn.jsdelivr.net/npm/@whitesev/domutils@1.0.8/dist/index.umd.js -// @resource ElementPlusResourceCSS https://cdn.jsdelivr.net/npm/element-plus@2.7.2/dist/index.min.css -// @connect * +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js +// @require https://fastly.jsdelivr.net/npm/vue@3.4.30/dist/vue.global.prod.js +// @require https://fastly.jsdelivr.net/npm/vue-demi@0.14.8/lib/index.iife.min.js +// @require https://fastly.jsdelivr.net/npm/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js +// @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js +// @resource ElementPlusResourceCSS https://fastly.jsdelivr.net/npm/element-plus@2.7.5/dist/index.min.css +// @connect // @grant GM_addStyle // @grant GM_deleteValue +// @grant GM_getResourceText // @grant GM_getValue // @grant GM_info // @grant GM_registerMenuCommand @@ -41,6 +43,90 @@ var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)(); var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)(); var _monkeyWindow = /* @__PURE__ */ (() => window)(); + const HttpxCookieManager = { + $data: { + /** 是否启用 */ + get enable() { + return PopsPanel.getValue("httpx-use-cookie-enable"); + }, + /** 是否使用document.cookie */ + get useDocumentCookie() { + return PopsPanel.getValue("httpx-use-document-cookie"); + }, + cookieRule: [] + }, + /** + * 补充cookie末尾分号 + */ + fixCookieSplit(str) { + if (utils.isNotNull(str) && !str.trim().endsWith(";")) { + str += ";"; + } + return str; + }, + /** + * 合并两个cookie + */ + concatCookie(targetCookie, newCookie) { + if (utils.isNull(targetCookie)) { + return newCookie; + } + targetCookie = targetCookie.trim(); + newCookie = newCookie.trim(); + targetCookie = this.fixCookieSplit(targetCookie); + if (newCookie.startsWith(";")) { + newCookie = newCookie.substring(1); + } + return targetCookie.concat(newCookie); + }, + /** + * 处理cookie + * @param details + * @returns + */ + handle(details) { + if (details.fetch) { + return; + } + if (!this.$data.enable) { + return; + } + let ownCookie = ""; + let url = details.url; + if (url.startsWith("//")) { + url = window.location.protocol + url; + } + let urlObj = new URL(url); + if (this.$data.useDocumentCookie && urlObj.hostname.endsWith( + window.location.hostname.split(".").slice(-2).join(".") + )) { + ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); + } + this.$data.cookieRule.forEach((rule) => { + if (urlObj.hostname.match(rule.hostname)) { + let cookie = PopsPanel.getValue(rule.key); + if (utils.isNull(cookie)) { + return; + } + ownCookie = this.concatCookie(ownCookie, cookie); + } + }); + if (utils.isNotNull(ownCookie)) { + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); + } else { + details.headers["Cookie"] = ownCookie; + } + log.info(["Httpx => 设置cookie:", details]); + } + if (details.headers && details.headers.Cookie != null && utils.isNull(details.headers.Cookie)) { + delete details.headers.Cookie; + } + } + }; const _SCRIPT_NAME_ = "Demo Script Name"; const utils = Utils.noConflict(); DOMUtils.noConflict(); @@ -53,18 +139,43 @@ const DEBUG = false; log.config({ debug: DEBUG, - logMaxCount: 2e4, + logMaxCount: 1e3, autoClearConsole: true, tag: true }); - Qmsg.config({ - position: "bottom", - html: true, - maxNums: 5, - autoClose: true, - showClose: false, - showReverse: true - }); + Qmsg.config( + Object.defineProperties( + { + html: true, + autoClose: true, + showClose: false + }, + { + position: { + get() { + return PopsPanel.getValue("qmsg-config-position", "bottom"); + } + }, + maxNums: { + get() { + return PopsPanel.getValue("qmsg-config-maxnums", 5); + } + }, + showReverse: { + get() { + return PopsPanel.getValue("qmsg-config-showreverse", true); + } + }, + zIndex: { + get() { + let maxZIndex = Utils.getMaxZIndex(10); + let popsMaxZIndex = pops.config.Utils.getPopsMaxZIndex(10).zIndex; + return Utils.getMaxValue(maxZIndex, popsMaxZIndex); + } + } + } + ) + ); const GM_Menu = new utils.GM_Menu({ GM_getValue: _GM_getValue, GM_setValue: _GM_setValue, @@ -72,18 +183,25 @@ GM_unregisterMenuCommand: _GM_unregisterMenuCommand }); const httpx = new utils.Httpx(_GM_xmlhttpRequest); - httpx.config({ - logDetails: DEBUG, - onabort() { + httpx.interceptors.request.use((data) => { + HttpxCookieManager.handle(data); + return data; + }); + httpx.interceptors.response.use(void 0, (data) => { + log.error(["拦截器-请求错误", data]); + if (data.type === "onabort") { Qmsg.warning("请求取消"); - }, - ontimeout() { - Qmsg.error("请求超时"); - }, - onerror(response) { + } else if (data.type === "onerror") { Qmsg.error("请求异常"); - log.error(["httpx-onerror 请求异常", response]); + } else if (data.type === "ontimeout") { + Qmsg.error("请求超时"); + } else { + Qmsg.error("其它错误"); } + return data; + }); + httpx.config({ + logDetails: DEBUG }); ({ Object: { @@ -101,23 +219,219 @@ const KEY = "GM_Panel"; const ATTRIBUTE_KEY = "data-key"; const ATTRIBUTE_DEFAULT_VALUE = "data-default-value"; + const UISwitch = function(text, key, defaultValue, clickCallBack, description) { + let result = { + text, + type: "switch", + description, + attributes: {}, + getValue() { + return Boolean(PopsPanel.getValue(key, defaultValue)); + }, + callback(event, value) { + log.success(`${value ? "开启" : "关闭"} ${text}`); + PopsPanel.setValue(key, Boolean(value)); + }, + afterAddToUListCallBack: void 0 + }; + if (result.attributes) { + result.attributes[ATTRIBUTE_KEY] = key; + result.attributes[ATTRIBUTE_DEFAULT_VALUE] = Boolean(defaultValue); + } + return result; + }; + const UISelect = function(text, key, defaultValue, data, callback, description) { + let selectData = []; + if (typeof data === "function") { + selectData = data(); + } else { + selectData = data; + } + let result = { + text, + type: "select", + description, + attributes: {}, + getValue() { + return PopsPanel.getValue(key, defaultValue); + }, + callback(event, isSelectedValue, isSelectedText) { + PopsPanel.setValue(key, isSelectedValue); + if (typeof callback === "function") { + callback(event, isSelectedValue, isSelectedText); + } + }, + data: selectData + }; + if (result.attributes) { + result.attributes[ATTRIBUTE_KEY] = key; + result.attributes[ATTRIBUTE_DEFAULT_VALUE] = defaultValue; + } + return result; + }; + const Component_Common = { + id: "component-common", + title: "通用", + forms: [ + { + text: "Toast配置", + type: "forms", + forms: [ + UISelect( + "Toast位置", + "qmsg-config-position", + "bottom", + [ + { + value: "topleft", + text: "左上角" + }, + { + value: "top", + text: "顶部" + }, + { + value: "topright", + text: "右上角" + }, + { + value: "left", + text: "左边" + }, + { + value: "center", + text: "中间" + }, + { + value: "right", + text: "右边" + }, + { + value: "bottomleft", + text: "左下角" + }, + { + value: "bottom", + text: "底部" + }, + { + value: "bottomright", + text: "右下角" + } + ], + (event, isSelectValue, isSelectText) => { + log.info("设置当前Qmsg弹出位置" + isSelectText); + }, + "Toast显示在页面九宫格的位置" + ), + UISelect( + "最多显示的数量", + "qmsg-config-maxnums", + 3, + [ + { + value: 1, + text: "1" + }, + { + value: 2, + text: "2" + }, + { + value: 3, + text: "3" + }, + { + value: 4, + text: "4" + }, + { + value: 5, + text: "5" + } + ], + void 0, + "限制Toast显示的数量" + ), + UISwitch( + "逆序弹出", + "qmsg-config-showreverse", + false, + void 0, + "修改Toast弹出的顺序" + ) + ] + }, + { + text: "Cookie配置", + type: "forms", + forms: [ + UISwitch( + "启用", + "httpx-use-cookie-enable", + false, + void 0, + "启用后,将根据下面的配置进行添加cookie" + ), + UISwitch( + "使用document.cookie", + "httpx-use-document-cookie", + false, + void 0, + "自动根据请求的域名来设置对应的cookie" + ) + // UITextArea( + // "tieba.baidu.com", + // "httpx-cookie-tieba.baidu.com", + // "", + // void 0, + // void 0, + // "Cookie格式:xxx=xxxx;xxx=xxxx" + // ), + ] + } + ] + }; + const __PopsPanel__ = { + data: null, + oneSuccessExecMenu: null, + onceExec: null, + listenData: null + }; const PopsPanel = { /** 数据 */ $data: { /** * 菜单项的默认值 */ - data: new utils.Dictionary(), + get data() { + if (__PopsPanel__.data == null) { + __PopsPanel__.data = new utils.Dictionary(); + } + return __PopsPanel__.data; + }, /** * 成功只执行了一次的项 */ - oneSuccessExecMenu: new utils.Dictionary(), + get oneSuccessExecMenu() { + if (__PopsPanel__.oneSuccessExecMenu == null) { + __PopsPanel__.oneSuccessExecMenu = new utils.Dictionary(); + } + return __PopsPanel__.oneSuccessExecMenu; + }, /** * 成功只执行了一次的项 */ - onceExec: new utils.Dictionary(), + get onceExec() { + if (__PopsPanel__.onceExec == null) { + __PopsPanel__.onceExec = new utils.Dictionary(); + } + return __PopsPanel__.onceExec; + }, /** 脚本名,一般用在设置的标题上 */ - scriptName: SCRIPT_NAME, + get scriptName() { + return SCRIPT_NAME; + }, /** 菜单项的总值在本地数据配置的键名 */ key: KEY, /** 菜单项在attributes上配置的菜单键 */ @@ -130,7 +444,12 @@ /** * 值改变的监听器 */ - listenData: new utils.Dictionary() + get listenData() { + if (__PopsPanel__.listenData == null) { + __PopsPanel__.listenData = new utils.Dictionary(); + } + return __PopsPanel__.listenData; + } }, init() { this.initPanelDefaultValue(); @@ -268,6 +587,14 @@ console.warn("没有找到对应的监听器"); } }, + /** + * 判断该键是否存在 + * @param key 键 + */ + hasKey(key) { + let locaData = _GM_getValue(KEY, {}); + return key in locaData; + }, /** * 自动判断菜单是否启用,然后执行回调 * @param key @@ -277,6 +604,10 @@ if (typeof key !== "string") { throw new TypeError("key 必须是字符串"); } + if (!this.$data.data.has(key)) { + log.warn(`${key} 键不存在`); + return; + } let value = PopsPanel.getValue(key); if (value) { callback(value); @@ -291,6 +622,10 @@ if (typeof key !== "string") { throw new TypeError("key 必须是字符串"); } + if (!this.$data.data.has(key)) { + log.warn(`${key} 键不存在`); + return; + } let value = PopsPanel.getValue(key); if (value) { if (this.$data.oneSuccessExecMenu.has(key)) { @@ -302,7 +637,7 @@ }, /** * 根据key执行一次 - * @param key + * @param key */ onceExec(key, callback) { if (typeof key !== "string") { @@ -367,7 +702,7 @@ * 获取配置内容 */ getPanelContentConfig() { - let configList = []; + let configList = [Component_Common]; return configList; } }; diff --git a/packages/demo-vue-vite-typescript/package.json b/packages/demo-vue-vite-typescript/package.json index d5fb28aa2..82ae49f82 100644 --- a/packages/demo-vue-vite-typescript/package.json +++ b/packages/demo-vue-vite-typescript/package.json @@ -15,24 +15,24 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.3.1", - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "pinia": "^2.1.7", "qmsg": "^1.1.2", - "vue": "^3.4.29", - "vue-router": "^4.3.3" + "vue": "^3.4.30", + "vue-router": "^4.4.0" }, "devDependencies": { - "@types/node": "^20.14.5", + "@types/node": "^20.14.8", "@vitejs/plugin-vue": "^5.0.5", - "element-plus": "^2.7.5", - "typescript": "^5.4.5", + "element-plus": "^2.7.6", + "typescript": "^5.5.2", "unplugin-auto-import": "^0.17.6", "unplugin-element-plus": "^0.8.0", "unplugin-icons": "^0.19.0", "unplugin-vue-components": "^0.27.0", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3", - "vue-tsc": "^2.0.21" + "vue-tsc": "^2.0.22" } } diff --git a/packages/demo-vue-vite-typescript/src/utils/HttpxCookieManager.ts b/packages/demo-vue-vite-typescript/src/utils/HttpxCookieManager.ts index fe5cd5641..2f6a2981e 100644 --- a/packages/demo-vue-vite-typescript/src/utils/HttpxCookieManager.ts +++ b/packages/demo-vue-vite-typescript/src/utils/HttpxCookieManager.ts @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/SCRIPT_VERSION.json" index 76e40cd75..3998e2594 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1718789436577, - "version": "2024.6.19" + "time": 1719112118239, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.min.user.js" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.min.user.js" index d42a5ebe3..3aeb49699 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.min.user.js" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 【移动端】bilibili优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description bilibili(哔哩哔哩)优化,免登录等 // @license GPL-3.0-only @@ -11,11 +11,11 @@ // @match *://live.bilibili.com/* // @match *://www.bilibili.com/read/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://update.greasyfork.org/scripts/497907/1394170/QRCodeJS.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/md5@2.3.0/dist/md5.min.js // @connect * // @connect m.bilibili.com @@ -40,7 +40,7 @@ (function (g, W, st, lt) { 'use strict'; - var V=typeof GM_getValue<"u"?GM_getValue:void 0,I=typeof GM_info<"u"?GM_info:void 0,ct=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,L=typeof GM_setValue<"u"?GM_setValue:void 0,ut=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,pt=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,y=typeof unsafeWindow<"u"?unsafeWindow:void 0,J=window;const dt={$data:{get enable(){return c.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return c.getValue("httpx-use-document-cookie")},cookieList:[{key:"httpx-cookie-bilibili.com",hostname:/bilibili.com/g}]},fixCookieSplit(t){return s.isNotNull(t)&&!t.trim().endsWith(";")&&(t+=";"),t},concatCookie(t,e){return s.isNull(t)?e:(t=t.trim(),e=e.trim(),t=this.fixCookieSplit(t),e.startsWith(";")&&(e=e.substring(1)),t.concat(e))},handle(t){if(t.fetch||!this.$data.enable)return;let e="",i=t.url;i.startsWith("//")&&(i=window.location.protocol+i);let r=new URL(i);this.$data.useDocumentCookie&&r.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(e=this.concatCookie(e,document.cookie.trim())),this.$data.cookieList.forEach(n=>{if(n.hostname.test(r.hostname)){let a=c.getValue(n.key);if(s.isNull(a))return;e=this.concatCookie(e,a);}}),s.isNotNull(e)&&(t.headers&&t.headers.Cookie?t.headers.Cookie=this.concatCookie(t.headers.Cookie,e):t.headers.Cookie=e,o.info(["Httpx => 设置cookie:",t])),t.headers&&t.headers.Cookie!=null&&s.isNull(t.headers.Cookie)&&delete t.headers.Cookie;}},mt="【移动端】bilibili优化",s=W.noConflict(),m=st.noConflict(),D=J.pops||y.pops,F=J.QRCode||y.QRCode,o=new s.Log(I,y.console||J.console);var it;const Q=((it=I==null?void 0:I.script)==null?void 0:it.name)||mt,ft=new s.GM_Cookie,rt=!1;o.config({debug:rt,logMaxCount:1e3,autoClearConsole:!0,tag:!0});g.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return c.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return c.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return c.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let t=W.getMaxZIndex(10),e=D.config.Utils.getPopsMaxZIndex(10).zIndex;return W.getMaxValue(t,e)}}}));const ht=new s.GM_Menu({GM_getValue:V,GM_setValue:L,GM_registerMenuCommand:ct,GM_unregisterMenuCommand:ut}),T=new s.Httpx(pt);T.interceptors.request.use(t=>(dt.handle(t),t));T.interceptors.response.use(void 0,t=>(o.error(["拦截器-请求错误",t]),t.type==="onabort"?g.warning("请求取消"):t.type==="onerror"?g.error("请求异常"):t.type==="ontimeout"?g.error("请求超时"):g.error("其它错误"),t));T.config({logDetails:rt});const z={Object:{defineProperty:y.Object.defineProperty},Function:{apply:y.Function.prototype.apply,call:y.Function.prototype.call},Element:{appendChild:y.Element.prototype.appendChild},setTimeout:y.setTimeout},C=s.addStyle,S="GM_Panel",P="data-key",M="data-default-value",d=function(t,e,i,r,n){let a={text:t,type:"switch",description:n,attributes:{},getValue(){return !!c.getValue(e,i)},callback(l,u){o.success(`${u?"开启":"关闭"} ${t}`),c.setValue(e,!!u);},afterAddToUListCallBack:void 0};return a.attributes&&(a.attributes[P]=e,a.attributes[M]=!!i),a},gt=function(t,e,i,r,n,a="",l){let u={text:t,type:"textarea",attributes:{},description:r,placeholder:a,disabled:l,getValue(){return c.getValue(e,i)},callback(f,v){c.setValue(e,v);}};return u.attributes&&(u.attributes[P]=e,u.attributes[M]=i),u},K=function(t,e,i,r,n,a){let l=[];typeof r=="function"?l=r():l=r;let u={text:t,type:"select",description:a,attributes:{},getValue(){return c.getValue(e,i)},callback(f,v,h){c.setValue(e,v),typeof n=="function"&&n(f,v,h);},data:l};return u.attributes&&(u.attributes[P]=e,u.attributes[M]=i),u},vt={id:"panel-common",title:"通用",forms:[{text:"功能",type:"forms",forms:[d("监听路由-重载所有功能","bili-listenRouterChange",!0,void 0,"用于处理页面跳转(本页)时功能不生效问题"),d("修复点击UP主正确进入空间","bili-repairEnterUserHome",!0,void 0,"可以修复点击UP主进入个人空间但是跳转404的问题"),d("新标签页打开","bili-go-to-url-blank",!1,void 0,"通过开启【覆盖点击事件】相关的设置,通过新标签页打开链接")]},{text:"变量设置",type:"forms",forms:[d("isLogin","bili-setLogin",!0,void 0,"$store.state.common.noCallApp=true
$store.state.common.userInfo.isLogin=true
$store.state.loginInfo.isLogin=true"),d("isClient","bili-setIsClient",!0,void 0,"$store.state.video.isClient=true
$store.state.opus.isClient=true
$store.state.playlist.isClient=true
$store.state.ver.bili=true
$store.state.ver.biliVer=2333"),d("tinyApp","bili-setTinyApp",!0,void 0,"$store.state.common.tinyApp=true")]},{text:"劫持/拦截",type:"forms",forms:[d("覆盖.launch-app-btn openApp","bili-overrideLaunchAppBtn_Vue_openApp",!0,void 0,"覆盖.launch-app-btn元素上的openApp函数,可阻止点击唤醒/下载App"),d("劫持setTimeout-autoOpenApp","bili-hookSetTimeout_autoOpenApp",!0,void 0,"阻止自动调用App")]},{text:"Toast配置",type:"forms",forms:[K("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(t,e,i)=>{o.info("设置当前Qmsg弹出位置"+i);},"Toast显示在页面九宫格的位置"),K("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),d("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[d("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),d("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来获取对应的cookie"),gt("bilibili.com","httpx-cookie-bilibili.com","",void 0,void 0,"Cookie格式:xxx=xxxx;xxx=xxxx")]}]},x={isVideo(){return window.location.pathname.startsWith("/video/")},isBangumi(){return window.location.pathname.startsWith("/bangumi/")},isSearch(){return window.location.pathname.startsWith("/search")},isLive(){return window.location.hostname==="live.bilibili.com"},isOpus(){return window.location.pathname.startsWith("/opus")},isTopicDetail(){return window.location.pathname.startsWith("/topic-detail")},isDynamic(){return window.location.pathname.startsWith("/dynamic")},isHead(){return window.location.pathname==="/"||window.location.pathname.startsWith("/channel")}},bt={isPC(){return window.location.hostname==="www.bilibili.com"},isReadMobile(){return this.isPC()&&window.location.pathname.startsWith("/read/mobile")}},yt={id:"panel-video",title:"视频",isDefault(){return x.isVideo()},forms:[{text:"功能",type:"forms",forms:[d("修复视频底部区域高度","bili-video-repairVideoBottomAreaHeight",!0,void 0,"添加margin-top"),d("自动点击【继续在网页观看】","bili-video-autoClickContinueToWatchOnTheWebpage",!0,void 0,"可避免弹窗出现且自动点击后播放视频"),d("美化显示","bili-video-beautify",!0,void 0,"调整底部推荐视频卡片样式类似哔哩哔哩App"),d("手势返回关闭评论区","bili-video-gestureReturnToCloseCommentArea",!0,void 0,"当浏览器手势触发浏览器回退页面时,关闭评论区"),d("initPlayer","bili-video-initPlayer",!0,void 0,"自动执行初始化播放器"),d("强制本页刷新跳转","bili-video-forceThisPageToRefreshAndRedirect",!1,void 0,"用于解决跳转播放视频时,播放当前视频会有上一个播放视频的声音的情况")]},{text:"变量设置",type:"forms",forms:[d("playBtnNoOpenApp","bili-video-setVideoPlayer",!0,void 0,"playBtnNoOpenApp=true
playBtnOpenApp=false
coverOpenApp=false"),d("解锁充电限制","bili-video-unlockUpower",!1,void 0,"is_upower_exclusive=true
is_upower_play=false
is_upower_preview=false")]},{text:"覆盖点击事件",type:"forms",forms:[d("相关视频","bili-video-cover-bottomRecommendVideo",!0,void 0,"点击下面的相关视频可正确跳转至该视频"),d("选集","bili-video-cover-seasonNew",!0,void 0,"点击下面的选集列表内的视频可正确跳转至该视频")]},{text:"网络拦截",type:"forms",forms:[d("解锁清晰度","bili-video-xhr-unlockQuality",!0,void 0,"最高清晰度为720P")]},{text:"劫持/拦截",type:"forms",forms:[d("阻止调用App","bili-video-hook-callApp",!0,void 0,"处理函数: PlayerAgent")]}]},wt={id:"panel-bangumi",title:"番剧",isDefault(){return x.isBangumi()},forms:[{text:"变量设置",type:"forms",forms:[d("pay","bili-bangumi-setPay",!0,void 0,"$store.state.userStat.pay=1
$store.state.mediaInfo.user_status.pay=1")]},{text:"覆盖点击事件",type:"forms",forms:[d("【选集】","bili-bangumi-cover-clicl-event-chooseEp",!0,void 0,"让【选集】的视频列表可点击跳转"),d("【其它】","bili-bangumi-cover-clicl-event-other",!0,void 0,"让【PV&其他】、【预告】、【主题曲】、【香境剧场】等的视频列表可点击跳转"),d("【更多推荐】","bili-bangumi-cover-clicl-event-recommend",!0,void 0,"让【更多推荐】的视频列表可点击跳转")]},{text:"网络拦截",type:"forms",forms:[d("解锁清晰度","bili-bangumi-xhr-unlockQuality",!0,void 0,"最高清晰度为720P")]},{text:"劫持/拦截",type:"forms",forms:[d("阻止调用App","bili-bangumi-hook-callApp",!0,void 0,"")]}]},xt={id:"panel-search",title:"搜索",isDefault(){return x.isSearch()},forms:[]},kt={id:"panel-live",title:"直播",isDefault(){return x.isLive()},forms:[{text:"屏蔽",type:"forms",forms:[d("【屏蔽】聊天室","bili-live-block-chatRoom",!1,void 0,"直接不显示底部的聊天室"),d("【屏蔽】xxx进入直播间","bili-live-block-brush-prompt",!1,void 0,"直接不显示底部的xxx进入直播间"),d("【屏蔽】控制面板","bili-live-block-control-panel",!1,void 0,"屏蔽底部的发个弹幕、送礼")]},{text:"劫持/拦截",type:"forms",forms:[d("阻止open-app-btn元素点击事件触发","bili-live-prevent-openAppBtn",!0,void 0,"开启后可不跳转至唤醒App页面")]}]},_t={id:"panel-opus",title:"专栏",isDefault(){return x.isOpus()},forms:[{text:"功能",type:"forms",forms:[d("自动展开阅读全文","bili-opus-automaticallyExpandToReadFullText",!0,void 0,"屏蔽【展开阅读全文】按钮并自动处理全文高度")]},{text:"覆盖点击事件",type:"forms",forms:[d("话题","bili-opus-cover-topicJump",!0,void 0,"点击话题正确跳转"),d("header用户","bili-opus-cover-header",!0,void 0,"点击内容上的发布本动态的用户正确跳转个人空间")]}]},$t={id:"panel-dynamic",title:"动态",isDefault(){return x.isDynamic()},forms:[{text:"覆盖点击事件",type:"forms",forms:[d("话题","bili-dynamic-cover-topicJump",!0,void 0,"点击话题正确跳转"),d("header用户","bili-dynamic-cover-header",!0,void 0,"点击内容上的发布本动态的用户正确跳转个人空间"),d("@用户","bili-dynamic-cover-atJump",!0,void 0,"点击@用户正确跳转个人空间"),d("引用","bili-dynamic-cover-referenceJump",!0,void 0,"点击引用的视频|用户正确跳转")]}]},Ct={id:"panel-topic-detail",title:"话题",isDefault(){return x.isTopicDetail()},forms:[]},A={appkey:"4409e2ce8ffd12b8",appsec:"59b43e04ad6965f34319062b478f83dd"};function O(t,e,i){t.appkey=e;const r=new URLSearchParams(t);return r.sort(),lt(r.toString()+i)}const p={getVue(t){return t==null?void 0:t.__vue__},waitVuePropToSet(t,e){function i(){let r=null;return typeof t=="string"?r=document.querySelector(t):typeof t=="function"?r=t():t instanceof HTMLElement&&(r=t),r}e.forEach(r=>{typeof r.msg=="string"&&o.info(r.msg);function n(){let a=i();if(a==null)return !1;let l=p.getVue(a);return l==null?!1:!!r.check(l)}s.waitVueByInterval(()=>i(),n,250,1e4).then(a=>{if(!a)return;let l=i(),u=p.getVue(l);u!=null&&r.set(u);});});},goToUrl(t,e=!1){let i=document.querySelector("#app");if(i==null){g.error("跳转Url: 获取根元素#app失败"),o.error("跳转Url: 获取根元素#app失败:"+t);return}let r=p.getVue(i);if(r==null){o.error("获取#app的vue属性失败"),g.error("获取#app的vue属性失败");return}let n=r.$router,a=c.getValue("bili-go-to-url-blank");if(o.info("即将跳转URL:"+t),e&&(a=!1),a)window.open(t,"_blank");else {if(t.startsWith("http")||t.startsWith("//")){t.startsWith("//")&&(t=window.location.protocol+t);let l=new URL(t);if(l.origin===window.location.origin)t=l.pathname+l.search+l.hash;else {o.info("不同域名,直接本页打开,不用Router:"+t),window.location.href=t;return}}o.info("$router push跳转Url:"+t),n.push(t);}},goToLogin(t=""){window.open(`https://passport.bilibili.com/h5-app/passport/login?gourl=${encodeURIComponent(t)}`);},parseDuration(t){if(typeof t!="number"&&(t=parseInt(t)),isNaN(t))return t.toString();function e(i){return i<10?`0${i}`:i}return t<60?`0:${e(t)}`:t>=60&&t<3600?`${Math.floor(t/60)}:${e(t%60)}`:`${Math.floor(t/3600)}:${e(Math.floor(t/60)%60)}:${e(t%60)}`},hookGestureReturnByVueRouter(t){function e(){o.success("触发popstate事件"),r(!0);}function i(){o.success("监听地址改变"),t.vueObj.$router.history.push(t.hash),m.on(window,"popstate",e);}async function r(n=!1){if(m.off(window,"popstate",e),!t.callback(n))for(;;)if(t.vueObj.$router.history.current.hash===t.hash)o.info("后退!"),t.vueObj.$router.back(),await s.sleep(250);else return}return i(),{resumeBack:r}},loadScript(t){let e=document.createElement("script");return e.src=t,document.head.appendChild(e),new Promise(i=>{e.onload=function(){o.success("script标签加载完毕:"+t),setTimeout(()=>{i(!0);},100);};})},addBlockCSS(...t){let e=[];t.length!==0&&(t.length===1&&typeof t[0]=="string"&&t[0].trim()===""||(t.forEach(i=>{Array.isArray(i)?e=e.concat(i):e.push(i);}),C(`${e.join(`, + var V=typeof GM_getValue<"u"?GM_getValue:void 0,I=typeof GM_info<"u"?GM_info:void 0,ct=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,L=typeof GM_setValue<"u"?GM_setValue:void 0,ut=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,pt=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,y=typeof unsafeWindow<"u"?unsafeWindow:void 0,J=window;const dt={$data:{get enable(){return c.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return c.getValue("httpx-use-document-cookie")},cookieRule:[{key:"httpx-cookie-bilibili.com",hostname:/bilibili.com/g}]},fixCookieSplit(t){return s.isNotNull(t)&&!t.trim().endsWith(";")&&(t+=";"),t},concatCookie(t,e){return s.isNull(t)?e:(t=t.trim(),e=e.trim(),t=this.fixCookieSplit(t),e.startsWith(";")&&(e=e.substring(1)),t.concat(e))},handle(t){if(t.fetch||!this.$data.enable)return;let e="",i=t.url;i.startsWith("//")&&(i=window.location.protocol+i);let r=new URL(i);this.$data.useDocumentCookie&&r.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(e=this.concatCookie(e,document.cookie.trim())),this.$data.cookieRule.forEach(n=>{if(r.hostname.match(n.hostname)){let a=c.getValue(n.key);if(s.isNull(a))return;e=this.concatCookie(e,a);}}),s.isNotNull(e)&&(t.headers&&t.headers.Cookie?t.headers.Cookie=this.concatCookie(t.headers.Cookie,e):t.headers.Cookie=e,o.info(["Httpx => 设置cookie:",t])),t.headers&&t.headers.Cookie!=null&&s.isNull(t.headers.Cookie)&&delete t.headers.Cookie;}},mt="【移动端】bilibili优化",s=W.noConflict(),m=st.noConflict(),D=J.pops||y.pops,F=J.QRCode||y.QRCode,o=new s.Log(I,y.console||J.console);var it;const Q=((it=I==null?void 0:I.script)==null?void 0:it.name)||mt,ft=new s.GM_Cookie,rt=!1;o.config({debug:rt,logMaxCount:1e3,autoClearConsole:!0,tag:!0});g.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return c.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return c.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return c.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let t=W.getMaxZIndex(10),e=D.config.Utils.getPopsMaxZIndex(10).zIndex;return W.getMaxValue(t,e)}}}));const ht=new s.GM_Menu({GM_getValue:V,GM_setValue:L,GM_registerMenuCommand:ct,GM_unregisterMenuCommand:ut}),T=new s.Httpx(pt);T.interceptors.request.use(t=>(dt.handle(t),t));T.interceptors.response.use(void 0,t=>(o.error(["拦截器-请求错误",t]),t.type==="onabort"?g.warning("请求取消"):t.type==="onerror"?g.error("请求异常"):t.type==="ontimeout"?g.error("请求超时"):g.error("其它错误"),t));T.config({logDetails:rt});const z={Object:{defineProperty:y.Object.defineProperty},Function:{apply:y.Function.prototype.apply,call:y.Function.prototype.call},Element:{appendChild:y.Element.prototype.appendChild},setTimeout:y.setTimeout},C=s.addStyle,S="GM_Panel",P="data-key",M="data-default-value",d=function(t,e,i,r,n){let a={text:t,type:"switch",description:n,attributes:{},getValue(){return !!c.getValue(e,i)},callback(l,u){o.success(`${u?"开启":"关闭"} ${t}`),c.setValue(e,!!u);},afterAddToUListCallBack:void 0};return a.attributes&&(a.attributes[P]=e,a.attributes[M]=!!i),a},gt=function(t,e,i,r,n,a="",l){let u={text:t,type:"textarea",attributes:{},description:r,placeholder:a,disabled:l,getValue(){return c.getValue(e,i)},callback(f,v){c.setValue(e,v);}};return u.attributes&&(u.attributes[P]=e,u.attributes[M]=i),u},K=function(t,e,i,r,n,a){let l=[];typeof r=="function"?l=r():l=r;let u={text:t,type:"select",description:a,attributes:{},getValue(){return c.getValue(e,i)},callback(f,v,h){c.setValue(e,v),typeof n=="function"&&n(f,v,h);},data:l};return u.attributes&&(u.attributes[P]=e,u.attributes[M]=i),u},vt={id:"panel-common",title:"通用",forms:[{text:"功能",type:"forms",forms:[d("监听路由-重载所有功能","bili-listenRouterChange",!0,void 0,"用于处理页面跳转(本页)时功能不生效问题"),d("修复点击UP主正确进入空间","bili-repairEnterUserHome",!0,void 0,"可以修复点击UP主进入个人空间但是跳转404的问题"),d("新标签页打开","bili-go-to-url-blank",!1,void 0,"通过开启【覆盖点击事件】相关的设置,通过新标签页打开链接")]},{text:"变量设置",type:"forms",forms:[d("isLogin","bili-setLogin",!0,void 0,"$store.state.common.noCallApp=true
$store.state.common.userInfo.isLogin=true
$store.state.loginInfo.isLogin=true"),d("isClient","bili-setIsClient",!0,void 0,"$store.state.video.isClient=true
$store.state.opus.isClient=true
$store.state.playlist.isClient=true
$store.state.ver.bili=true
$store.state.ver.biliVer=2333"),d("tinyApp","bili-setTinyApp",!0,void 0,"$store.state.common.tinyApp=true")]},{text:"劫持/拦截",type:"forms",forms:[d("覆盖.launch-app-btn openApp","bili-overrideLaunchAppBtn_Vue_openApp",!0,void 0,"覆盖.launch-app-btn元素上的openApp函数,可阻止点击唤醒/下载App"),d("劫持setTimeout-autoOpenApp","bili-hookSetTimeout_autoOpenApp",!0,void 0,"阻止自动调用App")]},{text:"Toast配置",type:"forms",forms:[K("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(t,e,i)=>{o.info("设置当前Qmsg弹出位置"+i);},"Toast显示在页面九宫格的位置"),K("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),d("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[d("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),d("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来获取对应的cookie"),gt("bilibili.com","httpx-cookie-bilibili.com","",void 0,void 0,"Cookie格式:xxx=xxxx;xxx=xxxx")]}]},x={isVideo(){return window.location.pathname.startsWith("/video/")},isBangumi(){return window.location.pathname.startsWith("/bangumi/")},isSearch(){return window.location.pathname.startsWith("/search")},isLive(){return window.location.hostname==="live.bilibili.com"},isOpus(){return window.location.pathname.startsWith("/opus")},isTopicDetail(){return window.location.pathname.startsWith("/topic-detail")},isDynamic(){return window.location.pathname.startsWith("/dynamic")},isHead(){return window.location.pathname==="/"||window.location.pathname.startsWith("/channel")}},bt={isPC(){return window.location.hostname==="www.bilibili.com"},isReadMobile(){return this.isPC()&&window.location.pathname.startsWith("/read/mobile")}},yt={id:"panel-video",title:"视频",isDefault(){return x.isVideo()},forms:[{text:"功能",type:"forms",forms:[d("修复视频底部区域高度","bili-video-repairVideoBottomAreaHeight",!0,void 0,"添加margin-top"),d("自动点击【继续在网页观看】","bili-video-autoClickContinueToWatchOnTheWebpage",!0,void 0,"可避免弹窗出现且自动点击后播放视频"),d("美化显示","bili-video-beautify",!0,void 0,"调整底部推荐视频卡片样式类似哔哩哔哩App"),d("手势返回关闭评论区","bili-video-gestureReturnToCloseCommentArea",!0,void 0,"当浏览器手势触发浏览器回退页面时,关闭评论区"),d("initPlayer","bili-video-initPlayer",!0,void 0,"自动执行初始化播放器"),d("强制本页刷新跳转","bili-video-forceThisPageToRefreshAndRedirect",!1,void 0,"用于解决跳转播放视频时,播放当前视频会有上一个播放视频的声音的情况")]},{text:"变量设置",type:"forms",forms:[d("playBtnNoOpenApp","bili-video-setVideoPlayer",!0,void 0,"playBtnNoOpenApp=true
playBtnOpenApp=false
coverOpenApp=false"),d("解锁充电限制","bili-video-unlockUpower",!1,void 0,"is_upower_exclusive=true
is_upower_play=false
is_upower_preview=false")]},{text:"覆盖点击事件",type:"forms",forms:[d("相关视频","bili-video-cover-bottomRecommendVideo",!0,void 0,"点击下面的相关视频可正确跳转至该视频"),d("选集","bili-video-cover-seasonNew",!0,void 0,"点击下面的选集列表内的视频可正确跳转至该视频")]},{text:"网络拦截",type:"forms",forms:[d("解锁清晰度","bili-video-xhr-unlockQuality",!0,void 0,"最高清晰度为720P")]},{text:"劫持/拦截",type:"forms",forms:[d("阻止调用App","bili-video-hook-callApp",!0,void 0,"处理函数: PlayerAgent")]}]},wt={id:"panel-bangumi",title:"番剧",isDefault(){return x.isBangumi()},forms:[{text:"变量设置",type:"forms",forms:[d("pay","bili-bangumi-setPay",!0,void 0,"$store.state.userStat.pay=1
$store.state.mediaInfo.user_status.pay=1")]},{text:"覆盖点击事件",type:"forms",forms:[d("【选集】","bili-bangumi-cover-clicl-event-chooseEp",!0,void 0,"让【选集】的视频列表可点击跳转"),d("【其它】","bili-bangumi-cover-clicl-event-other",!0,void 0,"让【PV&其他】、【预告】、【主题曲】、【香境剧场】等的视频列表可点击跳转"),d("【更多推荐】","bili-bangumi-cover-clicl-event-recommend",!0,void 0,"让【更多推荐】的视频列表可点击跳转")]},{text:"网络拦截",type:"forms",forms:[d("解锁清晰度","bili-bangumi-xhr-unlockQuality",!0,void 0,"最高清晰度为720P")]},{text:"劫持/拦截",type:"forms",forms:[d("阻止调用App","bili-bangumi-hook-callApp",!0,void 0,"")]}]},xt={id:"panel-search",title:"搜索",isDefault(){return x.isSearch()},forms:[]},kt={id:"panel-live",title:"直播",isDefault(){return x.isLive()},forms:[{text:"屏蔽",type:"forms",forms:[d("【屏蔽】聊天室","bili-live-block-chatRoom",!1,void 0,"直接不显示底部的聊天室"),d("【屏蔽】xxx进入直播间","bili-live-block-brush-prompt",!1,void 0,"直接不显示底部的xxx进入直播间"),d("【屏蔽】控制面板","bili-live-block-control-panel",!1,void 0,"屏蔽底部的发个弹幕、送礼")]},{text:"劫持/拦截",type:"forms",forms:[d("阻止open-app-btn元素点击事件触发","bili-live-prevent-openAppBtn",!0,void 0,"开启后可不跳转至唤醒App页面")]}]},_t={id:"panel-opus",title:"专栏",isDefault(){return x.isOpus()},forms:[{text:"功能",type:"forms",forms:[d("自动展开阅读全文","bili-opus-automaticallyExpandToReadFullText",!0,void 0,"屏蔽【展开阅读全文】按钮并自动处理全文高度")]},{text:"覆盖点击事件",type:"forms",forms:[d("话题","bili-opus-cover-topicJump",!0,void 0,"点击话题正确跳转"),d("header用户","bili-opus-cover-header",!0,void 0,"点击内容上的发布本动态的用户正确跳转个人空间")]}]},$t={id:"panel-dynamic",title:"动态",isDefault(){return x.isDynamic()},forms:[{text:"覆盖点击事件",type:"forms",forms:[d("话题","bili-dynamic-cover-topicJump",!0,void 0,"点击话题正确跳转"),d("header用户","bili-dynamic-cover-header",!0,void 0,"点击内容上的发布本动态的用户正确跳转个人空间"),d("@用户","bili-dynamic-cover-atJump",!0,void 0,"点击@用户正确跳转个人空间"),d("引用","bili-dynamic-cover-referenceJump",!0,void 0,"点击引用的视频|用户正确跳转")]}]},Ct={id:"panel-topic-detail",title:"话题",isDefault(){return x.isTopicDetail()},forms:[]},A={appkey:"4409e2ce8ffd12b8",appsec:"59b43e04ad6965f34319062b478f83dd"};function O(t,e,i){t.appkey=e;const r=new URLSearchParams(t);return r.sort(),lt(r.toString()+i)}const p={getVue(t){return t==null?void 0:t.__vue__},waitVuePropToSet(t,e){function i(){let r=null;return typeof t=="string"?r=document.querySelector(t):typeof t=="function"?r=t():t instanceof HTMLElement&&(r=t),r}e.forEach(r=>{typeof r.msg=="string"&&o.info(r.msg);function n(){let a=i();if(a==null)return !1;let l=p.getVue(a);return l==null?!1:!!r.check(l)}s.waitVueByInterval(()=>i(),n,250,1e4).then(a=>{if(!a)return;let l=i(),u=p.getVue(l);u!=null&&r.set(u);});});},goToUrl(t,e=!1){let i=document.querySelector("#app");if(i==null){g.error("跳转Url: 获取根元素#app失败"),o.error("跳转Url: 获取根元素#app失败:"+t);return}let r=p.getVue(i);if(r==null){o.error("获取#app的vue属性失败"),g.error("获取#app的vue属性失败");return}let n=r.$router,a=c.getValue("bili-go-to-url-blank");if(o.info("即将跳转URL:"+t),e&&(a=!1),a)window.open(t,"_blank");else {if(t.startsWith("http")||t.startsWith("//")){t.startsWith("//")&&(t=window.location.protocol+t);let l=new URL(t);if(l.origin===window.location.origin)t=l.pathname+l.search+l.hash;else {o.info("不同域名,直接本页打开,不用Router:"+t),window.location.href=t;return}}o.info("$router push跳转Url:"+t),n.push(t);}},goToLogin(t=""){window.open(`https://passport.bilibili.com/h5-app/passport/login?gourl=${encodeURIComponent(t)}`);},parseDuration(t){if(typeof t!="number"&&(t=parseInt(t)),isNaN(t))return t.toString();function e(i){return i<10?`0${i}`:i}return t<60?`0:${e(t)}`:t>=60&&t<3600?`${Math.floor(t/60)}:${e(t%60)}`:`${Math.floor(t/3600)}:${e(Math.floor(t/60)%60)}:${e(t%60)}`},hookGestureReturnByVueRouter(t){function e(){o.success("触发popstate事件"),r(!0);}function i(){o.success("监听地址改变"),t.vueObj.$router.history.push(t.hash),m.on(window,"popstate",e);}async function r(n=!1){if(m.off(window,"popstate",e),!t.callback(n))for(;;)if(t.vueObj.$router.history.current.hash===t.hash)o.info("后退!"),t.vueObj.$router.back(),await s.sleep(250);else return}return i(),{resumeBack:r}},loadScript(t){let e=document.createElement("script");return e.src=t,document.head.appendChild(e),new Promise(i=>{e.onload=function(){o.success("script标签加载完毕:"+t),setTimeout(()=>{i(!0);},100);};})},addBlockCSS(...t){let e=[];t.length!==0&&(t.length===1&&typeof t[0]=="string"&&t[0].trim()===""||(t.forEach(i=>{Array.isArray(i)?e=e.concat(i):e.push(i);}),C(`${e.join(`, `)}{display: none !important;}`)));}};function nt(t){return (t==null?void 0:t.code)===0&&((t==null?void 0:t.message)==="0"||(t==null?void 0:t.message)==="success")}const Z={async getQrCodeInfo(){var a;let t="https://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code",e={appkey:A.appkey,local_id:"0",csrf:((a=ft.get("bili_jct"))==null?void 0:a.value)||"",ts:"0"},i=O(e,A.appkey,A.appsec),r=await T.post(t,{data:s.toSearchParamsStr({...e,sign:i}),headers:{"Content-Type":"application/x-www-form-urlencoded"},responseType:"json",fetch:!0});if(o.info(r),!r.status)return;let n=s.toJSON(r.data.responseText);if(n.code!==0){g.error(n.message);return}return n.data},async poll(t){let e="https://passport.bilibili.com/x/passport-tv-login/qrcode/poll",i={appkey:A.appkey,auth_code:t,local_id:"0",ts:"0"},r=O(i,A.appkey,A.appsec),n=await T.post(e,{data:s.toSearchParamsStr({...i,sign:r}),headers:{"Content-Type":"application/x-www-form-urlencoded"},responseType:"json",fetch:!0});if(!n.status)return {success:!1,message:"网络错误",action:void 0};const a=s.toJSON(n.data.responseText),l={0:"成功","-3":"API校验密匙错误","-400":"请求错误","-404":"啥都木有",86038:"二维码已失效",86039:"二维码尚未确认",86090:"二维码已扫码未确认"};if(!nt(a)){const v=a.code.toString(),h=a.message||l[v]||"未知错误";return v==="86038"?{success:!1,message:h,action:"refresh"}:v==="86039"||v==="86090"?{success:!1,message:h,action:"wait"}:{success:!1,message:h,action:void 0}}const u=a.data.access_token,f=Date.now()+a.data.expires_in*1e3;return {success:!0,message:"获取成功",accessKey:u,accessKeyExpireAt:f}}},E={async init(){g.info("正在申请二维码...");let t=await this.getQRCodeInfo();t&&this.confirmScanQrcode(t);},getQRCodeInfo:async function(){o.info("正在申请二维码...");let t=await Z.getQrCodeInfo();return o.info(["获取到二维码信息",t]),t},async confirmScanQrcode(t){let e=D.alert({title:{text:"请扫描二维码登录",position:"center",html:!1,style:""},content:{text:'
',html:!0},btn:{ok:{enable:!1},close:{enable:!0,callback(a){n=!0,a.close();}}},mask:{enable:!0,clickEvent:{toClose:!1,toHide:!1}},only:!0,width:"310px",height:"365px",drag:!0,dragLimit:!0,style:` #bili-qrcode-canvas{ display: flex; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.user.js" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.user.js" index 35aa8d957..f339d68ab 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.user.js" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 【移动端】bilibili优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description bilibili(哔哩哔哩)优化,免登录等 // @license GPL-3.0-only @@ -11,11 +11,11 @@ // @match *://live.bilibili.com/* // @match *://www.bilibili.com/read/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://update.greasyfork.org/scripts/497907/1394170/QRCodeJS.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/md5@2.3.0/dist/md5.min.js // @connect * // @connect m.bilibili.com @@ -59,7 +59,7 @@ get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: [ + cookieRule: [ { key: "httpx-cookie-bilibili.com", hostname: /bilibili.com/g @@ -92,18 +92,18 @@ }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data2) { - if (data2.fetch) { + handle(details) { + if (details.fetch) { return; } if (!this.$data.enable) { return; } let ownCookie = ""; - let url = data2.url; + let url = details.url; if (url.startsWith("//")) { url = window.location.protocol + url; } @@ -113,9 +113,9 @@ )) { ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { - let cookie = PopsPanel.getValue(item.key); + this.$data.cookieRule.forEach((rule) => { + if (urlObj.hostname.match(rule.hostname)) { + let cookie = PopsPanel.getValue(rule.key); if (utils.isNull(cookie)) { return; } @@ -123,15 +123,18 @@ } }); if (utils.isNotNull(ownCookie)) { - if (data2.headers && data2.headers["Cookie"]) { - data2.headers.Cookie = this.concatCookie(data2.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data2.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data2]); + log.info(["Httpx => 设置cookie:", details]); } - if (data2.headers && data2.headers.Cookie != null && utils.isNull(data2.headers.Cookie)) { - delete data2.headers.Cookie; + if (details.headers && details.headers.Cookie != null && utils.isNull(details.headers.Cookie)) { + delete details.headers.Cookie; } } }; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/package.json" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/package.json" index 3890af701..021f8ea6d 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/package.json" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/package.json" @@ -16,25 +16,25 @@ "dependencies": { "@element-plus/icons-vue": "^2.3.1", "@mgdn/bvid": "^0.2.1", - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "md5": "^2.3.0", "qmsg": "^1.1.2", - "vue": "^3.4.29", - "vue-router": "^4.3.3" + "vue": "^3.4.30", + "vue-router": "^4.4.0" }, "devDependencies": { "@types/md5": "^2.3.5", - "@types/node": "^20.14.5", + "@types/node": "^20.14.8", "@vitejs/plugin-vue": "^5.0.5", - "element-plus": "^2.7.5", - "typescript": "^5.4.5", + "element-plus": "^2.7.6", + "typescript": "^5.5.2", "unplugin-auto-import": "^0.17.6", "unplugin-element-plus": "^0.8.0", "unplugin-icons": "^0.19.0", "unplugin-vue-components": "^0.27.0", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3", - "vue-tsc": "^2.0.21" + "vue-tsc": "^2.0.22" } } diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/hook/BilibiliNetworkHook.ts" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/hook/BilibiliNetworkHook.ts" index 09835accf..180add79e 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/hook/BilibiliNetworkHook.ts" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/hook/BilibiliNetworkHook.ts" @@ -1,5 +1,6 @@ -import { Qmsg, log, utils } from "@/env"; +import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; +import type { UtilsAjaxHookResult } from "@whitesev/utils/dist/src/AjaxHookerType"; let _ajaxHooker_ = null as any as UtilsAjaxHookResult; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index dc92e0181..0a3543819 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221bilibili\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,7 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: [ + cookieRule: [ { key: "httpx-cookie-bilibili.com", hostname: /bilibili.com/g, @@ -46,11 +53,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -61,7 +68,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -76,11 +83,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -89,22 +96,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/SCRIPT_VERSION.json" index b5617341f..a54e70b4f 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1719047080458, - "version": "2024.6.22" + "time": 1719111894678, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.min.user.js" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.min.user.js" index 0d19304a5..1a051e478 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.min.user.js" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 【移动端】微博优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.22 +// @version 2024.6.23 // @author WhiteSevs // @description 劫持自动跳转登录,修复用户主页正确跳转,伪装客户端,可查看名人堂日程表,自定义视频清晰度(可1080p、2K、2K-60、4K-60) // @license GPL-3.0-only @@ -13,7 +13,7 @@ // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js // @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.7/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @resource ElementPlusResourceCSS https://fastly.jsdelivr.net/npm/element-plus@2.7.2/dist/index.min.css // @connect m.weibo.cn @@ -34,7 +34,7 @@ (function (y, z, D) { 'use strict'; - var J=Object.defineProperty;var O=(e,t,o)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var E=(e,t,o)=>O(e,typeof t!="symbol"?t+"":t,o);var C=typeof GM_getValue<"u"?GM_getValue:void 0,$=typeof GM_info<"u"?GM_info:void 0,Z=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,H=typeof GM_setValue<"u"?GM_setValue:void 0,X=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,Y=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,g=typeof unsafeWindow<"u"?unsafeWindow:void 0,U=window;const ee={$data:{get enable(){return l.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return l.getValue("httpx-use-document-cookie")},cookieList:[{key:"httpx-cookie-weibo.com",hostname:/weibo.com/g}]},fixCookieSplit(e){return c.isNotNull(e)&&!e.trim().endsWith(";")&&(e+=";"),e},concatCookie(e,t){return c.isNull(e)?t:(e=e.trim(),t=t.trim(),e=this.fixCookieSplit(e),t.startsWith(";")&&(t=t.substring(1)),e.concat(t))},handle(e){if(e.fetch||!this.$data.enable)return;let t="",o=e.url;o.startsWith("//")&&(o=window.location.protocol+o);let i=new URL(o);this.$data.useDocumentCookie&&i.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(t=this.concatCookie(t,document.cookie.trim())),this.$data.cookieList.forEach(u=>{if(u.hostname.test(i.hostname)){let s=l.getValue(u.key);if(c.isNull(s))return;t=this.concatCookie(t,s);}}),c.isNotNull(t)&&(e.headers&&e.headers.Cookie?e.headers.Cookie=this.concatCookie(e.headers.Cookie,t):e.headers.Cookie=t,n.info(["Httpx => 设置cookie:",e])),e.headers&&e.headers.Cookie!=null&&c.isNull(e.headers.Cookie)&&delete e.headers.Cookie;}},te="【移动端】微博优化",c=D.noConflict(),oe=z.noConflict(),G=U.pops||g.pops,n=new c.Log($,g.console||U.console);var Q;const L=((Q=$==null?void 0:$.script)==null?void 0:Q.name)||te,q=!1;n.config({debug:q,logMaxCount:2e4,autoClearConsole:!0,tag:!0});y.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return l.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return l.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return l.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let e=D.getMaxZIndex(10),t=G.config.Utils.getPopsMaxZIndex(10).zIndex;return D.getMaxValue(e,t)}}}));const ie=new c.GM_Menu({GM_getValue:C,GM_setValue:H,GM_registerMenuCommand:Z,GM_unregisterMenuCommand:X}),T=new c.Httpx(Y);T.interceptors.request.use(e=>(ee.handle(e),e));T.interceptors.response.use(void 0,e=>(n.error(["拦截器-请求错误",e]),e.type==="onabort"?y.warning("请求取消"):e.type==="onerror"?y.error("请求异常"):e.type==="ontimeout"?y.error("请求超时"):y.error("其它错误"),e));T.config({logDetails:q});g.Object.defineProperty,g.Function.prototype.apply,g.Function.prototype.call,g.Element.prototype.appendChild,g.setTimeout;const N=c.addStyle,x="GM_Panel",W="data-key",P="data-default-value",ne={async component(e){let t={page:"/tv/show/"+e},o={data:JSON.stringify({Component_Play_Playinfo:{oid:e}})},i=`https://www.weibo.com/tv/api/component?${c.toSearchParamsStr(t)}`,u=await T.post(i,{data:c.toSearchParamsStr(o),headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/x-www-form-urlencoded",Host:"www.weibo.com",Origin:"https://www.weibo.com","Page-Referer":t.page,Referer:"https://www.weibo.com"+t.page,"User-Agent":c.getRandomPCUA()}});if(!u.status)return;let s=c.toJSON(u.data.responseText);if(s.code!=="100000"){y.error("获取播放信息失败");return}return s.data.Component_Play_Playinfo}},M={getVue(e){if(e!=null)return e.__vue__||e.__Ivue__||e.__IVue__},waitVuePropToSet(e,t){function o(){let i=null;return typeof e=="string"?i=document.querySelector(e):typeof e=="function"?i=e():e instanceof HTMLElement&&(i=e),i}t.forEach(i=>{typeof i.msg=="string"&&n.info(i.msg);function u(){let s=o();if(s==null)return !1;let r=M.getVue(s);return r==null?!1:!!i.check(r)}c.waitVueByInterval(()=>o(),u,250,1e4).then(s=>{if(!s){typeof i.close=="function"&&i.close();return}let r=o(),a=M.getVue(r);a!=null&&i.set(a);});});}},re={"流畅 360P":{label:"流畅",sign:1,name:"mp4_ld_mp4"},"标清 480P":{label:"标清",sign:2,name:"mp4_hd_mp4"},"高清 720P":{label:"高清",sign:3,name:"mp4_720p_mp4"}},j={"高清 1080P":{label:"超清",sign:4,name:"mp4_1080p_mp4"},"超清 2K":{label:"2K",sign:5,name:"mp4_1440p_mp4"},"超清 2K60":{label:"2K-60",sign:6,name:"mp4_1440p_60fps_mp4"},"超清 4K":{label:"4K",sign:7,name:"mp4_2160p_mp4"},"超清 4K60":{label:"4K-60",sign:7,name:"mp4_2160p_60fps_mp4"}},v={...re,...j};class ae{constructor(){E(this,"$src",j);E(this,"$data",{newQualityNameList:[],videoQualityMap:new c.Dictionary});this.$data.newQualityNameList=[],this.$data.newQualityNameList.push(...Object.keys(this.$src));}lockVideoQuality(){let t=this;n.info("锁定视频清晰度"),M.waitVuePropToSet(".video-player .mwb-video",[{msg:"等待获取属性 __vue__.player.controlBar.addChild",check(o){return typeof o.player.controlBar.addChild=="function"},set(o){let i=o.player.controlBar.addChild,u=l.getValue("weibo-common-lockVideoQuality"),s=-1;Object.keys(v).find(a=>v[a].name===u?(s=v[a].sign,!0):!1);let r=function(...a){if(a[0]==="qualityButton"){let p=a[1];if(n.info(["锁定视频清晰度",p]),p.qualityList.find(f=>f.sign===1&&t.$data.videoQualityMap.has(f.src)?(t.$data.videoQualityMap.get(f.src).forEach(m=>{if(p.qualityList.findIndex(_=>_.sign===m.sign)===-1){let _={label:m.label,sign:m.sign,src:m.src};n.success(["添加新的视频清晰度",_]),p.qualityList.push(_);}}),!0):!1),s!==-1)if(p.qualityList.find(m=>m.sign===s))p.defaultSign=s;else {let m=p.qualityList.map(_=>{if(_.sign<=s)return _.sign}).filter(_=>_),b=c.getMaxValue(...m);p.defaultSign=b,n.error("该清晰度不存在,选择比该画质低的清晰度:"+b);}else {let f=p.qualityList.map(b=>b.sign),m=c.getMaxValue(...f);p.defaultSign=m;}}return i.apply(this,a)};i!=r&&(o.player.controlBar.addChild=r,n.success("成功覆盖属性 __vue__.player.controlBar.addChild"));}}]);}async unlockVideoHigherQuality(){let t=this,o=[];document.querySelectorAll(".weibo-media-wraps:not([data-unlock-quality])").forEach(i=>{i.setAttribute("data-unlock-quality","true");let u=function(){return new Promise((s,r)=>{M.waitVuePropToSet(i,[{msg:"等待获取属性 __vue__.item.object_id",check(a){var h,p,f;return typeof((h=a==null?void 0:a.item)==null?void 0:h.type)=="string"&&((p=a==null?void 0:a.item)==null?void 0:p.type)!=="video"?!0:typeof((f=a==null?void 0:a.item)==null?void 0:f.object_id)=="string"},close(){s();},async set(a){try{if(a.item.type!=="video")return;let h=a.item.object_id,p=a.item.urls;n.success("成功获取属性 __vue__.item.object_id="+h);let f=await ne.component(h);if(!f)return;if(n.info(["获取组件信息成功",f]),!f.urls){n.error("获取组件信息urls失败"),y.error("获取组件信息urls失败");return}if(typeof f.urls!="object"){n.error("组件信息urls不是一个对象"),y.error("组件信息urls不是一个对象");return}if(!Object.keys(f.urls).length){n.error("组件信息urls为空"),y.error("组件信息urls为空");return}Object.keys(f.urls).forEach(m=>{let b=f.urls[m];if(t.$data.newQualityNameList.includes(m)){let _={label:t.$src[m].label,name:t.$src[m].name,sign:t.$src[m].sign,src:b},V=p.mp4_ld_mp4;if(V)if(!t.$data.videoQualityMap.has(V))t.$data.videoQualityMap.set(V,[_]);else {let I=t.$data.videoQualityMap.get(V);I.push(_),t.$data.videoQualityMap.set(V,I);}}if(m in v){let _=v[m];_.name in p||(n.success(["新增清晰度:",_]),p[_.name]=b);}else n.error(["视频清晰度映射尚未补充",{srcName:m,src:b}]);});}catch(h){n.error(h);}finally{s();}}}]);})};o.push(u);});for(const i of o)i(),await c.sleep(100);}}const A=function(e,t,o,i,u,s){let r=[];typeof i=="function"?r=i():r=i;let a={text:e,type:"select",description:s,attributes:{},getValue(){return l.getValue(t,o)},callback(h,p,f){l.setValue(t,p),typeof u=="function"&&u(h,p,f);},data:r};return a.attributes&&(a.attributes[W]=t,a.attributes[P]=o),a},d=function(e,t,o,i,u){let s={text:e,type:"switch",description:u,attributes:{},getValue(){return !!l.getValue(t,o)},callback(r,a){n.success(`${a?"开启":"关闭"} ${e}`),l.setValue(t,!!a);},afterAddToUListCallBack:void 0};return s.attributes&&(s.attributes[W]=t,s.attributes[P]=!!o),s},se=function(e,t,o,i,u,s="",r){let a={text:e,type:"textarea",attributes:{},description:i,placeholder:s,disabled:r,getValue(){return l.getValue(t,o)},callback(h,p){l.setValue(t,p);}};return a.attributes&&(a.attributes[W]=t,a.attributes[P]=o),a},le={id:"weibo-panel-config-currency",title:"通用",forms:[{text:"功能",type:"forms",forms:[A("视频清晰度","weibo-common-lockVideoQuality","",[{value:"",text:"自动"},...(()=>{let e=[];return Object.keys(v).forEach(t=>{let o=v[t];e.push({value:o.name,text:t});}),e})()],void 0,"设置视频清晰度,默认自动,其它的清晰度将自动被删除(强制固定选择的清晰度)"),d("解锁更多清晰度","weibo-common-unlockVideoHigherQuality",!0,void 0,"自动请求PC端的视频清晰度,如果请求成功,将解锁更多的清晰度,如1080p、2K、2K-60、4K-60")]},{text:"屏蔽",type:"forms",forms:[d("【屏蔽】广告","weibo_remove_ads",!0,void 0,"包括【登录/注册按钮】、【小程序横幅推荐】"),d("【屏蔽】底部工具栏","weibo_shield_bottom_bar",!1,void 0,"屏蔽聊天/关注按钮")]},{text:"拦截跳转",type:"forms",forms:[d("api/attitudes/create","weibo_apply_attitudes_create",!0),d("点赞","weibo_apply_likes_update",!0,void 0,"未登录时,拦截点赞跳转登录"),d("评论","weibo_apply_comments_create",!0,void 0,"未登录时,拦截评论跳转登录"),d("关注","weibo_apply_friendships_create",!0,void 0,"未登录时,拦截关注跳转登录"),d("转发","weibo_apply_statuses_repostTimeline",!0,void 0,"未登录时,拦截查看转发数据"),d("回复","weibo_apply_comments_reply",!0,void 0,"未登录时,拦截回复跳转登录"),d("优化跳转主页","weibo_apply_profile_info",!0,void 0,"未登录时,正确跳转至用户主页"),d("下拉加载更多评论","weibo_apply_comments_hotflow",!0,void 0,"未登录时,拦截下拉加载更多评论跳转登录"),d("楼中楼下拉加载更多评论","weibo_apply_comments_hotFlowChild",!0,void 0,"未登录时,拦截下拉加载更多评论跳转登录")]},{text:"网络请求(不一定能劫持到)",type:"forms",forms:[d("/api/config","weibo_request_api_config",!0,void 0,"Api为获取用户数据,未登录时伪装为已登录"),d("/comments/hot","weibo_request_comments_hot",!0,void 0,"Api为获取评论数据,未登录时伪装为成功获取评论数据"),d("/status/push","weibo_request_status_push",!0,void 0,"Api为获取顶部的热点新闻信息流")]},{text:"Router路由",type:"forms",forms:[d("监听路由改变","weibo-listenRouterChange",!0,void 0,"监听路由改变,动态加载功能"),d("修复用户主页正确跳转","weibo_router_profile_to_user_home",!0,void 0,"可以正确跳转至用户主页")]},{text:"函数禁用",type:"forms",forms:[d("navigator.serviceWorker.register","weibo_hijack_navigator_service_worker_register",!0,void 0,"禁止注册serviceWorker")]},{text:"Toast配置",type:"forms",forms:[A("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(e,t,o)=>{n.info("设置当前Qmsg弹出位置"+o);},"Toast显示在页面九宫格的位置"),A("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),d("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[d("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),d("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来获取对应的cookie"),se("weibo.com","httpx-cookie-weibo.com","",void 0,void 0,"Cookie格式:xxx=xxxx;xxx=xxxx")]}]},ue={id:"weibo-panel-config-huati",title:"话题",forms:[{text:"功能",type:"forms",forms:[d("伪装微博客户端","huati_weibo_masquerade_weibo_client_app",!0,void 0,"可以隐藏底部的【在微博内打开】")]},{text:"网络请求(不一定能劫持到)",type:"forms",forms:[d("/ajax/super/starschedule","huati_weibo_get_more_celebrity_calendar_information",!0,void 0,"Api为获取日程数据,开启后可获取正常日程数据")]}]},ce={id:"weibo-panel-config-video",title:"视频",forms:[{text:"功能",type:"forms",forms:[A("视频清晰度","weibo-video-quality","",[{value:"",text:"自动"},{value:"mp4_ld_mp4",text:"流畅360p"},{value:"mp4_hd_mp4",text:"标清480p"},{value:"mp4_720p_mp4",text:"高清720p"},{value:"mp4_1080p_mp4",text:"超清1080p"}],void 0,"设置视频清晰度,默认自动,其它的清晰度将自动被删除(强制固定选择的清晰度)"),d("解锁1080p","weibo-video-unlockVideo1080p",!0,void 0,"请求PC端的视频1080p链接,开启该功能↑选择的1080p才会生效")]},{text:"屏蔽",type:"forms",forms:[d("【屏蔽】底部工具栏","weibo_video_shield_bottom_toolbar",!0),d("【屏蔽】相关推荐","weibo_video_shield_recommend",!0),d("【屏蔽】热门评论","weibo_video_shield_hot_comments",!0)]},{text:"webpack",type:"forms",forms:[d("gotoApp","weibo_video_webpack_gotoApp",!0,void 0,"开启后阻止唤醒Scheme")]}]},w={data:null,oneSuccessExecMenu:null,onceExec:null,listenData:null},l={$data:{get data(){return w.data==null&&(w.data=new c.Dictionary),w.data},get oneSuccessExecMenu(){return w.oneSuccessExecMenu==null&&(w.oneSuccessExecMenu=new c.Dictionary),w.oneSuccessExecMenu},get onceExec(){return w.onceExec==null&&(w.onceExec=new c.Dictionary),w.onceExec},get scriptName(){return L},key:x,attributeKeyName:W,attributeDefaultValueName:P},$listener:{get listenData(){return w.listenData==null&&(w.listenData=new c.Dictionary),w.listenData}},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){g.top===g.self&&ie.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}}]);},initPanelDefaultValue(){let e=this;function t(i){if(!i.attributes)return;let u=i.attributes[W],s=i.attributes[P];if(u==null){n.warn(["请先配置键",i]);return}e.$data.data.has(u)&&n.warn("请检查该key(已存在): "+u),e.$data.data.set(u,s);}let o=this.getPanelContentConfig();for(let i=0;it in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var E=(e,t,o)=>O(e,typeof t!="symbol"?t+"":t,o);var C=typeof GM_getValue<"u"?GM_getValue:void 0,$=typeof GM_info<"u"?GM_info:void 0,Z=typeof GM_registerMenuCommand<"u"?GM_registerMenuCommand:void 0,H=typeof GM_setValue<"u"?GM_setValue:void 0,X=typeof GM_unregisterMenuCommand<"u"?GM_unregisterMenuCommand:void 0,Y=typeof GM_xmlhttpRequest<"u"?GM_xmlhttpRequest:void 0,g=typeof unsafeWindow<"u"?unsafeWindow:void 0,U=window;const ee={$data:{get enable(){return l.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return l.getValue("httpx-use-document-cookie")},cookieRule:[{key:"httpx-cookie-weibo.com",hostname:/weibo.com/g}]},fixCookieSplit(e){return c.isNotNull(e)&&!e.trim().endsWith(";")&&(e+=";"),e},concatCookie(e,t){return c.isNull(e)?t:(e=e.trim(),t=t.trim(),e=this.fixCookieSplit(e),t.startsWith(";")&&(t=t.substring(1)),e.concat(t))},handle(e){if(e.fetch||!this.$data.enable)return;let t="",o=e.url;o.startsWith("//")&&(o=window.location.protocol+o);let i=new URL(o);this.$data.useDocumentCookie&&i.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(t=this.concatCookie(t,document.cookie.trim())),this.$data.cookieRule.forEach(u=>{if(i.hostname.match(u.hostname)){let s=l.getValue(u.key);if(c.isNull(s))return;t=this.concatCookie(t,s);}}),c.isNotNull(t)&&(e.headers&&e.headers.Cookie?e.headers.Cookie=this.concatCookie(e.headers.Cookie,t):e.headers.Cookie=t,n.info(["Httpx => 设置cookie:",e])),e.headers&&e.headers.Cookie!=null&&c.isNull(e.headers.Cookie)&&delete e.headers.Cookie;}},te="【移动端】微博优化",c=D.noConflict(),oe=z.noConflict(),G=U.pops||g.pops,n=new c.Log($,g.console||U.console);var Q;const L=((Q=$==null?void 0:$.script)==null?void 0:Q.name)||te,q=!1;n.config({debug:q,logMaxCount:2e4,autoClearConsole:!0,tag:!0});y.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return l.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return l.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return l.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let e=D.getMaxZIndex(10),t=G.config.Utils.getPopsMaxZIndex(10).zIndex;return D.getMaxValue(e,t)}}}));const ie=new c.GM_Menu({GM_getValue:C,GM_setValue:H,GM_registerMenuCommand:Z,GM_unregisterMenuCommand:X}),T=new c.Httpx(Y);T.interceptors.request.use(e=>(ee.handle(e),e));T.interceptors.response.use(void 0,e=>(n.error(["拦截器-请求错误",e]),e.type==="onabort"?y.warning("请求取消"):e.type==="onerror"?y.error("请求异常"):e.type==="ontimeout"?y.error("请求超时"):y.error("其它错误"),e));T.config({logDetails:q});g.Object.defineProperty,g.Function.prototype.apply,g.Function.prototype.call,g.Element.prototype.appendChild,g.setTimeout;const N=c.addStyle,x="GM_Panel",W="data-key",P="data-default-value",ne={async component(e){let t={page:"/tv/show/"+e},o={data:JSON.stringify({Component_Play_Playinfo:{oid:e}})},i=`https://www.weibo.com/tv/api/component?${c.toSearchParamsStr(t)}`,u=await T.post(i,{data:c.toSearchParamsStr(o),headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/x-www-form-urlencoded",Host:"www.weibo.com",Origin:"https://www.weibo.com","Page-Referer":t.page,Referer:"https://www.weibo.com"+t.page,"User-Agent":c.getRandomPCUA()}});if(!u.status)return;let s=c.toJSON(u.data.responseText);if(s.code!=="100000"){y.error("获取播放信息失败");return}return s.data.Component_Play_Playinfo}},M={getVue(e){if(e!=null)return e.__vue__||e.__Ivue__||e.__IVue__},waitVuePropToSet(e,t){function o(){let i=null;return typeof e=="string"?i=document.querySelector(e):typeof e=="function"?i=e():e instanceof HTMLElement&&(i=e),i}t.forEach(i=>{typeof i.msg=="string"&&n.info(i.msg);function u(){let s=o();if(s==null)return !1;let a=M.getVue(s);return a==null?!1:!!i.check(a)}c.waitVueByInterval(()=>o(),u,250,1e4).then(s=>{if(!s){typeof i.close=="function"&&i.close();return}let a=o(),r=M.getVue(a);r!=null&&i.set(r);});});}},ae={"流畅 360P":{label:"流畅",sign:1,name:"mp4_ld_mp4"},"标清 480P":{label:"标清",sign:2,name:"mp4_hd_mp4"},"高清 720P":{label:"高清",sign:3,name:"mp4_720p_mp4"}},j={"高清 1080P":{label:"超清",sign:4,name:"mp4_1080p_mp4"},"超清 2K":{label:"2K",sign:5,name:"mp4_1440p_mp4"},"超清 2K60":{label:"2K-60",sign:6,name:"mp4_1440p_60fps_mp4"},"超清 4K":{label:"4K",sign:7,name:"mp4_2160p_mp4"},"超清 4K60":{label:"4K-60",sign:7,name:"mp4_2160p_60fps_mp4"}},v={...ae,...j};class re{constructor(){E(this,"$src",j);E(this,"$data",{newQualityNameList:[],videoQualityMap:new c.Dictionary});this.$data.newQualityNameList=[],this.$data.newQualityNameList.push(...Object.keys(this.$src));}lockVideoQuality(){let t=this;n.info("锁定视频清晰度"),M.waitVuePropToSet(".video-player .mwb-video",[{msg:"等待获取属性 __vue__.player.controlBar.addChild",check(o){return typeof o.player.controlBar.addChild=="function"},set(o){let i=o.player.controlBar.addChild,u=l.getValue("weibo-common-lockVideoQuality"),s=-1;Object.keys(v).find(r=>v[r].name===u?(s=v[r].sign,!0):!1);let a=function(...r){if(r[0]==="qualityButton"){let p=r[1];if(n.info(["锁定视频清晰度",p]),p.qualityList.find(f=>f.sign===1&&t.$data.videoQualityMap.has(f.src)?(t.$data.videoQualityMap.get(f.src).forEach(m=>{if(p.qualityList.findIndex(_=>_.sign===m.sign)===-1){let _={label:m.label,sign:m.sign,src:m.src};n.success(["添加新的视频清晰度",_]),p.qualityList.push(_);}}),!0):!1),s!==-1)if(p.qualityList.find(m=>m.sign===s))p.defaultSign=s;else {let m=p.qualityList.map(_=>{if(_.sign<=s)return _.sign}).filter(_=>_),b=c.getMaxValue(...m);p.defaultSign=b,n.error("该清晰度不存在,选择比该画质低的清晰度:"+b);}else {let f=p.qualityList.map(b=>b.sign),m=c.getMaxValue(...f);p.defaultSign=m;}}return i.apply(this,r)};i!=a&&(o.player.controlBar.addChild=a,n.success("成功覆盖属性 __vue__.player.controlBar.addChild"));}}]);}async unlockVideoHigherQuality(){let t=this,o=[];document.querySelectorAll(".weibo-media-wraps:not([data-unlock-quality])").forEach(i=>{i.setAttribute("data-unlock-quality","true");let u=function(){return new Promise((s,a)=>{M.waitVuePropToSet(i,[{msg:"等待获取属性 __vue__.item.object_id",check(r){var h,p,f;return typeof((h=r==null?void 0:r.item)==null?void 0:h.type)=="string"&&((p=r==null?void 0:r.item)==null?void 0:p.type)!=="video"?!0:typeof((f=r==null?void 0:r.item)==null?void 0:f.object_id)=="string"},close(){s();},async set(r){try{if(r.item.type!=="video")return;let h=r.item.object_id,p=r.item.urls;n.success("成功获取属性 __vue__.item.object_id="+h);let f=await ne.component(h);if(!f)return;if(n.info(["获取组件信息成功",f]),!f.urls){n.error("获取组件信息urls失败"),y.error("获取组件信息urls失败");return}if(typeof f.urls!="object"){n.error("组件信息urls不是一个对象"),y.error("组件信息urls不是一个对象");return}if(!Object.keys(f.urls).length){n.error("组件信息urls为空"),y.error("组件信息urls为空");return}Object.keys(f.urls).forEach(m=>{let b=f.urls[m];if(t.$data.newQualityNameList.includes(m)){let _={label:t.$src[m].label,name:t.$src[m].name,sign:t.$src[m].sign,src:b},V=p.mp4_ld_mp4;if(V)if(!t.$data.videoQualityMap.has(V))t.$data.videoQualityMap.set(V,[_]);else {let I=t.$data.videoQualityMap.get(V);I.push(_),t.$data.videoQualityMap.set(V,I);}}if(m in v){let _=v[m];_.name in p||(n.success(["新增清晰度:",_]),p[_.name]=b);}else n.error(["视频清晰度映射尚未补充",{srcName:m,src:b}]);});}catch(h){n.error(h);}finally{s();}}}]);})};o.push(u);});for(const i of o)i(),await c.sleep(100);}}const A=function(e,t,o,i,u,s){let a=[];typeof i=="function"?a=i():a=i;let r={text:e,type:"select",description:s,attributes:{},getValue(){return l.getValue(t,o)},callback(h,p,f){l.setValue(t,p),typeof u=="function"&&u(h,p,f);},data:a};return r.attributes&&(r.attributes[W]=t,r.attributes[P]=o),r},d=function(e,t,o,i,u){let s={text:e,type:"switch",description:u,attributes:{},getValue(){return !!l.getValue(t,o)},callback(a,r){n.success(`${r?"开启":"关闭"} ${e}`),l.setValue(t,!!r);},afterAddToUListCallBack:void 0};return s.attributes&&(s.attributes[W]=t,s.attributes[P]=!!o),s},se=function(e,t,o,i,u,s="",a){let r={text:e,type:"textarea",attributes:{},description:i,placeholder:s,disabled:a,getValue(){return l.getValue(t,o)},callback(h,p){l.setValue(t,p);}};return r.attributes&&(r.attributes[W]=t,r.attributes[P]=o),r},le={id:"weibo-panel-config-currency",title:"通用",forms:[{text:"功能",type:"forms",forms:[A("视频清晰度","weibo-common-lockVideoQuality","",[{value:"",text:"自动"},...(()=>{let e=[];return Object.keys(v).forEach(t=>{let o=v[t];e.push({value:o.name,text:t});}),e})()],void 0,"设置视频清晰度,默认自动,其它的清晰度将自动被删除(强制固定选择的清晰度)"),d("解锁更多清晰度","weibo-common-unlockVideoHigherQuality",!0,void 0,"自动请求PC端的视频清晰度,如果请求成功,将解锁更多的清晰度,如1080p、2K、2K-60、4K-60")]},{text:"屏蔽",type:"forms",forms:[d("【屏蔽】广告","weibo_remove_ads",!0,void 0,"包括【登录/注册按钮】、【小程序横幅推荐】"),d("【屏蔽】底部工具栏","weibo_shield_bottom_bar",!1,void 0,"屏蔽聊天/关注按钮")]},{text:"拦截跳转",type:"forms",forms:[d("api/attitudes/create","weibo_apply_attitudes_create",!0),d("点赞","weibo_apply_likes_update",!0,void 0,"未登录时,拦截点赞跳转登录"),d("评论","weibo_apply_comments_create",!0,void 0,"未登录时,拦截评论跳转登录"),d("关注","weibo_apply_friendships_create",!0,void 0,"未登录时,拦截关注跳转登录"),d("转发","weibo_apply_statuses_repostTimeline",!0,void 0,"未登录时,拦截查看转发数据"),d("回复","weibo_apply_comments_reply",!0,void 0,"未登录时,拦截回复跳转登录"),d("优化跳转主页","weibo_apply_profile_info",!0,void 0,"未登录时,正确跳转至用户主页"),d("下拉加载更多评论","weibo_apply_comments_hotflow",!0,void 0,"未登录时,拦截下拉加载更多评论跳转登录"),d("楼中楼下拉加载更多评论","weibo_apply_comments_hotFlowChild",!0,void 0,"未登录时,拦截下拉加载更多评论跳转登录")]},{text:"网络请求(不一定能劫持到)",type:"forms",forms:[d("/api/config","weibo_request_api_config",!0,void 0,"Api为获取用户数据,未登录时伪装为已登录"),d("/comments/hot","weibo_request_comments_hot",!0,void 0,"Api为获取评论数据,未登录时伪装为成功获取评论数据"),d("/status/push","weibo_request_status_push",!0,void 0,"Api为获取顶部的热点新闻信息流")]},{text:"Router路由",type:"forms",forms:[d("监听路由改变","weibo-listenRouterChange",!0,void 0,"监听路由改变,动态加载功能"),d("修复用户主页正确跳转","weibo_router_profile_to_user_home",!0,void 0,"可以正确跳转至用户主页")]},{text:"函数禁用",type:"forms",forms:[d("navigator.serviceWorker.register","weibo_hijack_navigator_service_worker_register",!0,void 0,"禁止注册serviceWorker")]},{text:"Toast配置",type:"forms",forms:[A("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(e,t,o)=>{n.info("设置当前Qmsg弹出位置"+o);},"Toast显示在页面九宫格的位置"),A("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),d("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[d("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),d("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来获取对应的cookie"),se("weibo.com","httpx-cookie-weibo.com","",void 0,void 0,"Cookie格式:xxx=xxxx;xxx=xxxx")]}]},ue={id:"weibo-panel-config-huati",title:"话题",forms:[{text:"功能",type:"forms",forms:[d("伪装微博客户端","huati_weibo_masquerade_weibo_client_app",!0,void 0,"可以隐藏底部的【在微博内打开】")]},{text:"网络请求(不一定能劫持到)",type:"forms",forms:[d("/ajax/super/starschedule","huati_weibo_get_more_celebrity_calendar_information",!0,void 0,"Api为获取日程数据,开启后可获取正常日程数据")]}]},ce={id:"weibo-panel-config-video",title:"视频",forms:[{text:"功能",type:"forms",forms:[A("视频清晰度","weibo-video-quality","",[{value:"",text:"自动"},{value:"mp4_ld_mp4",text:"流畅360p"},{value:"mp4_hd_mp4",text:"标清480p"},{value:"mp4_720p_mp4",text:"高清720p"},{value:"mp4_1080p_mp4",text:"超清1080p"}],void 0,"设置视频清晰度,默认自动,其它的清晰度将自动被删除(强制固定选择的清晰度)"),d("解锁1080p","weibo-video-unlockVideo1080p",!0,void 0,"请求PC端的视频1080p链接,开启该功能↑选择的1080p才会生效")]},{text:"屏蔽",type:"forms",forms:[d("【屏蔽】底部工具栏","weibo_video_shield_bottom_toolbar",!0),d("【屏蔽】相关推荐","weibo_video_shield_recommend",!0),d("【屏蔽】热门评论","weibo_video_shield_hot_comments",!0)]},{text:"webpack",type:"forms",forms:[d("gotoApp","weibo_video_webpack_gotoApp",!0,void 0,"开启后阻止唤醒Scheme")]}]},w={data:null,oneSuccessExecMenu:null,onceExec:null,listenData:null},l={$data:{get data(){return w.data==null&&(w.data=new c.Dictionary),w.data},get oneSuccessExecMenu(){return w.oneSuccessExecMenu==null&&(w.oneSuccessExecMenu=new c.Dictionary),w.oneSuccessExecMenu},get onceExec(){return w.onceExec==null&&(w.onceExec=new c.Dictionary),w.onceExec},get scriptName(){return L},key:x,attributeKeyName:W,attributeDefaultValueName:P},$listener:{get listenData(){return w.listenData==null&&(w.listenData=new c.Dictionary),w.listenData}},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){g.top===g.self&&ie.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}}]);},initPanelDefaultValue(){let e=this;function t(i){if(!i.attributes)return;let u=i.attributes[W],s=i.attributes[P];if(u==null){n.warn(["请先配置键",i]);return}e.$data.data.has(u)&&n.warn("请检查该key(已存在): "+u),e.$data.data.set(u,s);}let o=this.getPanelContentConfig();for(let i=0;i{r({data:{}});});if(o==="api/likes/update"&&l.getValue("weibo_apply_likes_update"))return n.success("拦截点赞跳转登录"),new Promise(r=>{r({data:{}});});if(o==="api/comments/create"&&l.getValue("weibo_apply_comments_create"))return n.success("拦截评论跳转登录"),new Promise(r=>{r({data:{}});});if(o==="api/friendships/create"&&l.getValue("weibo_apply_friendships_create"))return n.success("拦截关注跳转登录"),new Promise(r=>{r({data:{}});});if(o==="api/comments/reply"&&l.getValue("weibo_apply_comments_reply"))return n.success("拦截回复跳转登录"),new Promise((r,a)=>{r({data:{ok:200}});});if(o.startsWith("profile/info")&&l.getValue("weibo_apply_profile_info")){n.success(["优化跳转xx微博主页",i]);let r=`https://weibo.com/${i.uid}`;return n.success("跳转微博主页:"+r),window.location.href=r,null}else if(o==="comments/hotflow"&&l.getValue("weibo_apply_comments_hotflow")){if(!("id"in i&&"max_id_type"in i&&"mid"in i)||"id"in i&&"max_id"in i&&"max_id_type"in i&&"mid"in i)return n.success(["拦截下拉加载更多评论跳转登录",i]),new Promise(r=>{r({ok:1,data:{data:[],total_number:0}});})}else if(o==="comments/hotFlowChild"&&l.getValue("weibo_apply_comments_hotFlowChild")){if("max_id"in i&&i.max_id!==0)return n.success(["拦截评论中的评论下拉加载更多评论跳转登录",i]),new Promise(r=>{r({data:{ok:1,data:[],rootComment:[],total_number:0}});})}else if(o==="api/statuses/repostTimeline"&&l.getValue("weibo_apply_statuses_repostTimeline"))return n.success(["拦截查看转发数据,因为需登录",i]),new Promise(r=>{r({data:{ok:1,data:{data:[],total_number:0}}});});return e.call(this,...t)};},hookNetWork(){F.ajaxHooker.hook(function(e){n.info(["ajaxHookr: ",e.url]),e.url.startsWith("https://m.weibo.cn/api/config")&&l.getValue("weibo_request_api_config")?e.response=function(t){let o=c.toJSON(t.responseText);o.data.preferQuickapp=0,o.data.login=!0,o.data.uid="",Reflect.deleteProperty(o.data,"loginUrl"),Reflect.deleteProperty(o.data,"wx_callback"),Reflect.deleteProperty(o.data,"wx_authorize"),Reflect.deleteProperty(o.data,"passport_login_url"),n.success("伪装已登录"),t.responseText=JSON.stringify(o);}:e.url.startsWith("https://m.weibo.cn/comments/hot")&&l.getValue("weibo_request_comments_hot")?e.response=function(t){let o=c.toJSON(t.responseText);o.ok!==1&&(n.error(["由于尚未登录,获取不到更多评论数据",o]),o={ok:1}),t.responseText=JSON.stringify(o);}:e.url.startsWith("https://m.weibo.cn/status/push?")&&l.getValue("weibo_request_status_push")&&(e.response=function(t){c.toJSON(t.responseText),t.json={};});});},hookWebpack(e="webpackJsonp",t,o){let i;Object.defineProperty(g,e,{get(){return i},set(u){n.success("成功劫持webpack,当前webpack名:"+e),i=u;const s=i.push;i.push=function(...r){let a=r[0][0];return (t==a||Array.isArray(t)&&Array.isArray(a)&&JSON.stringify(t)===JSON.stringify(a))&&Object.keys(r[0][1]).forEach(h=>{let p=r[0][1][h];r[0][1][h]=function(...f){let m=p.call(this,...f);return f[0]=o(f[0]),m};}),s.call(this,...r)};}});},hookVueRouter(){M.waitVuePropToSet("#app",[{msg:"等待获取属性 __vue__.$router",check(e){var t;return typeof((t=e==null?void 0:e.$router)==null?void 0:t.push)=="function"},set(e){n.success("拦截Vue路由跳转"),e.$router.beforeEach((t,o,i)=>{var u;if(t.name==="profile"&&l.getValue("weibo_router_profile_to_user_home")){let s=(u=t==null?void 0:t.params)==null?void 0:u.uid;if(s==null){n.error("获取uid失败"),y.error("获取uid失败");return}n.success(`修复跳转${s}微博主页`);let r=`https://m.weibo.cn/u/${s}`;window.location.href=r;return}i();}),e.$router.afterEach((t,o)=>{l.execMenu("weibo-listenRouterChange",()=>{n.info("路由更新,重载功能"),K.init();});});}}]);},hookServiceWorkerRegister(){n.info("hook => navigator.serviceWorker.register"),g.Object.defineProperty(g.navigator.serviceWorker,"register",{get(){return function(...e){n.success(["劫持navigator.serviceWorker.register: ",e]);}}});}},k={isMWeiBo(){return globalThis.location.hostname==="m.weibo.cn"},isMWeiBo_detail(){return this.isMWeiBo()&&globalThis.location.pathname.startsWith("/detail/")},isMWeiBo_u(){return this.isMWeiBo()&&globalThis.location.pathname.startsWith("/u/")},isMWeiBo_search(){return this.isMWeiBo()&&globalThis.location.pathname.startsWith("/search")},isHuaTi(){return globalThis.location.hostname==="huati.weibo.cn"},isVideo(){return globalThis.location.hostname==="h5.video.weibo.com"}},de={init(){l.execMenu("huati_weibo_masquerade_weibo_client_app",()=>{this.isWeibo();}),l.execMenuOnce("huati_weibo_get_more_celebrity_calendar_information",()=>{this.hookNetWorkWithGetMoreCelebrityCalendarInformation();});},isWeibo(){n.info("伪装微博"),M.waitVuePropToSet("#loadMore",[{msg:"等待设置属性 __vue__.isWeibo",check(e){return typeof e.isWeibo=="boolean"},set(e){e.isWeibo=!0,n.success("成功设置属性 __vue__.isWeibo=true");}}]);},hookNetWorkWithGetMoreCelebrityCalendarInformation(){F.ajaxHooker.hook(e=>{n.info(["ajaxHookr: ",e.url]),e.url.startsWith("/ajax/super/starschedule?")&&(e.response=async t=>{let o=await T.get(e.url,{headers:{Host:globalThis.location.hostname,Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest","sec-ch-ua-mobile":"?1","User-Agent":c.getRandomAndroidUA()+" Weibo (__weibo__)","sec-ch-ua-platform":"Android","Sec-Fetch-Site":"same-origin","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:globalThis.location.href,"Accept-Encoding":"gzip, deflate, br","Accept-Language":"zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"}});t.response=o.data.responseText,t.responseText=o.data.responseText;});});}},fe={init(){this.hookWebpack();},hookWebpack(){n.info("劫持webpack"),S.hookWebpack("webpackJsonp","chunk-common",e=>{if(typeof(e==null?void 0:e.exports)=="object"&&typeof e.exports.a=="object"&&typeof e.exports.a.gotoApp=="function"&&l.getValue("weibo_video_webpack_gotoApp"))return n.success(["成功劫持webpack调用函数",e]),e.exports.a.gotoApp=function(...t){n.info(["阻止唤醒App:",t]);},e});}},R={addBlockCSS(...e){let t=[];e.length!==0&&(e.length===1&&typeof e[0]=="string"&&e[0].trim()===""||(e.forEach(o=>{Array.isArray(o)?t=t.concat(o):t.push(o);}),N(`${t.join(`, -`)}{display: none !important;}`)));}},me={init(){l.onceExec("weibo-video-init-hook",()=>{fe.init();}),l.execMenuOnce("weibo_video_shield_bottom_toolbar",()=>{this.shieldBottomToolBar();}),l.execMenuOnce("weibo_video_shield_hot_comments",()=>{this.shieldHotComments();}),l.execMenuOnce("weibo_video_shield_recommend",()=>{this.shieldRecommend();});},shieldBottomToolBar(){n.info("【屏蔽】底部工具栏"),R.addBlockCSS(".woo-toolBar");},shieldRecommend(){n.info("【屏蔽】相关推荐"),R.addBlockCSS('#app .woo-panel[class*="Playdetail_card_"]:nth-child(2)');},shieldHotComments(){n.info("【屏蔽】热门评论"),R.addBlockCSS('#app .woo-panel[class*="Playdetail_card_"]:nth-child(3)');}},K={$data:{weiBoUnlockQuality:new ae},init(){l.execMenuOnce("weibo_hijack_navigator_service_worker_register",()=>{S.hookServiceWorkerRegister();}),k.isHuaTi()?(n.info("Router: 话题"),de.init()):k.isMWeiBo()?(n.info("Router: 移动端微博"),l.onceExec("weibo-m-init",()=>{S.hookNetWork(),S.hookApply(),S.hookVueRouter();}),l.execMenuOnce("weibo_remove_ads",()=>{N(pe);}),l.execMenuOnce("weibo_shield_bottom_bar",()=>{this.shieldBottomBar();}),this.$data.weiBoUnlockQuality.lockVideoQuality(),oe.ready(()=>{l.execMenuOnce("weibo-common-unlockVideoHigherQuality",()=>{let e=new c.LockFunction(()=>{this.$data.weiBoUnlockQuality.unlockVideoHigherQuality();},15);c.mutationObserver(document.body,{config:{subtree:!0,childList:!0},immediate:!0,callback:()=>{e.run();}});});}),k.isMWeiBo_detail()?n.info("Router: 移动端微博帖子"):k.isMWeiBo_u()?n.info("Router: 移动端微博主页"):k.isMWeiBo_search()&&n.info("Router: 移动端微博搜索")):k.isVideo()?(n.info("Router: 视频页"),me.init()):n.error("Router: 未适配 => "+window.location.href);},shieldBottomBar(){n.info("【屏蔽】底部工具栏"),R.addBlockCSS("#app div.m-tab-bar.m-bar-panel.m-container-max");}};l.init();K.init(); +`;let B=null;const F={get ajaxHooker(){return B==null&&(n.info("启用ajaxHooker拦截网络"),B=c.ajaxHooker(),B.protect()),B}},S={hookApply(){n.info("劫持Function.prototype.apply");let e=g.Function.prototype.apply;g.Function.prototype.apply=function(...t){var u,s;if(t.length!==2)return e.call(this,...t);if(t.length===2&&!Array.isArray(t[1]))return e.call(this,...t);if(typeof t[1][0]!="string")return e.call(this,...t);const o=t[1][0],i=(s=(u=t[1])==null?void 0:u[1])==null?void 0:s.params;if(o==="api/attitudes/create"&&l.getValue("weibo_apply_attitudes_create"))return n.success("拦截跳转登录"),new Promise(a=>{a({data:{}});});if(o==="api/likes/update"&&l.getValue("weibo_apply_likes_update"))return n.success("拦截点赞跳转登录"),new Promise(a=>{a({data:{}});});if(o==="api/comments/create"&&l.getValue("weibo_apply_comments_create"))return n.success("拦截评论跳转登录"),new Promise(a=>{a({data:{}});});if(o==="api/friendships/create"&&l.getValue("weibo_apply_friendships_create"))return n.success("拦截关注跳转登录"),new Promise(a=>{a({data:{}});});if(o==="api/comments/reply"&&l.getValue("weibo_apply_comments_reply"))return n.success("拦截回复跳转登录"),new Promise((a,r)=>{a({data:{ok:200}});});if(o.startsWith("profile/info")&&l.getValue("weibo_apply_profile_info")){n.success(["优化跳转xx微博主页",i]);let a=`https://weibo.com/${i.uid}`;return n.success("跳转微博主页:"+a),window.location.href=a,null}else if(o==="comments/hotflow"&&l.getValue("weibo_apply_comments_hotflow")){if(!("id"in i&&"max_id_type"in i&&"mid"in i)||"id"in i&&"max_id"in i&&"max_id_type"in i&&"mid"in i)return n.success(["拦截下拉加载更多评论跳转登录",i]),new Promise(a=>{a({ok:1,data:{data:[],total_number:0}});})}else if(o==="comments/hotFlowChild"&&l.getValue("weibo_apply_comments_hotFlowChild")){if("max_id"in i&&i.max_id!==0)return n.success(["拦截评论中的评论下拉加载更多评论跳转登录",i]),new Promise(a=>{a({data:{ok:1,data:[],rootComment:[],total_number:0}});})}else if(o==="api/statuses/repostTimeline"&&l.getValue("weibo_apply_statuses_repostTimeline"))return n.success(["拦截查看转发数据,因为需登录",i]),new Promise(a=>{a({data:{ok:1,data:{data:[],total_number:0}}});});return e.call(this,...t)};},hookNetWork(){F.ajaxHooker.hook(function(e){n.info(["ajaxHookr: ",e.url]),e.url.startsWith("https://m.weibo.cn/api/config")&&l.getValue("weibo_request_api_config")?e.response=function(t){let o=c.toJSON(t.responseText);o.data.preferQuickapp=0,o.data.login=!0,o.data.uid="",Reflect.deleteProperty(o.data,"loginUrl"),Reflect.deleteProperty(o.data,"wx_callback"),Reflect.deleteProperty(o.data,"wx_authorize"),Reflect.deleteProperty(o.data,"passport_login_url"),n.success("伪装已登录"),t.responseText=JSON.stringify(o);}:e.url.startsWith("https://m.weibo.cn/comments/hot")&&l.getValue("weibo_request_comments_hot")?e.response=function(t){let o=c.toJSON(t.responseText);o.ok!==1&&(n.error(["由于尚未登录,获取不到更多评论数据",o]),o={ok:1}),t.responseText=JSON.stringify(o);}:e.url.startsWith("https://m.weibo.cn/status/push?")&&l.getValue("weibo_request_status_push")&&(e.response=function(t){c.toJSON(t.responseText),t.json={};});});},hookWebpack(e="webpackJsonp",t,o){let i;Object.defineProperty(g,e,{get(){return i},set(u){n.success("成功劫持webpack,当前webpack名:"+e),i=u;const s=i.push;i.push=function(...a){let r=a[0][0];return (t==r||Array.isArray(t)&&Array.isArray(r)&&JSON.stringify(t)===JSON.stringify(r))&&Object.keys(a[0][1]).forEach(h=>{let p=a[0][1][h];a[0][1][h]=function(...f){let m=p.call(this,...f);return f[0]=o(f[0]),m};}),s.call(this,...a)};}});},hookVueRouter(){M.waitVuePropToSet("#app",[{msg:"等待获取属性 __vue__.$router",check(e){var t;return typeof((t=e==null?void 0:e.$router)==null?void 0:t.push)=="function"},set(e){n.success("拦截Vue路由跳转"),e.$router.beforeEach((t,o,i)=>{var u;if(t.name==="profile"&&l.getValue("weibo_router_profile_to_user_home")){let s=(u=t==null?void 0:t.params)==null?void 0:u.uid;if(s==null){n.error("获取uid失败"),y.error("获取uid失败");return}n.success(`修复跳转${s}微博主页`);let a=`https://m.weibo.cn/u/${s}`;window.location.href=a;return}i();}),e.$router.afterEach((t,o)=>{l.execMenu("weibo-listenRouterChange",()=>{n.info("路由更新,重载功能"),K.init();});});}}]);},hookServiceWorkerRegister(){n.info("hook => navigator.serviceWorker.register"),g.Object.defineProperty(g.navigator.serviceWorker,"register",{get(){return function(...e){n.success(["劫持navigator.serviceWorker.register: ",e]);}}});}},k={isMWeiBo(){return globalThis.location.hostname==="m.weibo.cn"},isMWeiBo_detail(){return this.isMWeiBo()&&globalThis.location.pathname.startsWith("/detail/")},isMWeiBo_u(){return this.isMWeiBo()&&globalThis.location.pathname.startsWith("/u/")},isMWeiBo_search(){return this.isMWeiBo()&&globalThis.location.pathname.startsWith("/search")},isHuaTi(){return globalThis.location.hostname==="huati.weibo.cn"},isVideo(){return globalThis.location.hostname==="h5.video.weibo.com"}},de={init(){l.execMenu("huati_weibo_masquerade_weibo_client_app",()=>{this.isWeibo();}),l.execMenuOnce("huati_weibo_get_more_celebrity_calendar_information",()=>{this.hookNetWorkWithGetMoreCelebrityCalendarInformation();});},isWeibo(){n.info("伪装微博"),M.waitVuePropToSet("#loadMore",[{msg:"等待设置属性 __vue__.isWeibo",check(e){return typeof e.isWeibo=="boolean"},set(e){e.isWeibo=!0,n.success("成功设置属性 __vue__.isWeibo=true");}}]);},hookNetWorkWithGetMoreCelebrityCalendarInformation(){F.ajaxHooker.hook(e=>{n.info(["ajaxHookr: ",e.url]),e.url.startsWith("/ajax/super/starschedule?")&&(e.response=async t=>{let o=await T.get(e.url,{headers:{Host:globalThis.location.hostname,Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest","sec-ch-ua-mobile":"?1","User-Agent":c.getRandomAndroidUA()+" Weibo (__weibo__)","sec-ch-ua-platform":"Android","Sec-Fetch-Site":"same-origin","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:globalThis.location.href,"Accept-Encoding":"gzip, deflate, br","Accept-Language":"zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"}});t.response=o.data.responseText,t.responseText=o.data.responseText;});});}},fe={init(){this.hookWebpack();},hookWebpack(){n.info("劫持webpack"),S.hookWebpack("webpackJsonp","chunk-common",e=>{if(typeof(e==null?void 0:e.exports)=="object"&&typeof e.exports.a=="object"&&typeof e.exports.a.gotoApp=="function"&&l.getValue("weibo_video_webpack_gotoApp"))return n.success(["成功劫持webpack调用函数",e]),e.exports.a.gotoApp=function(...t){n.info(["阻止唤醒App:",t]);},e});}},R={addBlockCSS(...e){let t=[];e.length!==0&&(e.length===1&&typeof e[0]=="string"&&e[0].trim()===""||(e.forEach(o=>{Array.isArray(o)?t=t.concat(o):t.push(o);}),N(`${t.join(`, +`)}{display: none !important;}`)));}},me={init(){l.onceExec("weibo-video-init-hook",()=>{fe.init();}),l.execMenuOnce("weibo_video_shield_bottom_toolbar",()=>{this.shieldBottomToolBar();}),l.execMenuOnce("weibo_video_shield_hot_comments",()=>{this.shieldHotComments();}),l.execMenuOnce("weibo_video_shield_recommend",()=>{this.shieldRecommend();});},shieldBottomToolBar(){n.info("【屏蔽】底部工具栏"),R.addBlockCSS(".woo-toolBar");},shieldRecommend(){n.info("【屏蔽】相关推荐"),R.addBlockCSS('#app .woo-panel[class*="Playdetail_card_"]:nth-child(2)');},shieldHotComments(){n.info("【屏蔽】热门评论"),R.addBlockCSS('#app .woo-panel[class*="Playdetail_card_"]:nth-child(3)');}},K={$data:{weiBoUnlockQuality:new re},init(){l.execMenuOnce("weibo_hijack_navigator_service_worker_register",()=>{S.hookServiceWorkerRegister();}),k.isHuaTi()?(n.info("Router: 话题"),de.init()):k.isMWeiBo()?(n.info("Router: 移动端微博"),l.onceExec("weibo-m-init",()=>{S.hookNetWork(),S.hookApply(),S.hookVueRouter();}),l.execMenuOnce("weibo_remove_ads",()=>{N(pe);}),l.execMenuOnce("weibo_shield_bottom_bar",()=>{this.shieldBottomBar();}),this.$data.weiBoUnlockQuality.lockVideoQuality(),oe.ready(()=>{l.execMenuOnce("weibo-common-unlockVideoHigherQuality",()=>{let e=new c.LockFunction(()=>{this.$data.weiBoUnlockQuality.unlockVideoHigherQuality();},15);c.mutationObserver(document.body,{config:{subtree:!0,childList:!0},immediate:!0,callback:()=>{e.run();}});});}),k.isMWeiBo_detail()?n.info("Router: 移动端微博帖子"):k.isMWeiBo_u()?n.info("Router: 移动端微博主页"):k.isMWeiBo_search()&&n.info("Router: 移动端微博搜索")):k.isVideo()?(n.info("Router: 视频页"),me.init()):n.error("Router: 未适配 => "+window.location.href);},shieldBottomBar(){n.info("【屏蔽】底部工具栏"),R.addBlockCSS("#app div.m-tab-bar.m-bar-panel.m-container-max");}};l.init();K.init(); })(Qmsg, DOMUtils, Utils); \ No newline at end of file diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.user.js" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.user.js" index 66f5c57f3..4acdbe19c 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.user.js" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 【移动端】微博优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.22 +// @version 2024.6.23 // @author WhiteSevs // @description 劫持自动跳转登录,修复用户主页正确跳转,伪装客户端,可查看名人堂日程表,自定义视频清晰度(可1080p、2K、2K-60、4K-60) // @license GPL-3.0-only @@ -13,7 +13,7 @@ // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js // @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.7/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @resource ElementPlusResourceCSS https://fastly.jsdelivr.net/npm/element-plus@2.7.2/dist/index.min.css // @connect m.weibo.cn @@ -56,7 +56,7 @@ get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: [ + cookieRule: [ { key: "httpx-cookie-weibo.com", hostname: /weibo.com/g @@ -89,18 +89,18 @@ }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data) { - if (data.fetch) { + handle(details) { + if (details.fetch) { return; } if (!this.$data.enable) { return; } let ownCookie = ""; - let url = data.url; + let url = details.url; if (url.startsWith("//")) { url = window.location.protocol + url; } @@ -110,9 +110,9 @@ )) { ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { - let cookie = PopsPanel.getValue(item.key); + this.$data.cookieRule.forEach((rule) => { + if (urlObj.hostname.match(rule.hostname)) { + let cookie = PopsPanel.getValue(rule.key); if (utils.isNull(cookie)) { return; } @@ -120,15 +120,18 @@ } }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } - if (data.headers && data.headers.Cookie != null && utils.isNull(data.headers.Cookie)) { - delete data.headers.Cookie; + if (details.headers && details.headers.Cookie != null && utils.isNull(details.headers.Cookie)) { + delete details.headers.Cookie; } } }; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/package.json" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/package.json" index 362fd38b2..290d372bd 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/package.json" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/package.json" @@ -15,7 +15,7 @@ }, "dependencies": { "@whitesev/domutils": "^1.1.2", - "@whitesev/utils": "^1.5.7", + "@whitesev/utils": "^1.5.8", "qmsg": "^1.1.2" }, "devDependencies": { diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index 8810b912b..19149b706 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\345\276\256\345\215\232\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,7 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: [ + cookieRule: [ { key: "httpx-cookie-weibo.com", hostname: /weibo.com/g, @@ -46,11 +53,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -61,7 +68,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -76,10 +83,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -88,22 +96,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/SCRIPT_VERSION.json" index 900f3ef94..e342091e5 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1718879490274, - "version": "2024.6.20.18" + "time": 1719111945591, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.min.user.js" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.min.user.js" index 36c19aca4..cdd3f0c4b 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.min.user.js" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 【移动端】百度系优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.20.18 +// @version 2024.6.23 // @author WhiteSevs // @description 用于【移动端】的百度系列产品优化,包括【百度搜索】、【百家号】、【百度贴吧】、【百度文库】、【百度经验】、【百度百科】、【百度知道】、【百度翻译】、【百度图片】、【百度地图】、【百度好看视频】、【百度爱企查】、【百度问题】、【百度识图】等 // @license GPL-3.0-only @@ -11,17 +11,17 @@ // @match *://www.tieba.com/* // @match *://uf9kyh.smartapps.cn/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://update.greasyfork.org/scripts/488179/1384528/showdown.js -// @require https://fastly.jsdelivr.net/npm/vue@3.4.29/dist/vue.global.prod.js +// @require https://fastly.jsdelivr.net/npm/vue@3.4.30/dist/vue.global.prod.js // @require https://fastly.jsdelivr.net/npm/vue-demi@0.14.8/lib/index.iife.min.js // @require https://fastly.jsdelivr.net/npm/pinia@2.1.7/dist/pinia.iife.prod.js -// @require https://fastly.jsdelivr.net/npm/vue-router@4.3.3/dist/vue-router.global.js +// @require https://fastly.jsdelivr.net/npm/vue-router@4.4.0/dist/vue-router.global.js // @require https://update.greasyfork.org/scripts/495227/1378053/Element-Plus.js // @require https://fastly.jsdelivr.net/npm/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.4/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.js // @resource ElementPlusResourceCSS https://fastly.jsdelivr.net/npm/element-plus@2.7.5/dist/index.min.css // @resource ViewerCSS https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.css @@ -394,7 +394,7 @@ match-attr##srcid##sp_purc_atom 复制代码 - `}),i=o.querySelector(".code-copy-text");b.on(i,"click",void 0,function(){try{p.setClip(a),Z.success("复制成功");}catch(l){Z.error("复制失败,"+l);}}),b.before(t,o);});},clearHistoryQuestion(){ie.question=[];let e=ie.dialogAlias.$shadowRoot.querySelector(".pops-alert-content");e.innerHTML="";},scrollToContentContainerEnd(){let e=ie.dialogAlias.popsElement.querySelector(".pops-alert-content");e.scrollTo(0,e.scrollHeight);}},hn=function(e,t,r,n,a,o){let i=[];typeof n=="function"?i=n():i=n;let l={text:e,type:"select",description:o,attributes:{},getValue(){return x.getValue(t,r)},callback(c,u,d){x.setValue(t,u),typeof a=="function"&&a(c,u,d);},data:i};return l.attributes&&(l.attributes[Ht]=t,l.attributes[Ft]=r),l},pi=function(e,t,r,n,a,o="",i){let l={text:e,type:"textarea",attributes:{},description:n,placeholder:o,disabled:i,getValue(){return x.getValue(t,r)},callback(c,u){x.setValue(t,u);}};return l.attributes&&(l.attributes[Ht]=t,l.attributes[Ft]=r),l},fi={id:"baidu-panel-config-common",title:"通用",forms:[{text:"Toast配置",type:"forms",forms:[hn("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(e,t,r)=>{s.info("设置当前Qmsg弹出位置"+r);},"Toast显示在页面九宫格的位置"),hn("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),$("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[$("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),$("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来获取对应的cookie"),pi("tieba.baidu.com","httpx-cookie-tieba.baidu.com","",void 0,void 0,"Cookie格式:xxx=xxxx;xxx=xxxx")]}]},Ue={data:null,oneSuccessExecMenu:null,onceExec:null,listenData:null},x={$data:{get data(){return Ue.data==null&&(Ue.data=new p.Dictionary),Ue.data},get oneSuccessExecMenu(){return Ue.oneSuccessExecMenu==null&&(Ue.oneSuccessExecMenu=new p.Dictionary),Ue.oneSuccessExecMenu},get onceExec(){return Ue.onceExec==null&&(Ue.onceExec=new p.Dictionary),Ue.onceExec},get scriptName(){return vn},key:gt,attributeKeyName:Ht,attributeDefaultValueName:Ft},$listener:{get listenData(){return Ue.listenData==null&&(Ue.listenData=new p.Dictionary),Ue.listenData}},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){Q.top===Q.self&&Rr.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}},{key:"show_yiyan_chatgpt",text:"⚙ 文心一言",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{ie.init();}}]);},initPanelDefaultValue(){let e=this;function t(n){if(!n.attributes)return;let a=n.attributes[Ht],o=n.attributes[Ft];if(a==null){s.warn(["请先配置键",n]);return}e.$data.data.has(a)&&s.warn("请检查该key(已存在): "+a),e.$data.data.set(a,o);}let r=this.getPanelContentConfig();for(let n=0;n450?"80dvh":"450px"},getPanelContentConfig(){return [fi,jo,Wo,Go,Ko,Yo,Zo,Qo,Xo,ei,ti,ri,ni,ai,oi,ii,si,li,ci,ui,di]}},mi={$data:{get enable(){return x.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return x.getValue("httpx-use-document-cookie")},cookieList:[{key:"httpx-cookie-tieba.baidu.com",hostname:/(tieba.baidu|www.tieba|ala.baidu|static.tieba.baidu|nba.baidu).com/g}]},fixCookieSplit(e){return p.isNotNull(e)&&!e.trim().endsWith(";")&&(e+=";"),e},concatCookie(e,t){return p.isNull(e)?t:(e=e.trim(),t=t.trim(),e=this.fixCookieSplit(e),t.startsWith(";")&&(t=t.substring(1)),e.concat(t))},handle(e){if(e.fetch||!this.$data.enable)return;let t="",r=e.url;r.startsWith("//")&&(r=window.location.protocol+r);let n=new URL(r);this.$data.useDocumentCookie&&n.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(t=this.concatCookie(t,document.cookie.trim())),this.$data.cookieList.forEach(a=>{if(a.hostname.test(n.hostname)){let o=x.getValue(a.key);if(p.isNull(o))return;t=this.concatCookie(t,o);}}),p.isNotNull(t)&&(e.headers&&e.headers.Cookie?e.headers.Cookie=this.concatCookie(e.headers.Cookie,t):e.headers.Cookie=t,s.info(["Httpx => 设置cookie:",e])),e.headers&&e.headers.Cookie!=null&&p.isNull(e.headers.Cookie)&&delete e.headers.Cookie;}},hi="【移动端】百度系优化",p=wt.noConflict(),b=Mr.noConflict(),dt=jr.pops||Q.pops,gn=jr.showdown||Q.showdown,s=new wt.Log(Xt,Q.console||jr.console);var Qn;const vn=((Qn=Xt==null?void 0:Xt.script)==null?void 0:Qn.name)||hi,ue=new Wr(!0),oa=!1;s.config({debug:oa,logMaxCount:2e4,autoClearConsole:!0,tag:!0});Z.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return x.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return x.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return x.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let e=wt.getMaxZIndex(10),t=dt.config.Utils.getPopsMaxZIndex(10).zIndex;return wt.getMaxValue(e,t)}}}));const Rr=new wt.GM_Menu({GM_getValue:Mt,GM_setValue:Nr,GM_registerMenuCommand:Ho,GM_unregisterMenuCommand:Fo}),he=new wt.Httpx(Vo);he.interceptors.request.use(e=>(mi.handle(e),e));he.interceptors.response.use(void 0,e=>(s.error(["拦截器-请求错误",e]),e.type==="onabort"?Z.warning("请求取消"):e.type==="onerror"?Z.error("请求异常"):e.type==="ontimeout"?Z.error("请求超时"):Z.error("其它错误"),e));he.config({logDetails:oa});const je={Object:{defineProperty:Q.Object.defineProperty},Function:{apply:Q.Function.prototype.apply,call:Q.Function.prototype.call},Element:{appendChild:Q.Element.prototype.appendChild},setTimeout:Q.setTimeout},J=wt.addStyle,er="vite-app",ia=async function(e,t=[]){Mr.ready(async()=>{const r=vue.createApp(e);let n=Mr.createElement("div",{id:er});if(ElementPlusIconsVue!=null)for(const[a,o]of Object.entries(ElementPlusIconsVue))r.component(a,o);document.body.appendChild(n),t.forEach(a=>{r.use(a);}),r.mount(n);}),J(aa("ElementPlusResourceCSS"));},gi=`.c-container.na-ec-item,\r + `}),i=o.querySelector(".code-copy-text");b.on(i,"click",void 0,function(){try{p.setClip(a),Z.success("复制成功");}catch(l){Z.error("复制失败,"+l);}}),b.before(t,o);});},clearHistoryQuestion(){ie.question=[];let e=ie.dialogAlias.$shadowRoot.querySelector(".pops-alert-content");e.innerHTML="";},scrollToContentContainerEnd(){let e=ie.dialogAlias.popsElement.querySelector(".pops-alert-content");e.scrollTo(0,e.scrollHeight);}},hn=function(e,t,r,n,a,o){let i=[];typeof n=="function"?i=n():i=n;let l={text:e,type:"select",description:o,attributes:{},getValue(){return x.getValue(t,r)},callback(c,u,d){x.setValue(t,u),typeof a=="function"&&a(c,u,d);},data:i};return l.attributes&&(l.attributes[Ht]=t,l.attributes[Ft]=r),l},pi=function(e,t,r,n,a,o="",i){let l={text:e,type:"textarea",attributes:{},description:n,placeholder:o,disabled:i,getValue(){return x.getValue(t,r)},callback(c,u){x.setValue(t,u);}};return l.attributes&&(l.attributes[Ht]=t,l.attributes[Ft]=r),l},fi={id:"baidu-panel-config-common",title:"通用",forms:[{text:"Toast配置",type:"forms",forms:[hn("Toast位置","qmsg-config-position","bottom",[{value:"topleft",text:"左上角"},{value:"top",text:"顶部"},{value:"topright",text:"右上角"},{value:"left",text:"左边"},{value:"center",text:"中间"},{value:"right",text:"右边"},{value:"bottomleft",text:"左下角"},{value:"bottom",text:"底部"},{value:"bottomright",text:"右下角"}],(e,t,r)=>{s.info("设置当前Qmsg弹出位置"+r);},"Toast显示在页面九宫格的位置"),hn("最多显示的数量","qmsg-config-maxnums",3,[{value:1,text:"1"},{value:2,text:"2"},{value:3,text:"3"},{value:4,text:"4"},{value:5,text:"5"}],void 0,"限制Toast显示的数量"),$("逆序弹出","qmsg-config-showreverse",!1,void 0,"修改Toast弹出的顺序")]},{text:"Cookie配置",type:"forms",forms:[$("启用","httpx-use-cookie-enable",!1,void 0,"启用后,将根据下面的配置进行添加cookie"),$("使用document.cookie","httpx-use-document-cookie",!1,void 0,"自动根据请求的域名来获取对应的cookie"),pi("tieba.baidu.com","httpx-cookie-tieba.baidu.com","",void 0,void 0,"Cookie格式:xxx=xxxx;xxx=xxxx")]}]},Ue={data:null,oneSuccessExecMenu:null,onceExec:null,listenData:null},x={$data:{get data(){return Ue.data==null&&(Ue.data=new p.Dictionary),Ue.data},get oneSuccessExecMenu(){return Ue.oneSuccessExecMenu==null&&(Ue.oneSuccessExecMenu=new p.Dictionary),Ue.oneSuccessExecMenu},get onceExec(){return Ue.onceExec==null&&(Ue.onceExec=new p.Dictionary),Ue.onceExec},get scriptName(){return vn},key:gt,attributeKeyName:Ht,attributeDefaultValueName:Ft},$listener:{get listenData(){return Ue.listenData==null&&(Ue.listenData=new p.Dictionary),Ue.listenData}},init(){this.initPanelDefaultValue(),this.initExtensionsMenu();},initExtensionsMenu(){Q.top===Q.self&&Rr.add([{key:"show_pops_panel_setting",text:"⚙ 设置",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{this.showPanel();}},{key:"show_yiyan_chatgpt",text:"⚙ 文心一言",autoReload:!1,isStoreValue:!1,showText(e){return e},callback:()=>{ie.init();}}]);},initPanelDefaultValue(){let e=this;function t(n){if(!n.attributes)return;let a=n.attributes[Ht],o=n.attributes[Ft];if(a==null){s.warn(["请先配置键",n]);return}e.$data.data.has(a)&&s.warn("请检查该key(已存在): "+a),e.$data.data.set(a,o);}let r=this.getPanelContentConfig();for(let n=0;n450?"80dvh":"450px"},getPanelContentConfig(){return [fi,jo,Wo,Go,Ko,Yo,Zo,Qo,Xo,ei,ti,ri,ni,ai,oi,ii,si,li,ci,ui,di]}},mi={$data:{get enable(){return x.getValue("httpx-use-cookie-enable")},get useDocumentCookie(){return x.getValue("httpx-use-document-cookie")},cookieRule:[{key:"httpx-cookie-tieba.baidu.com",hostname:/(tieba.baidu|www.tieba|ala.baidu|static.tieba.baidu|nba.baidu).com/g}]},fixCookieSplit(e){return p.isNotNull(e)&&!e.trim().endsWith(";")&&(e+=";"),e},concatCookie(e,t){return p.isNull(e)?t:(e=e.trim(),t=t.trim(),e=this.fixCookieSplit(e),t.startsWith(";")&&(t=t.substring(1)),e.concat(t))},handle(e){if(e.fetch||!this.$data.enable)return;let t="",r=e.url;r.startsWith("//")&&(r=window.location.protocol+r);let n=new URL(r);this.$data.useDocumentCookie&&n.hostname.endsWith(window.location.hostname.split(".").slice(-2).join("."))&&(t=this.concatCookie(t,document.cookie.trim())),this.$data.cookieRule.forEach(a=>{if(n.hostname.match(a.hostname)){let o=x.getValue(a.key);if(p.isNull(o))return;t=this.concatCookie(t,o);}}),p.isNotNull(t)&&(e.headers&&e.headers.Cookie?e.headers.Cookie=this.concatCookie(e.headers.Cookie,t):e.headers.Cookie=t,s.info(["Httpx => 设置cookie:",e])),e.headers&&e.headers.Cookie!=null&&p.isNull(e.headers.Cookie)&&delete e.headers.Cookie;}},hi="【移动端】百度系优化",p=wt.noConflict(),b=Mr.noConflict(),dt=jr.pops||Q.pops,gn=jr.showdown||Q.showdown,s=new wt.Log(Xt,Q.console||jr.console);var Qn;const vn=((Qn=Xt==null?void 0:Xt.script)==null?void 0:Qn.name)||hi,ue=new Wr(!0),oa=!1;s.config({debug:oa,logMaxCount:2e4,autoClearConsole:!0,tag:!0});Z.config(Object.defineProperties({html:!0,autoClose:!0,showClose:!1},{position:{get(){return x.getValue("qmsg-config-position","bottom")}},maxNums:{get(){return x.getValue("qmsg-config-maxnums",5)}},showReverse:{get(){return x.getValue("qmsg-config-showreverse",!0)}},zIndex:{get(){let e=wt.getMaxZIndex(10),t=dt.config.Utils.getPopsMaxZIndex(10).zIndex;return wt.getMaxValue(e,t)}}}));const Rr=new wt.GM_Menu({GM_getValue:Mt,GM_setValue:Nr,GM_registerMenuCommand:Ho,GM_unregisterMenuCommand:Fo}),he=new wt.Httpx(Vo);he.interceptors.request.use(e=>(mi.handle(e),e));he.interceptors.response.use(void 0,e=>(s.error(["拦截器-请求错误",e]),e.type==="onabort"?Z.warning("请求取消"):e.type==="onerror"?Z.error("请求异常"):e.type==="ontimeout"?Z.error("请求超时"):Z.error("其它错误"),e));he.config({logDetails:oa});const je={Object:{defineProperty:Q.Object.defineProperty},Function:{apply:Q.Function.prototype.apply,call:Q.Function.prototype.call},Element:{appendChild:Q.Element.prototype.appendChild},setTimeout:Q.setTimeout},J=wt.addStyle,er="vite-app",ia=async function(e,t=[]){Mr.ready(async()=>{const r=vue.createApp(e);let n=Mr.createElement("div",{id:er});if(ElementPlusIconsVue!=null)for(const[a,o]of Object.entries(ElementPlusIconsVue))r.component(a,o);document.body.appendChild(n),t.forEach(a=>{r.use(a);}),r.mount(n);}),J(aa("ElementPlusResourceCSS"));},gi=`.c-container.na-ec-item,\r .c-container.ec-container,\r div[data-type="ad"],\r .c-result.sfc-log[data-tpl="adv_wenku_fc"],\r diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.user.js" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.user.js" index 7ab4096e0..319858a6f 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.user.js" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/dist/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 【移动端】百度系优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.20.18 +// @version 2024.6.23 // @author WhiteSevs // @description 用于【移动端】的百度系列产品优化,包括【百度搜索】、【百家号】、【百度贴吧】、【百度文库】、【百度经验】、【百度百科】、【百度知道】、【百度翻译】、【百度图片】、【百度地图】、【百度好看视频】、【百度爱企查】、【百度问题】、【百度识图】等 // @license GPL-3.0-only @@ -11,17 +11,17 @@ // @match *://www.tieba.com/* // @match *://uf9kyh.smartapps.cn/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://update.greasyfork.org/scripts/488179/1384528/showdown.js -// @require https://fastly.jsdelivr.net/npm/vue@3.4.29/dist/vue.global.prod.js +// @require https://fastly.jsdelivr.net/npm/vue@3.4.30/dist/vue.global.prod.js // @require https://fastly.jsdelivr.net/npm/vue-demi@0.14.8/lib/index.iife.min.js // @require https://fastly.jsdelivr.net/npm/pinia@2.1.7/dist/pinia.iife.prod.js -// @require https://fastly.jsdelivr.net/npm/vue-router@4.3.3/dist/vue-router.global.js +// @require https://fastly.jsdelivr.net/npm/vue-router@4.4.0/dist/vue-router.global.js // @require https://update.greasyfork.org/scripts/495227/1378053/Element-Plus.js // @require https://fastly.jsdelivr.net/npm/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.4/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.js // @resource ElementPlusResourceCSS https://fastly.jsdelivr.net/npm/element-plus@2.7.5/dist/index.min.css // @resource ViewerCSS https://fastly.jsdelivr.net/npm/viewerjs@1.11.6/dist/viewer.min.css @@ -3787,7 +3787,7 @@ match-attr##srcid##sp_purc_atom get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: [ + cookieRule: [ { key: "httpx-cookie-tieba.baidu.com", hostname: /(tieba.baidu|www.tieba|ala.baidu|static.tieba.baidu|nba.baidu).com/g @@ -3820,18 +3820,18 @@ match-attr##srcid##sp_purc_atom }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data) { - if (data.fetch) { + handle(details) { + if (details.fetch) { return; } if (!this.$data.enable) { return; } let ownCookie = ""; - let url = data.url; + let url = details.url; if (url.startsWith("//")) { url = window.location.protocol + url; } @@ -3841,9 +3841,9 @@ match-attr##srcid##sp_purc_atom )) { ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { - let cookie = PopsPanel.getValue(item.key); + this.$data.cookieRule.forEach((rule) => { + if (urlObj.hostname.match(rule.hostname)) { + let cookie = PopsPanel.getValue(rule.key); if (utils.isNull(cookie)) { return; } @@ -3851,15 +3851,18 @@ match-attr##srcid##sp_purc_atom } }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } - if (data.headers && data.headers.Cookie != null && utils.isNull(data.headers.Cookie)) { - delete data.headers.Cookie; + if (details.headers && details.headers.Cookie != null && utils.isNull(details.headers.Cookie)) { + delete details.headers.Cookie; } } }; diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/package.json" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/package.json" index 8814ef590..777d8c7c8 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/package.json" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/package.json" @@ -15,26 +15,26 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.3.1", - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.4", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "pinia": "^2.1.7", "qmsg": "^1.1.2", "viewerjs": "^1.11.6", - "vue": "^3.4.29", + "vue": "^3.4.30", "vue-demi": "^0.14.8", - "vue-router": "^4.3.3" + "vue-router": "^4.4.0" }, "devDependencies": { - "@types/node": "^20.14.6", + "@types/node": "^20.14.8", "@vitejs/plugin-vue": "^5.0.5", - "element-plus": "^2.7.5", - "typescript": "^5.4.5", + "element-plus": "^2.7.6", + "typescript": "^5.5.2", "unplugin-auto-import": "^0.17.6", "unplugin-element-plus": "^0.8.0", "unplugin-icons": "^0.19.0", "unplugin-vue-components": "^0.27.0", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3", - "vue-tsc": "^2.0.21" + "vue-tsc": "^2.0.22" } } diff --git "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index 60bae77f2..37265e6be 100644 --- "a/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/\343\200\220\347\247\273\345\212\250\347\253\257\343\200\221\347\231\276\345\272\246\347\263\273\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,7 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: [ + cookieRule: [ { key: "httpx-cookie-tieba.baidu.com", hostname: @@ -47,11 +54,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -62,7 +69,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -77,10 +84,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -89,22 +97,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" index 909b0492c..636d3d347 100644 --- "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1718794304046, - "version": "2024.6.19" + "time": 1719112354183, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.min.user.js" "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.min.user.js" index 080b95d86..cf6e69407 100644 --- "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.min.user.js" +++ "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 小红书优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 屏蔽登录弹窗、屏蔽广告、优化评论浏览、优化图片浏览、允许复制、禁止唤醒App、禁止唤醒弹窗、修复正确跳转等 // @license GPL-3.0-only @@ -10,10 +10,10 @@ // @match *://www.xiaohongshu.com/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js // @require https://update.greasyfork.org/scripts/449471/1360565/Viewer.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @connect edith.xiaohongshu.com // @grant GM_addStyle // @grant GM_deleteValue diff --git "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.user.js" "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.user.js" index a0e533743..b96feec9d 100644 --- "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.user.js" +++ "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/dist/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 小红书优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 屏蔽登录弹窗、屏蔽广告、优化评论浏览、优化图片浏览、允许复制、禁止唤醒App、禁止唤醒弹窗、修复正确跳转等 // @license GPL-3.0-only @@ -10,10 +10,10 @@ // @match *://www.xiaohongshu.com/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js // @require https://update.greasyfork.org/scripts/449471/1360565/Viewer.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @connect edith.xiaohongshu.com // @grant GM_addStyle // @grant GM_deleteValue diff --git "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/package.json" "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/package.json" index db3c14628..8a7a65157 100644 --- "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/package.json" +++ "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/package.json" @@ -15,24 +15,24 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.3.1", - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "qmsg": "^1.1.2", "viewerjs": "^1.11.6", - "vue": "^3.4.29", - "vue-router": "^4.3.3" + "vue": "^3.4.30", + "vue-router": "^4.4.0" }, "devDependencies": { - "@types/node": "^20.14.5", + "@types/node": "^20.14.8", "@vitejs/plugin-vue": "^5.0.5", - "element-plus": "^2.7.5", - "typescript": "^5.4.5", + "element-plus": "^2.7.6", + "typescript": "^5.5.2", "unplugin-auto-import": "^0.17.6", "unplugin-element-plus": "^0.8.0", "unplugin-icons": "^0.19.0", "unplugin-vue-components": "^0.27.0", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3", - "vue-tsc": "^2.0.21" + "vue-tsc": "^2.0.22" } } diff --git "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index fe5cd5641..2f6a2981e 100644 --- "a/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/\345\260\217\347\272\242\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/SCRIPT_VERSION.json" index df1593c80..284da8de2 100644 --- "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1719035084332, - "version": "2024.6.22" + "time": 1719112204961, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.min.user.js" "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.min.user.js" index 079fc3b34..28dec4d44 100644 --- "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.min.user.js" +++ "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 抖音优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.22 +// @version 2024.6.23 // @author WhiteSevs // @description 过滤广告、过滤直播、可自定义过滤视频的屏蔽关键字、伪装登录、直播屏蔽弹幕、礼物特效等 // @license GPL-3.0-only @@ -9,9 +9,9 @@ // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://*.douyin.com/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.4/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @grant GM_addStyle // @grant GM_deleteValue diff --git "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.user.js" "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.user.js" index 779c4cd77..3964ff69b 100644 --- "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.user.js" +++ "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/dist/\346\212\226\351\237\263\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 抖音优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.22 +// @version 2024.6.23 // @author WhiteSevs // @description 过滤广告、过滤直播、可自定义过滤视频的屏蔽关键字、伪装登录、直播屏蔽弹幕、礼物特效等 // @license GPL-3.0-only @@ -9,9 +9,9 @@ // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://*.douyin.com/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.4/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @grant GM_addStyle // @grant GM_deleteValue diff --git "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/package.json" "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/package.json" index bf7468941..7f072c9ce 100644 --- "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/package.json" +++ "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/package.json" @@ -17,16 +17,16 @@ }, "dependencies": { "@whitesev/domutils": "^1.1.2", - "@whitesev/utils": "^1.5.4", + "@whitesev/utils": "^1.5.8", "qmsg": "^1.1.2", - "vue": "^3.4.29" + "vue": "^3.4.30" }, "devDependencies": { - "@types/node": "^20.14.7", + "@types/node": "^20.14.8", "@vitejs/plugin-vue": "^5.0.5", "typescript": "^5.5.2", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3", - "vue-tsc": "^2.0.21" + "vue-tsc": "^2.0.22" } } diff --git "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index fe5cd5641..2f6a2981e 100644 --- "a/packages/\346\212\226\351\237\263\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/\346\212\226\351\237\263\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, }; diff --git "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" index d67a43d80..f8656b6f5 100644 --- "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" +++ "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/SCRIPT_VERSION.json" @@ -1,4 +1,4 @@ { - "time": 1718793789342, - "version": "2024.6.19" + "time": 1719112280479, + "version": "2024.6.23" } \ No newline at end of file diff --git "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.min.user.js" "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.min.user.js" index d7194b6db..3b957bd09 100644 --- "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.min.user.js" +++ "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.min.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 简书优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转拦截的URL // @license GPL-3.0-only @@ -10,10 +10,10 @@ // @match *://*.jianshu.com/* // @match *://*.jianshu.io/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @grant GM_addStyle // @grant GM_deleteValue // @grant GM_getResourceText diff --git "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.user.js" "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.user.js" index dd8b52801..d90112725 100644 --- "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.user.js" +++ "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/dist/\347\256\200\344\271\246\344\274\230\345\214\226.user.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 简书优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript -// @version 2024.6.19 +// @version 2024.6.23 // @author WhiteSevs // @description 支持手机端和PC端,屏蔽广告,优化浏览体验,自动跳转拦截的URL // @license GPL-3.0-only @@ -10,10 +10,10 @@ // @match *://*.jianshu.com/* // @match *://*.jianshu.io/* // @require https://update.greasyfork.org/scripts/494167/1376186/CoverUMD.js -// @require https://update.greasyfork.org/scripts/456485/1396237/pops.js +// @require https://update.greasyfork.org/scripts/456485/1398647/pops.js // @require https://fastly.jsdelivr.net/npm/qmsg@1.1.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.2/dist/index.umd.js -// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.1/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/utils@1.5.8/dist/index.umd.js +// @require https://fastly.jsdelivr.net/npm/@whitesev/domutils@1.1.2/dist/index.umd.js // @grant GM_addStyle // @grant GM_deleteValue // @grant GM_getResourceText diff --git "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/package.json" "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/package.json" index ab17d3d0b..58a23af79 100644 --- "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/package.json" +++ "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/package.json" @@ -14,13 +14,13 @@ "clear": "del .\\SCRIPT_VERSION.json && pnpm store prune" }, "dependencies": { - "@whitesev/domutils": "^1.1.1", - "@whitesev/utils": "^1.5.2", + "@whitesev/domutils": "^1.1.2", + "@whitesev/utils": "^1.5.8", "qmsg": "^1.1.2" }, "devDependencies": { - "@types/node": "^20.14.5", - "typescript": "^5.4.5", + "@types/node": "^20.14.8", + "typescript": "^5.5.2", "vite": "^5.3.1", "vite-plugin-monkey": "4.0.3" } diff --git "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" index fe5cd5641..2f6a2981e 100644 --- "a/packages/\347\256\200\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" +++ "b/packages/\347\256\200\344\271\246\344\274\230\345\214\226/src/utils/HttpxCookieManager.ts" @@ -2,6 +2,13 @@ import { log, utils } from "@/env"; import { PopsPanel } from "@/setting/setting"; import type { HttpxDetails } from "@whitesev/utils/dist/src/Httpx"; +interface HttpxCookieManagerRule { + /** PopsPanel存储的键名 */ + key: string; + /** 匹配url的hostname的正则或字符串 */ + hostname: RegExp | string; +} + export const HttpxCookieManager = { $data: { /** 是否启用 */ @@ -12,14 +19,7 @@ export const HttpxCookieManager = { get useDocumentCookie() { return PopsPanel.getValue("httpx-use-document-cookie"); }, - cookieList: < - { - /** PopsPanel的键名 */ - key: string; - /** 域名匹配规则 */ - hostname: RegExp; - }[] - >[], + cookieRule: [], }, /** * 补充cookie末尾分号 @@ -48,11 +48,11 @@ export const HttpxCookieManager = { }, /** * 处理cookie - * @param data + * @param details * @returns */ - handle(data: Required) { - if (data.fetch) { + handle(details: Required) { + if (details.fetch) { // fetch不做处理 return; } @@ -63,7 +63,7 @@ export const HttpxCookieManager = { } let ownCookie = ""; - let url = data.url; + let url = details.url; // 完善Url if (url.startsWith("//")) { url = window.location.protocol + url; @@ -78,11 +78,11 @@ export const HttpxCookieManager = { // 通过document.cookie获取添加 ownCookie = this.concatCookie(ownCookie, document.cookie.trim()); } - - this.$data.cookieList.forEach((item) => { - if (item.hostname.test(urlObj.hostname)) { + this.$data.cookieRule.forEach((rule) => { + // 正则不要使用test匹配 + if (urlObj.hostname.match(rule.hostname)) { // 域名匹配成功 - let cookie = PopsPanel.getValue(item.key) as string; + let cookie = PopsPanel.getValue(rule.key) as string; if (utils.isNull(cookie)) { return; } @@ -91,22 +91,25 @@ export const HttpxCookieManager = { }); if (utils.isNotNull(ownCookie)) { - if (data.headers && data.headers["Cookie"]) { - data.headers.Cookie = this.concatCookie(data.headers.Cookie, ownCookie); + if (details.headers && details.headers["Cookie"]) { + details.headers.Cookie = this.concatCookie( + details.headers.Cookie, + ownCookie + ); } else { - data.headers["Cookie"] = ownCookie; + details.headers["Cookie"] = ownCookie; } - log.info(["Httpx => 设置cookie:", data]); + log.info(["Httpx => 设置cookie:", details]); } if ( - data.headers && - data.headers.Cookie != null && - utils.isNull(data.headers.Cookie) + details.headers && + details.headers.Cookie != null && + utils.isNull(details.headers.Cookie) ) { // 有cookie,但是cookie是空的 // 删除该设置 - delete data.headers.Cookie; + delete details.headers.Cookie; } }, };