您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
支持手机端和PC端、屏蔽广告、优化浏览体验、重定向链接、全文居中、自动展开全文、允许复制文字、劫持唤醒/跳转App、自定义屏蔽元素等
当前为
// ==UserScript== // @name 简书优化 // @namespace https://github.com/WhiteSevs/TamperMonkeyScript // @version 2025.9.14 // @author WhiteSevs // @description 支持手机端和PC端、屏蔽广告、优化浏览体验、重定向链接、全文居中、自动展开全文、允许复制文字、劫持唤醒/跳转App、自定义屏蔽元素等 // @license GPL-3.0-only // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAEK1JREFUeF7tXQt0VMUZ/ububgIJjwDJDWqpj6L4LEJbpT0C1r7UFmu1WLJBq7XUHjXZDWDVUytgpYq2ujdUW/FxrMfcCFSPrdTa1laqbVGhalF8AfVZQjbkAQSSze7eKbMQIHt378y9e/eVzJyTg+795///+ea78/937twZAlmGNAJkSLdeNh6SAEOcBJIAkgD5RYAuXqxsaX/JN7K00lsa8/g8nog3Evf4okbE5/H4vIqh+BQl7o1T4iPE8BqJfz3eOI158uv5QOseg8QMqsQ8hEbZv17QqOGLxQzqiXmJETUMbyzqiUcj8dLYcG88ujuyIzZx3JlRsnixkc925GQEoLNne1qqPVN8XmWSYeB4ABMVQiYaoMcTYGw+Aci3bQp0KCCbDUq3KMBmKNjSh/hbR4VWvpIL37JCgLbg3KkGjU8jlEwhCk6nFFMAFNQdmwtwM7FBQSMEWEcI2WAY2KgoyrNVoUdbMtGZqq6r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wNqmkkV4Yu3cO+GMnqMY+fj93Hc8sEYTVkF6dymja7XLDAf97AI7JhqeMALySi4MUeT4MmuuU/lZtbE6Z01kR4AEAVw4aEIZyQyitVxubl9sdAVjnMxLIUuQIUCN+evXylf+xRYC24NwjQI0NFDiyyNs/pN0nBE9VhfQL0oFguWV+a71/MSFYNKQRLPLGE5BZVVrTGkcEkKNAcfc+7+7f/4DAKXIU4CFUuNd5d78QAeQoULgdbOWZyN0vRAAmFA74rwWQ8jGiOOEZ9F73KCAzK7Wm9byWckNAv4LWev+jhKCWp1BeLwgELlE1fbWIJ8IEODASZHWdgIjDUoaDAKE3qaHmpaI42SJAS93sKo/iC4sql3K5RoC+oWrNpqXflrmCXRd3BOacaUB50W49KZ9lBCxe+LhKAKZsZ8PssRHq/RsomZzlZkn1Ygg8p2o6f+lxCl22QkBy/dZAzQoCYlpnJuazlHIFAUKWq6Emtn7DUcmIAAcSQ5ZwXAfA58gDWckRAoTgI1C6tEprvs+RggOVMiYA09NSV3uyR8GlAGUf1cuXR5n0CK8uxatEoY+UkNgjo+9e3cET5113hQD9RthTgtfjvZQCl8n8gAe9zesUfyYKHqkK6U02a1qKu0qAwy2FA/4ZAGZQipkgmEGAEjcdHwK6WgD8CcA/PAZZN255k/NDDyzAyhoBkm22BOec7TWU8VDIeMMwjiCEjAfBeFCUAWD71/lAqJdQ4qWU/feB3w5cI4CX7s8z9ssCSoGRIA4gCiBGgKgBGiMgUXrg/9nvAIki8TsO/k6BXaDYDoLtFLQFhGwHpVuqteaNuWhfzgiQi8ZIG/YRkASwj9mgqiEJMKi6035jJAHsYzaoakgCDKrutN+Y/wNhP/X5lGDapQAAAABJRU5ErkJggg== // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @match *://*.jianshu.com/* // @match *://*.jianshu.io/* // @require https://fastly.jsdelivr.net/gh/WhiteSevs/TamperMonkeyScript@86be74b83fca4fa47521cded28377b35e1d7d2ac/lib/CoverUMD/index.js // @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected]/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected]/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/@whitesev/[email protected]/dist/index.umd.js // @require https://fastly.jsdelivr.net/npm/[email protected]/dist/index.umd.js // @connect * // @grant GM_deleteValue // @grant GM_getResourceText // @grant GM_getValue // @grant GM_info // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_unregisterMenuCommand // @grant GM_xmlhttpRequest // @grant unsafeWindow // @run-at document-start // ==/UserScript== (function (Qmsg, DOMUtils, Utils, pops) { 'use strict'; const blockCSS = `.download-app-guidance,\r .call-app-btn,\r .collapse-tips,\r .note-graceful-button,\r .app-open,\r .header-wrap,\r .recommend-wrap.recommend-ad,\r .call-app-Ad-bottom,\r #recommended-notes p.top-title span.more,\r #homepage .modal,\r button.index_call-app-btn,\r span.note__flow__download,\r .download-guide,\r #footer,\r .comment-open-app-btn-wrap,\r .nav.navbar-nav + div,\r .self-flow-ad,\r #free-reward-panel,\r div[id*='AdFive'],\r #index-aside-download-qrbox,\r .baidu-app-download-2eIkf_1,\r /* 底部的"小礼物走一走,来简书关注我"、赞赏支持和更多精彩内容,就在简书APP */\r div[role="main"] > div > section:first-child > div:nth-last-child(2),\r /* 它的内部是script标签,可能影响部分评论之间的高度问题 */\r div.adad_container ,\r /* 顶部导航栏的【下载App】 */\r #__next nav a[href*="navbar-app"] {\r display: none !important;\r }\r body.reader-day-mode.normal-size {\r overflow: auto !important;\r }\r .collapse-free-content {\r height: auto !important;\r }\r .copyright {\r color: #000 !important;\r }\r #note-show .content .show-content-free .collapse-free-content:after {\r background-image: none !important;\r }\r footer > div > div {\r justify-content: center;\r }\r /* 修复底部最后编辑于:。。。在某些套壳浏览器上的错位问题 */\r #note-show .content .show-content-free .note-meta-time {\r margin-top: 0px !important;\r }\r `; var _GM_deleteValue = (() => typeof GM_deleteValue != "undefined" ? GM_deleteValue : void 0)(); var _GM_getResourceText = (() => typeof GM_getResourceText != "undefined" ? GM_getResourceText : void 0)(); var _GM_getValue = (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)(); var _GM_info = (() => typeof GM_info != "undefined" ? GM_info : void 0)(); var _GM_registerMenuCommand = (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)(); var _GM_setValue = (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)(); var _GM_unregisterMenuCommand = (() => typeof GM_unregisterMenuCommand != "undefined" ? GM_unregisterMenuCommand : void 0)(); var _GM_xmlhttpRequest = (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)(); var _unsafeWindow = (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)(); var _monkeyWindow = (() => window)(); const KEY = "GM_Panel"; const ATTRIBUTE_INIT = "data-init"; const ATTRIBUTE_KEY = "data-key"; const ATTRIBUTE_DEFAULT_VALUE = "data-default-value"; const ATTRIBUTE_INIT_MORE_VALUE = "data-init-more-value"; const PROPS_STORAGE_API = "data-storage-api"; const PanelSizeUtil = { get width() { return globalThis.innerWidth; }, get height() { return globalThis.innerHeight; } }; const PanelUISize = { setting: { get width() { if (PanelSizeUtil.width < 550) { return "88vw"; } else if (PanelSizeUtil.width < 700) { return "550px"; } else { return "700px"; } }, get height() { if (PanelSizeUtil.height < 450) { return "70vh"; } else if (PanelSizeUtil.height < 550) { return "450px"; } else { return "550px"; } } }, settingMiddle: { get width() { return PanelSizeUtil.width < 350 ? "88vw" : "350px"; } } }; class StorageUtils { storageKey; listenerData; constructor(key) { if (typeof key === "string") { let trimKey = key.trim(); if (trimKey == "") { throw new Error("key参数不能为空字符串"); } this.storageKey = trimKey; } else { throw new Error("key参数类型错误,必须是字符串"); } this.listenerData = new Utils.Dictionary(); } getLocalValue() { let localValue = _GM_getValue(this.storageKey); if (localValue == null) { localValue = {}; this.setLocalValue(localValue); } return localValue; } setLocalValue(value) { _GM_setValue(this.storageKey, value); } set(key, value) { let oldValue = this.get(key); let localValue = this.getLocalValue(); Reflect.set(localValue, key, value); this.setLocalValue(localValue); this.triggerValueChangeListener(key, oldValue, value); } get(key, defaultValue) { let localValue = this.getLocalValue(); return Reflect.get(localValue, key) ?? defaultValue; } getAll() { let localValue = this.getLocalValue(); return localValue; } delete(key) { let oldValue = this.get(key); let localValue = this.getLocalValue(); Reflect.deleteProperty(localValue, key); this.setLocalValue(localValue); this.triggerValueChangeListener(key, oldValue, void 0); } has(key) { let localValue = this.getLocalValue(); return Reflect.has(localValue, key); } keys() { let localValue = this.getLocalValue(); return Reflect.ownKeys(localValue); } values() { let localValue = this.getLocalValue(); return Reflect.ownKeys(localValue).map( (key) => Reflect.get(localValue, key) ); } clear() { _GM_deleteValue(this.storageKey); } addValueChangeListener(key, callback) { let listenerId = Math.random(); let listenerData = this.listenerData.get(key) || []; listenerData.push({ id: listenerId, key, callback }); this.listenerData.set(key, listenerData); return listenerId; } removeValueChangeListener(listenerId) { let flag = false; for (const [key, listenerData] of this.listenerData.entries()) { for (let index = 0; index < listenerData.length; index++) { const value = listenerData[index]; if (typeof listenerId === "string" && value.key === listenerId || typeof listenerId === "number" && value.id === listenerId) { listenerData.splice(index, 1); index--; flag = true; } } this.listenerData.set(key, listenerData); } return flag; } triggerValueChangeListener(key, oldValue, newValue) { if (!this.listenerData.has(key)) { return; } let listenerData = this.listenerData.get(key); for (let index = 0; index < listenerData.length; index++) { const data = listenerData[index]; if (typeof data.callback === "function") { let value = this.get(key); let __newValue; let __oldValue; if (typeof oldValue !== "undefined" && arguments.length >= 2) { __oldValue = oldValue; } else { __oldValue = value; } if (typeof newValue !== "undefined" && arguments.length > 2) { __newValue = newValue; } else { __newValue = value; } data.callback(key, __oldValue, __newValue); } } } } const PopsPanelStorageApi = new StorageUtils(KEY); const PanelContent = { $data: { __contentConfig: null, get contentConfig() { if (this.__contentConfig == null) { this.__contentConfig = new utils.Dictionary(); } return this.__contentConfig; } }, addContentConfig(configList) { if (!Array.isArray(configList)) { configList = [configList]; } let index = this.$data.contentConfig.keys().length; this.$data.contentConfig.set(index, configList); }, getAllContentConfig() { return this.$data.contentConfig.values().flat(); }, getConfig(index = 0) { return this.$data.contentConfig.get(index) ?? []; }, getDefaultBottomContentConfig() { return [ { id: "script-version", title: `版本:${_GM_info?.script?.version || "未知"}`, isBottom: true, forms: [], clickFirstCallback(event, rightHeaderElement, rightContainerElement) { let supportURL = _GM_info?.script?.supportURL || _GM_info?.script?.namespace; if (typeof supportURL === "string" && utils.isNotNull(supportURL)) { window.open(supportURL, "_blank"); } return false; } } ]; } }; const PanelMenu = { $data: { __menuOption: [ { key: "show_pops_panel_setting", text: "⚙ 设置", autoReload: false, isStoreValue: false, showText(text) { return text; }, callback: () => { Panel.showPanel(PanelContent.getConfig(0)); } } ], get menuOption() { return this.__menuOption; } }, init() { this.initExtensionsMenu(); }, initExtensionsMenu() { if (!Panel.isTopWindow()) { return; } GM_Menu.add(this.$data.menuOption); }, addMenuOption(option) { if (!Array.isArray(option)) { option = [option]; } this.$data.menuOption.push(...option); }, updateMenuOption(option) { if (!Array.isArray(option)) { option = [option]; } option.forEach((optionItem) => { let findIndex = this.$data.menuOption.findIndex((it) => { return it.key === optionItem.key; }); if (findIndex !== -1) { this.$data.menuOption[findIndex] = optionItem; } }); }, getMenuOption(index = 0) { return this.$data.menuOption[index]; }, deleteMenuOption(index = 0) { this.$data.menuOption.splice(index, 1); } }; const CommonUtil = { waitRemove(...args) { args.forEach((selector) => { if (typeof selector !== "string") { return; } utils.waitNodeList(selector).then((nodeList) => { nodeList.forEach(($el) => $el.remove()); }); }); }, createBlockCSSNode(...args) { let selectorList = []; if (args.length === 0) { return; } if (args.length === 1 && typeof args[0] === "string" && args[0].trim() === "") { return; } args.forEach((selector) => { if (Array.isArray(selector)) { selectorList = selectorList.concat(selector); } else { selectorList.push(selector); } }); return DOMUtils.createElement("style", { type: "text/css", innerHTML: `${selectorList.join(",\n")}{display: none !important;}` }); }, addBlockCSS(...args) { let selectorList = []; if (args.length === 0) { return; } if (args.length === 1 && typeof args[0] === "string" && args[0].trim() === "") { return; } args.forEach((selector) => { if (Array.isArray(selector)) { selectorList = selectorList.concat(selector); } else { selectorList.push(selector); } }); return addStyle(`${selectorList.join(",\n")}{display: none !important;}`); }, setGMResourceCSS(resourceMapData) { let cssText = typeof _GM_getResourceText === "function" ? _GM_getResourceText(resourceMapData.keyName) : null; if (typeof cssText === "string" && cssText) { addStyle(cssText); } else { CommonUtil.loadStyleLink(resourceMapData.url); } }, async loadStyleLink(url) { let $link = document.createElement("link"); $link.rel = "stylesheet"; $link.type = "text/css"; $link.href = url; DOMUtils.ready(() => { document.head.appendChild($link); }); }, async loadScript(url) { let $script = document.createElement("script"); $script.src = url; return new Promise((resolve) => { $script.onload = () => { resolve(null); }; (document.head || document.documentElement).appendChild($script); }); }, fixUrl(url) { url = url.trim(); if (url.match(/^http(s|):\/\//i)) { return url; } else if (url.startsWith("//")) { if (url.startsWith("///")) ; else { url = window.location.protocol + url; } return url; } else { if (!url.startsWith("/")) { url += "/"; } url = window.location.origin + url; return url; } }, fixHttps(url) { if (url.startsWith("https://")) { return url; } if (!url.startsWith("http://")) { return url; } let urlInstance = new URL(url); urlInstance.protocol = "https:"; return urlInstance.toString(); }, lockScroll(...args) { let $hidden = document.createElement("style"); $hidden.innerHTML = ` .pops-overflow-hidden-important { overflow: hidden !important; } `; let $elList = [document.documentElement, document.body].concat(...args || []); $elList.forEach(($el) => { $el.classList.add("pops-overflow-hidden-important"); }); (document.head || document.documentElement).appendChild($hidden); return { recovery() { $elList.forEach(($el) => { $el.classList.remove("pops-overflow-hidden-important"); }); $hidden.remove(); } }; }, async getClipboardText() { function readClipboardText(resolve) { navigator.clipboard.readText().then((clipboardText) => { resolve(clipboardText); }).catch((error) => { log.error("读取剪贴板内容失败👉", error); resolve(""); }); } function requestPermissionsWithClipboard(resolve) { navigator.permissions.query({ name: "clipboard-read" }).then((permissionStatus) => { readClipboardText(resolve); }).catch((error) => { log.error("申请剪贴板权限失败,尝试直接读取👉", error.message ?? error.name ?? error.stack); readClipboardText(resolve); }); } function checkClipboardApi() { if (typeof navigator?.clipboard?.readText !== "function") { return false; } if (typeof navigator?.permissions?.query !== "function") { return false; } return true; } return new Promise((resolve) => { if (!checkClipboardApi()) { resolve(""); return; } if (document.hasFocus()) { requestPermissionsWithClipboard(resolve); } else { window.addEventListener( "focus", () => { requestPermissionsWithClipboard(resolve); }, { once: true } ); } }); }, escapeHtml(unsafe) { return unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/©/g, "©").replace(/®/g, "®").replace(/™/g, "™").replace(/→/g, "→").replace(/←/g, "←").replace(/↑/g, "↑").replace(/↓/g, "↓").replace(/—/g, "—").replace(/–/g, "–").replace(/…/g, "…").replace(/ /g, " ").replace(/\r\n/g, "<br>").replace(/\r/g, "<br>").replace(/\n/g, "<br>").replace(/\t/g, " "); }, interval(fn, intervalTime, timeout = 5e3) { let timeId; let maxTimeout = timeout - intervalTime; let intervalTimeCount = intervalTime; let loop = async (isTimeout) => { let result = await fn(isTimeout); if (typeof result === "boolean" && !result || isTimeout) { utils.workerClearTimeout(timeId); return; } intervalTimeCount += intervalTime; if (intervalTimeCount > maxTimeout) { loop(true); return; } timeId = utils.workerSetTimeout(() => { loop(false); }, intervalTime); }; loop(false); }, findParentNode($el, selector, parentSelector) { if (parentSelector) { let $parent = DOMUtils.closest($el, parentSelector); if ($parent) { let $target = $parent.querySelector(selector); return $target; } } else { if (DOMUtils.matches($el, selector)) { return $el; } let $parent = DOMUtils.closest($el, selector); return $parent; } } }; const Panel = { $data: { __contentConfigInitDefaultValue: null, __onceExecMenuData: null, __urlChangeReloadMenuExecOnce: null, __onceExecData: null, __panelConfig: {}, $panel: null, panelContent: [], get contentConfigInitDefaultValue() { if (this.__contentConfigInitDefaultValue == null) { this.__contentConfigInitDefaultValue = new utils.Dictionary(); } return this.__contentConfigInitDefaultValue; }, contentConfigInitDisabledKeys: [], get onceExecMenuData() { if (this.__onceExecMenuData == null) { this.__onceExecMenuData = new utils.Dictionary(); } return this.__onceExecMenuData; }, get urlChangeReloadMenuExecOnce() { if (this.__urlChangeReloadMenuExecOnce == null) { this.__urlChangeReloadMenuExecOnce = new utils.Dictionary(); } return this.__urlChangeReloadMenuExecOnce; }, get onceExecData() { if (this.__onceExecData == null) { this.__onceExecData = new utils.Dictionary(); } return this.__onceExecData; }, get scriptName() { return SCRIPT_NAME; }, get panelConfig() { return this.__panelConfig; }, set panelConfig(value) { this.__panelConfig = value; }, key: KEY, attributeKeyName: ATTRIBUTE_KEY, attributeDefaultValueName: ATTRIBUTE_DEFAULT_VALUE }, init() { this.initContentDefaultValue(); PanelMenu.init(); }, isTopWindow() { return _unsafeWindow.top === _unsafeWindow.self; }, initContentDefaultValue() { const initDefaultValue = (config) => { if (!config.attributes) { return; } if (config.type === "button" || config.type === "forms" || config.type === "deepMenu") { return; } let __attr_init__ = config.attributes[ATTRIBUTE_INIT]; if (typeof __attr_init__ === "function") { let __attr_result__ = __attr_init__(); if (typeof __attr_result__ === "boolean" && !__attr_result__) { return; } } let menuDefaultConfig = new Map(); let key = config.attributes[ATTRIBUTE_KEY]; if (key != null) { const defaultValue = config.attributes[ATTRIBUTE_DEFAULT_VALUE]; menuDefaultConfig.set(key, defaultValue); } let moreMenuDefaultConfig = config.attributes[ATTRIBUTE_INIT_MORE_VALUE]; if (typeof moreMenuDefaultConfig === "object" && moreMenuDefaultConfig) { Object.keys(moreMenuDefaultConfig).forEach((key2) => { menuDefaultConfig.set(key2, moreMenuDefaultConfig[key2]); }); } if (!menuDefaultConfig.size) { log.warn(["请先配置键", config]); return; } if (config.type === "switch") { let disabled = typeof config.disabled === "function" ? config.disabled() : config.disabled; if (typeof disabled === "boolean" && disabled) { this.$data.contentConfigInitDisabledKeys.push(...menuDefaultConfig.keys()); } } for (const [__key, __defaultValue] of menuDefaultConfig.entries()) { this.setDefaultValue(__key, __defaultValue); } }; const loopInitDefaultValue = (configList) => { for (let index = 0; index < configList.length; index++) { let configItem = configList[index]; initDefaultValue(configItem); let child_forms = configItem.forms; if (child_forms && Array.isArray(child_forms)) { loopInitDefaultValue(child_forms); } } }; const contentConfigList = [...PanelContent.getAllContentConfig()]; for (let index = 0; index < contentConfigList.length; index++) { let leftContentConfigItem = contentConfigList[index]; if (!leftContentConfigItem.forms) { continue; } const rightContentConfigList = leftContentConfigItem.forms; if (rightContentConfigList && Array.isArray(rightContentConfigList)) { loopInitDefaultValue(rightContentConfigList); } } this.$data.contentConfigInitDisabledKeys = [...new Set(this.$data.contentConfigInitDisabledKeys)]; }, setDefaultValue(key, defaultValue) { if (this.$data.contentConfigInitDefaultValue.has(key)) { log.warn("请检查该key(已存在): " + key); } this.$data.contentConfigInitDefaultValue.set(key, defaultValue); }, setValue(key, value) { PopsPanelStorageApi.set(key, value); }, getValue(key, defaultValue) { let localValue = PopsPanelStorageApi.get(key); if (localValue == null) { if (this.$data.contentConfigInitDefaultValue.has(key)) { return this.$data.contentConfigInitDefaultValue.get(key); } return defaultValue; } return localValue; }, deleteValue(key) { PopsPanelStorageApi.delete(key); }, hasKey(key) { return PopsPanelStorageApi.has(key); }, addValueChangeListener(key, callback) { let listenerId = PopsPanelStorageApi.addValueChangeListener(key, (__key, __newValue, __oldValue) => { callback(key, __oldValue, __newValue); }); return listenerId; }, removeValueChangeListener(listenerId) { PopsPanelStorageApi.removeValueChangeListener(listenerId); }, triggerMenuValueChange(key, newValue, oldValue) { PopsPanelStorageApi.triggerValueChangeListener(key, oldValue, newValue); }, exec(queryKey, callback, checkExec, once = true) { const that = this; let queryKeyFn; if (typeof queryKey === "string" || Array.isArray(queryKey)) { queryKeyFn = () => queryKey; } else { queryKeyFn = queryKey; } let isArrayKey = false; let queryKeyResult = queryKeyFn(); let keyList = []; if (Array.isArray(queryKeyResult)) { isArrayKey = true; keyList = queryKeyResult; } else { keyList.push(queryKeyResult); } let findNotInDataKey = keyList.find((it) => !this.$data.contentConfigInitDefaultValue.has(it)); if (findNotInDataKey) { log.warn(`${findNotInDataKey} 键不存在`); return; } let storageKey = JSON.stringify(keyList); if (once) { if (this.$data.onceExecMenuData.has(storageKey)) { return this.$data.onceExecMenuData.get(storageKey); } } let storeValueList = []; let listenerIdList = []; let dynamicAddStyleNodeCallback = (value, $style) => { let dynamicResultList = []; if (!Array.isArray($style)) { $style = [$style]; } $style.forEach(($styleItem) => { if ($styleItem == null) { return; } if ($styleItem instanceof HTMLStyleElement) { dynamicResultList.push($styleItem); return; } }); { storeValueList = storeValueList.concat(dynamicResultList); } }; let getMenuValue = (key) => { let value = this.getValue(key); return value; }; let clearBeforeStoreValue = () => { for (let index = 0; index < storeValueList.length; index++) { let $css = storeValueList[index]; $css.remove(); storeValueList.splice(index, 1); index--; } }; let checkMenuExec = () => { let flag = false; if (typeof checkExec === "function") { flag = checkExec(keyList); } else { flag = keyList.every((key) => getMenuValue(key)); } return flag; }; let valueChangeCallback = (valueOption) => { let execFlag = checkMenuExec(); let resultList = []; if (execFlag) { let valueList = keyList.map((key) => this.getValue(key)); let callbackResult = callback({ value: isArrayKey ? valueList : valueList[0], addStyleElement: (...args) => { return dynamicAddStyleNodeCallback(true, ...args); } }); if (!Array.isArray(callbackResult)) { callbackResult = [callbackResult]; } callbackResult.forEach((it) => { if (it == null) { return; } if (it instanceof HTMLStyleElement) { resultList.push(it); return; } }); } clearBeforeStoreValue(); storeValueList = [...resultList]; }; once && keyList.forEach((key) => { let listenerId = this.addValueChangeListener(key, (key2, newValue, oldValue) => { valueChangeCallback(); }); listenerIdList.push(listenerId); }); valueChangeCallback(); let result = { reload() { valueChangeCallback(); }, clear() { this.clearStoreStyleElements(); this.removeValueChangeListener(); once && that.$data.onceExecMenuData.delete(storageKey); }, clearStoreStyleElements: () => { return clearBeforeStoreValue(); }, removeValueChangeListener: () => { listenerIdList.forEach((listenerId) => { this.removeValueChangeListener(listenerId); }); } }; this.$data.onceExecMenuData.set(storageKey, result); return result; }, execMenu(key, callback, isReverse = false, once = false) { return this.exec( key, (option) => { return callback(option); }, (keyList) => { let execFlag = keyList.every((__key__) => { let flag = !!this.getValue(__key__); let disabled = Panel.$data.contentConfigInitDisabledKeys.includes(__key__); if (disabled) { flag = false; log.warn(`.execMenu${once ? "Once" : ""} ${__key__} 被禁用`); } isReverse && (flag = !flag); return flag; }); return execFlag; }, once ); }, execMenuOnce(key, callback, isReverse = false, listenUrlChange = false) { const result = this.execMenu(key, callback, isReverse, true); if (listenUrlChange) { if (result) { const urlChangeEvent = () => { result.reload(); }; this.removeUrlChangeWithExecMenuOnceListener(key); this.addUrlChangeWithExecMenuOnceListener(key, urlChangeEvent); const originClear = result.clear; result.clear = () => { originClear(); this.removeUrlChangeWithExecMenuOnceListener(key); }; } } return result; }, deleteExecMenuOnce(key) { key = this.transformKey(key); this.$data.onceExecMenuData.delete(key); this.$data.urlChangeReloadMenuExecOnce.delete(key); let flag = PopsPanelStorageApi.removeValueChangeListener(key); return flag; }, onceExec(key, callback) { key = this.transformKey(key); if (typeof key !== "string") { throw new TypeError("key 必须是字符串"); } if (this.$data.onceExecData.has(key)) { return; } callback(); this.$data.onceExecData.set(key, 1); }, deleteOnceExec(key) { key = this.transformKey(key); this.$data.onceExecData.delete(key); }, addUrlChangeWithExecMenuOnceListener(key, callback) { key = this.transformKey(key); this.$data.urlChangeReloadMenuExecOnce.set(key, callback); }, removeUrlChangeWithExecMenuOnceListener(key) { key = this.transformKey(key); this.$data.urlChangeReloadMenuExecOnce.delete(key); }, triggerUrlChangeWithExecMenuOnceEvent(config) { this.$data.urlChangeReloadMenuExecOnce.forEach((callback, key) => { callback(config); }); }, showPanel(content, title = `${SCRIPT_NAME}-设置`, preventDefaultContentConfig = false, preventRegisterSearchPlugin = false) { this.$data.$panel = null; this.$data.panelContent = []; let checkHasBottomVersionContentConfig = content.findIndex((it) => { let isBottom = typeof it.isBottom === "function" ? it.isBottom() : Boolean(it.isBottom); return isBottom && it.id === "script-version"; }) !== -1; if (!preventDefaultContentConfig && !checkHasBottomVersionContentConfig) { content.push(...PanelContent.getDefaultBottomContentConfig()); } let $panel = __pops.panel({ ...{ title: { text: title, position: "center", html: false, style: "" }, content, btn: { close: { enable: true, callback: (details, event) => { details.close(); this.$data.$panel = null; } } }, mask: { enable: true, clickEvent: { toClose: true, toHide: false }, clickCallBack: (originalRun, config) => { originalRun(); this.$data.$panel = null; } }, width: PanelUISize.setting.width, height: PanelUISize.setting.height, drag: true, only: true }, ...this.$data.panelConfig }); this.$data.$panel = $panel; this.$data.panelContent = content; if (!preventRegisterSearchPlugin) { this.registerConfigSearch({ $panel, content }); } }, registerConfigSearch(config) { const { $panel, content } = config; let asyncQueryProperty = async (target, handler) => { if (target == null) { return; } let handleResult = await handler(target); if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) { return handleResult.data; } return await asyncQueryProperty(handleResult.data, handler); }; let scrollToElementAndListen = ($el, callback) => { const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { callback?.(); observer.disconnect(); } }); }, { root: null, threshold: 1 } ); observer.observe($el); $el.scrollIntoView({ behavior: "smooth", block: "center" }); }; let addFlashingClass = ($el) => { const flashingClassName = "pops-flashing"; domUtils.animationend($el, () => { $el.classList.remove(flashingClassName); }); $el.classList.add(flashingClassName); }; let dbclick_event = (evt, selectorTarget) => { utils.preventEvent(evt); let $alert = __pops.alert({ title: { text: "搜索配置", position: "center" }, content: { text: ( ` <div class="search-wrapper"> <input class="search-config-text" name="search-config" type="text" placeholder="请输入需要搜素的配置名称"> </div> <div class="search-result-wrapper"></div> ` ), html: true }, btn: { ok: { enable: false } }, mask: { clickEvent: { toClose: true } }, width: PanelUISize.settingMiddle.width, height: "auto", drag: true, style: ( ` ${__pops.config.cssText.panelCSS} .search-wrapper{ border-bottom: 1px solid rgb(235, 238, 245, 1); } .pops-content:has(.search-result-wrapper:empty) .search-wrapper{ border-bottom: 0; } .search-config-text{ width: 100%; border: 0; height: 32px; padding: 0px 10px; outline: none; } .search-result-wrapper{ max-height: 400px; overflow: auto; } .search-result-item{ cursor: pointer; padding: 5px 10px; display: flex; flex-direction: column; } .search-result-item:hover{ background-color: #D8F1FD; } .search-result-item-path{ display: flex; align-items: center; } .search-result-item-description{ font-size: 0.8em; color: #6c6c6c; } ${config.searchDialogStyle ?? ""} ` ) }); $alert.$shadowRoot.querySelector(".search-wrapper"); let $searchInput = $alert.$shadowRoot.querySelector(".search-config-text"); let $searchResultWrapper = $alert.$shadowRoot.querySelector(".search-result-wrapper"); $searchInput.focus(); let clearSearchResult = () => { domUtils.empty($searchResultWrapper); }; let createSearchResultItem = (pathInfo) => { const searchPath = utils.queryProperty(pathInfo, (target) => { if (target?.next) { return { isFind: false, data: target.next }; } else { return { isFind: true, data: target }; } }); let $item = domUtils.createElement("div", { className: "search-result-item", innerHTML: ( ` <div class="search-result-item-path">${searchPath.matchedData?.path}</div> <div class="search-result-item-description">${searchPath.matchedData?.description ?? ""}</div> ` ) }); domUtils.on($item, "click", (clickItemEvent) => { let $asideItems = $panel.$shadowRoot.querySelectorAll( "aside.pops-panel-aside .pops-panel-aside-top-container li" ); let $targetAsideItem = $asideItems[pathInfo.index]; if (!$targetAsideItem) { Qmsg.error(`左侧项下标${pathInfo.index}不存在`); return; } $targetAsideItem.scrollIntoView({ behavior: "smooth", block: "center" }); $targetAsideItem.click(); asyncQueryProperty(pathInfo.next, async (target) => { if (target?.next) { let $findDeepMenu = await utils.waitNode(() => { return Array.from( $panel.$shadowRoot.querySelectorAll(".pops-panel-deepMenu-nav-item") ).find(($deepMenu) => { const __formConfig__ = Reflect.get($deepMenu, "__formConfig__"); return typeof __formConfig__ === "object" && __formConfig__ != null && __formConfig__.text === target.name; }); }, 2500); if ($findDeepMenu) { $findDeepMenu.click(); } else { Qmsg.error("未找到对应的二级菜单"); return { isFind: true, data: target }; } return { isFind: false, data: target.next }; } else { let $findTargetMenu = await utils.waitNode(() => { return Array.from( $panel.$shadowRoot.querySelectorAll(`li:not(.pops-panel-deepMenu-nav-item)`) ).find(($menuItem) => { const __formConfig__ = Reflect.get($menuItem, "__formConfig__"); return __formConfig__ === target.matchedData?.formConfig; }); }, 2500); if ($findTargetMenu) { scrollToElementAndListen($findTargetMenu); let $fold = $findTargetMenu.closest(`.pops-panel-forms-fold[data-fold-enable]`); if ($fold) { let $foldWrapper = $fold.querySelector(".pops-panel-forms-fold-container"); $foldWrapper.click(); await utils.sleep(500); } scrollToElementAndListen($findTargetMenu, () => { addFlashingClass($findTargetMenu); }); } else { Qmsg.error("未找到对应的菜单项"); } return { isFind: true, data: target }; } }); }); return $item; }; let execSearch = (searchText) => { const searchTextRegExp = new RegExp(searchText, "i"); const searchConfigResult = []; const loopContentConfig = (configList, path) => { for (let index = 0; index < configList.length; index++) { const configItem = configList[index]; let child_forms = configItem.forms; if (child_forms && Array.isArray(child_forms)) { const deepMenuPath = utils.deepClone(path); if (configItem.type === "deepMenu") { const deepNext = utils.queryProperty(deepMenuPath, (target) => { if (target?.next) { return { isFind: false, data: target.next }; } else { return { isFind: true, data: target }; } }); deepNext.next = { name: configItem.text }; } loopContentConfig(child_forms, deepMenuPath); } else { let text = Reflect.get(configItem, "text"); let description = Reflect.get(configItem, "description"); const delayMatchedTextList = [text, description]; let matchedIndex = delayMatchedTextList.findIndex((configText) => { if (typeof configText !== "string") { return; } return configText.match(searchTextRegExp); }); if (matchedIndex !== -1) { const matchedPath = utils.deepClone(path); const deepNext = utils.queryProperty(matchedPath, (target) => { if (target?.next) { return { isFind: false, data: target.next }; } else { return { isFind: true, data: target }; } }); deepNext.next = { name: text, matchedData: { path: "", formConfig: configItem, matchedText: delayMatchedTextList[matchedIndex], description } }; const pathList = []; utils.queryProperty(matchedPath, (target) => { const name = target?.name; if (typeof name === "string" && name.trim() !== "") { pathList.push(name); } if (target?.next) { return { isFind: false, data: target.next }; } else { return { isFind: true, data: target }; } }); const pathStr = pathList.join(CommonUtil.escapeHtml(" - ")); deepNext.next.matchedData.path = pathStr; searchConfigResult.push(matchedPath); } } } }; for (let index = 0; index < content.length; index++) { const leftContentConfigItem = content[index]; if (!leftContentConfigItem.forms) { continue; } if (leftContentConfigItem.isBottom && leftContentConfigItem.id === "script-version") { continue; } const rightContentConfigList = leftContentConfigItem.forms; if (rightContentConfigList && Array.isArray(rightContentConfigList)) { let text = leftContentConfigItem.title; if (typeof text === "function") { text = text(); } loopContentConfig(rightContentConfigList, { index, name: text }); } } let fragment = document.createDocumentFragment(); for (const pathInfo of searchConfigResult) { let $resultItem = createSearchResultItem(pathInfo); fragment.appendChild($resultItem); } clearSearchResult(); $searchResultWrapper.append(fragment); }; domUtils.on( $searchInput, "input", utils.debounce((evt2) => { utils.preventEvent(evt2); let searchText = domUtils.val($searchInput).trim(); if (searchText === "") { clearSearchResult(); return; } execSearch(searchText); }, 200) ); }; let clickElement = null; let isDoubleClick = false; let timer = void 0; domUtils.on( $panel.$shadowRoot, "dblclick", `aside.pops-panel-aside .pops-panel-aside-item:not(#script-version)`, dbclick_event ); domUtils.on( $panel.$shadowRoot, "touchend", `aside.pops-panel-aside .pops-panel-aside-item:not(#script-version)`, (evt, selectorTarget) => { clearTimeout(timer); timer = void 0; if (isDoubleClick && clickElement === selectorTarget) { isDoubleClick = false; clickElement = null; dbclick_event(evt); } else { timer = setTimeout(() => { isDoubleClick = false; }, 200); isDoubleClick = true; clickElement = selectorTarget; } }, { capture: true } ); $panel.$shadowRoot.appendChild( domUtils.createElement("style", { type: "text/css", textContent: ( ` .pops-flashing{ animation: double-blink 1.5s ease-in-out; } @keyframes double-blink { 0% { background-color: initial; } 25% { background-color: yellow; } 50% { background-color: initial; } 75% { background-color: yellow; } 100% { background-color: initial; } } ` ) }) ); }, transformKey(key) { if (Array.isArray(key)) { const keyArray = key.sort(); return JSON.stringify(keyArray); } else { return key; } } }; const PanelSettingConfig = { qmsg_config_position: { key: "qmsg-config-position", defaultValue: "bottom" }, qmsg_config_maxnums: { key: "qmsg-config-maxnums", defaultValue: 3 }, qmsg_config_showreverse: { key: "qmsg-config-showreverse", defaultValue: false } }; const utils = Utils.noConflict(); const domUtils = DOMUtils.noConflict(); const __pops = pops; const log = new utils.Log( _GM_info, _unsafeWindow.console || _monkeyWindow.console ); let SCRIPT_NAME = _GM_info?.script?.name || void 0; pops.config.Utils.AnyTouch(); const DEBUG = false; log.config({ debug: DEBUG, logMaxCount: 1e3, autoClearConsole: true, tag: true }); Qmsg.config({ isHTML: true, autoClose: true, showClose: false, consoleLogContent(qmsgInst) { const qmsgType = qmsgInst.getSetting().type; if (qmsgType === "loading") { return false; } const content = qmsgInst.getSetting().content; if (qmsgType === "warning") { log.warn(content); } else if (qmsgType === "error") { log.error(content); } else { log.info(content); } return true; }, get position() { return Panel.getValue( PanelSettingConfig.qmsg_config_position.key, PanelSettingConfig.qmsg_config_position.defaultValue ); }, get maxNums() { return Panel.getValue( PanelSettingConfig.qmsg_config_maxnums.key, PanelSettingConfig.qmsg_config_maxnums.defaultValue ); }, get showReverse() { return Panel.getValue( PanelSettingConfig.qmsg_config_showreverse.key, PanelSettingConfig.qmsg_config_showreverse.defaultValue ); }, get zIndex() { let maxZIndex = Utils.getMaxZIndex(); let popsMaxZIndex = pops.config.InstanceUtils.getPopsMaxZIndex().zIndex; return Utils.getMaxValue(maxZIndex, popsMaxZIndex) + 100; } }); __pops.GlobalConfig.setGlobalConfig({ zIndex: () => { let maxZIndex = Utils.getMaxZIndex(void 0, void 0, ($ele) => { if ($ele?.classList?.contains("qmsg-shadow-container")) { return false; } if ($ele?.closest("qmsg") && $ele.getRootNode() instanceof ShadowRoot) { return false; } }); let popsMaxZIndex = pops.config.InstanceUtils.getPopsMaxZIndex().zIndex; return Utils.getMaxValue(maxZIndex, popsMaxZIndex) + 100; }, mask: { enable: true, clickEvent: { toClose: false, toHide: false } }, drag: true }); const GM_Menu = new utils.GM_Menu({ GM_getValue: _GM_getValue, GM_setValue: _GM_setValue, GM_registerMenuCommand: _GM_registerMenuCommand, GM_unregisterMenuCommand: _GM_unregisterMenuCommand }); const httpx = new utils.Httpx({ xmlHttpRequest: _GM_xmlhttpRequest, logDetails: DEBUG }); httpx.interceptors.request.use((data) => { return data; }); httpx.interceptors.response.use(void 0, (data) => { log.error("拦截器-请求错误", data); if (data.type === "onabort") { Qmsg.warning("请求取消", { consoleLogContent: true }); } else if (data.type === "onerror") { Qmsg.error("请求异常", { consoleLogContent: true }); } else if (data.type === "ontimeout") { Qmsg.error("请求超时", { consoleLogContent: true }); } else { Qmsg.error("其它错误", { consoleLogContent: true }); } return data; }); ({ Object: { defineProperty: _unsafeWindow.Object.defineProperty }, Function: { apply: _unsafeWindow.Function.prototype.apply, call: _unsafeWindow.Function.prototype.call }, Element: { appendChild: _unsafeWindow.Element.prototype.appendChild }, setTimeout: _unsafeWindow.setTimeout }); const addStyle = utils.addStyle.bind(utils); DOMUtils.selector.bind(DOMUtils); DOMUtils.selectorAll.bind(DOMUtils); new utils.GM_Cookie(); const JianshuRouter = { isGoWild() { return window.location.pathname === "/go-wild"; } }; const waitForElementToRemove = function(selectorText = "") { utils.waitNodeList(selectorText).then((nodeList) => { nodeList.forEach((item) => item.remove()); }); }; const Jianshu = { init() { this.addCSS(); Panel.execMenu("JianShuAutoJumpRedirect_PC", () => { this.jumpRedirect(); }); Panel.execMenu("JianShuRemoveClipboardHijacking", () => { this.removeClipboardHijacking(); }); Panel.execMenu("JianShuAutoExpandFullText", () => { this.autoExpandFullText(); }); Panel.execMenu("JianShuArticleCenter", () => { return this.articleCenter(); }); Panel.execMenu("JianShuShieldRelatedArticles", () => { return this.blockRelatedArticles(); }); Panel.execMenu("jianshu-shieldClientDialog", () => { this.blockClientDialog(); }); Panel.execMenuOnce("JianShuShieldUserComments", () => { return this.blockUserComments(); }); Panel.execMenuOnce("JianShuShieldRecommendedReading", () => { return this.blockRecommendedReading(); }); Panel.execMenuOnce("jianshu-shieldTopNav", () => { return this.blockTopNav(); }); Panel.execMenuOnce("jianshu-shieldBottomToolbar", () => { return this.blockBottomToolbar(); }); }, addCSS() { log.info("添加屏蔽CSS"); return addStyle(blockCSS); }, articleCenter() { log.info("全文居中"); let result = []; result.push( CommonUtil.addBlockCSS("div[role=main] aside", "div._3Pnjry"), addStyle( ` div[role=main] aside, div._3Pnjry{ display: none !important; } div._gp-ck{ width: 100% !important; }` ) ); waitForElementToRemove("div[role=main] aside"); waitForElementToRemove("div._3Pnjry"); utils.waitNodeList("div._gp-ck").then((nodeList) => { nodeList.forEach((item) => { item.style["width"] = "100%"; }); }); return result; }, removeClipboardHijacking() { log.info("去除剪贴板劫持"); const stopNativePropagation = (event) => { event.stopPropagation(); }; window.addEventListener("copy", stopNativePropagation, true); document.addEventListener("copy", stopNativePropagation, true); }, autoExpandFullText() { utils.waitNode(`div#homepage div[class*="dialog-"]`).then((element) => { element.style["visibility"] = "hidden"; log.info("自动展开全文"); utils.mutationObserver(element, { callback: (mutations) => { if (mutations.length == 0) { return; } mutations.forEach((mutationItem) => { if (mutationItem.target.style["display"] != "none") { log.success("自动展开全文-自动点击"); document.querySelector( 'div#homepage div[class*="dialog-"] .cancel' )?.click(); } }); }, config: { childList: false, attributes: true, characterData: true, subtree: true } }); }); }, jumpRedirect() { if (JianshuRouter.isGoWild()) { log.success("去除简书拦截其它网址的url并自动跳转"); window.stop(); let search = window.location.href.replace( window.location.origin + "/", "" ); search = decodeURIComponent(search); let newURL = search.replace(/^go-wild\?ac=2&url=/gi, "").replace(/^https:\/\/link.zhihu.com\/\?target\=/gi, ""); window.location.href = newURL; } }, blockRelatedArticles() { log.info("屏蔽相关文章"); return CommonUtil.addBlockCSS( 'div[role="main"] > div > section:nth-child(2)' ); }, blockClientDialog() { log.info("【屏蔽】客户端弹窗"); CommonUtil.addBlockCSS( 'div:has(>div[class*="-mask"]:not([class*="-mask-hidden"]) + div[tabindex="-1"][role="dialog"])' ); utils.waitNode( `div[class*="-mask"]:not([class*="-mask-hidden"]) + div[tabindex="-1"][role="dialog"]` ).then((element) => { log.success("弹窗出现"); utils.waitPropertyByInterval( element, () => { let react = utils.getReactObj(element); return react?.reactInternalInstance?.return?.return?.memoizedProps?.onClose; }, 250, 1e4 ).then(() => { let react = utils.getReactObj(element); react.reactInternalInstance.return.return.memoizedProps.onClose( new Event("click") ); log.success("调用函数关闭弹窗"); }); }); }, blockUserComments() { log.info("屏蔽评论区"); return CommonUtil.addBlockCSS("div#note-page-comment"); }, blockRecommendedReading() { log.info("屏蔽底部推荐阅读"); return CommonUtil.addBlockCSS( 'div[role="main"] > div > section:last-child' ); }, blockTopNav() { log.info("【屏蔽】顶部导航栏"); return CommonUtil.addBlockCSS("header"); }, blockBottomToolbar() { log.info("【屏蔽】底部工具栏"); return CommonUtil.addBlockCSS("footer"); } }; const M_Jianshu = { init() { this.addCSS(); Panel.execMenu("JianShuAutoJumpRedirect_Mobile", () => { Jianshu.jumpRedirect(); }); Panel.execMenu("JianShuHijackSchemeScriptLabel_Mobile", () => { this.handlePrototype(); }); Panel.execMenu("JianShuRemoveClipboardHijacking_Mobile", () => { Jianshu.removeClipboardHijacking(); }); Panel.execMenu("JianShuAutoExpandFullText_Mobile", () => { Jianshu.autoExpandFullText(); }); Panel.execMenuOnce("JianShuremoveFooterRecommendRead", () => { return this.blockeFooterRecommendRead(); }); Panel.execMenu("JianShuShieldUserCommentsMobile", () => { return this.blockUserComments(); }); }, addCSS() { Jianshu.addCSS(); }, blockeFooterRecommendRead() { log.info("屏蔽底部推荐阅读"); return CommonUtil.addBlockCSS("#recommended-notes"); }, handlePrototype() { log.info("处理原型添加script标签"); let originalAppendChild = Node.prototype.appendChild; _unsafeWindow.Node.prototype.appendChild = function(element) { let allowElementLocalNameList = ["img"]; if (element.src && !element.src.includes("jianshu.io") && !allowElementLocalNameList.includes(element.localName)) { log.success(["禁止添加的元素", element]); return null; } else { return originalAppendChild.call(this, element); } }; }, blockUserComments() { log.info("屏蔽评论区"); return CommonUtil.addBlockCSS("#comment-main"); } }; const PanelComponents = { $data: { __storeApiFn: null, get storeApiValue() { if (!this.__storeApiFn) { this.__storeApiFn = new Utils.Dictionary(); } return this.__storeApiFn; } }, getStorageApi(type) { if (!this.hasStorageApi(type)) { return; } return this.$data.storeApiValue.get(type); }, hasStorageApi(type) { return this.$data.storeApiValue.has(type); }, setStorageApi(type, storageApiValue) { this.$data.storeApiValue.set(type, storageApiValue); }, initComponentsStorageApi(type, config, storageApiValue) { let propsStorageApi; if (this.hasStorageApi(type)) { propsStorageApi = this.getStorageApi(type); } else { propsStorageApi = storageApiValue; } this.setComponentsStorageApiProperty(config, propsStorageApi); }, setComponentsStorageApiProperty(config, storageApiValue) { Reflect.set(config.props, PROPS_STORAGE_API, storageApiValue); } }; const UISwitch = function(text, key, defaultValue, clickCallBack, description, afterAddToUListCallBack, disabled, valueChangeCallBack) { let result = { text, type: "switch", description, disabled, attributes: {}, props: {}, getValue() { let storageApiValue = this.props[PROPS_STORAGE_API]; let value = storageApiValue.get(key, defaultValue); return value; }, callback(event, __value) { let value = Boolean(__value); log.success(`${value ? "开启" : "关闭"} ${text}`); let storageApiValue = this.props[PROPS_STORAGE_API]; storageApiValue.set(key, value); }, afterAddToUListCallBack }; Reflect.set(result.attributes, ATTRIBUTE_KEY, key); Reflect.set(result.attributes, ATTRIBUTE_DEFAULT_VALUE, defaultValue); PanelComponents.initComponentsStorageApi( "switch", result, { get(key2, defaultValue2) { return Panel.getValue(key2, defaultValue2); }, set(key2, value) { Panel.setValue(key2, value); } } ); return result; }; const SettingUIMobile = { id: "jianshu-panel-config-mobile", title: "移动端", forms: [ { text: "", type: "forms", forms: [ { text: "功能", type: "deepMenu", forms: [ { text: "", type: "forms", forms: [ UISwitch( "自动展开全文", "JianShuAutoExpandFullText_Mobile", true ), UISwitch( "重定向链接", "JianShuAutoJumpRedirect_Mobile", true, void 0, "自动跳转简书拦截的Url链接" ) ] } ] }, { text: "屏蔽", type: "deepMenu", forms: [ { text: "", type: "forms", forms: [ UISwitch( "【屏蔽】底部推荐阅读", "JianShuremoveFooterRecommendRead", false ), UISwitch( "【屏蔽】评论区", "JianShuShieldUserCommentsMobile", false ) ] } ] }, { text: "劫持/拦截", type: "deepMenu", forms: [ { text: "", type: "forms", forms: [ UISwitch( "拦截-剪贴板", "JianShuRemoveClipboardHijacking_Mobile", true, void 0, "去除禁止复制" ), UISwitch( "劫持-唤醒/跳转App", "JianShuHijackSchemeScriptLabel_Mobile", true, void 0, "去除简书唤醒调用App" ) ] } ] } ] } ] }; const UISelect = function(text, key, defaultValue, data, selectCallBack, description, valueChangeCallBack) { let selectData = []; if (typeof data === "function") { selectData = data(); } else { selectData = data; } let result = { text, type: "select", description, attributes: {}, props: {}, getValue() { let storageApiValue = this.props[PROPS_STORAGE_API]; return storageApiValue.get(key, defaultValue); }, callback(event, isSelectedValue, isSelectedText) { let value = isSelectedValue; log.info(`选择:${isSelectedText}`); if (typeof selectCallBack === "function") { let result2 = selectCallBack(event, value, isSelectedText); if (result2) { return; } } let storageApiValue = this.props[PROPS_STORAGE_API]; storageApiValue.set(key, value); }, data: selectData }; Reflect.set(result.attributes, ATTRIBUTE_KEY, key); Reflect.set(result.attributes, ATTRIBUTE_DEFAULT_VALUE, defaultValue); PanelComponents.initComponentsStorageApi( "select", result, { get(key2, defaultValue2) { return Panel.getValue(key2, defaultValue2); }, set(key2, value) { Panel.setValue(key2, value); } } ); return result; }; const SettingUICommon = { id: "jianshu-panel-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弹出的顺序" ) ] } ] }; const SettingUIPC = { id: "jianshu-panel-config-pc", title: "桌面端", forms: [ { text: "", type: "forms", forms: [ { text: "功能", type: "deepMenu", forms: [ { text: "", type: "forms", forms: [ UISwitch("全文居中", "JianShuArticleCenter", true), UISwitch("自动展开全文", "JianShuAutoExpandFullText", true), UISwitch( "重定向链接", "JianShuAutoJumpRedirect_PC", true, void 0, "自动跳转简书拦截的Url链接" ) ] } ] }, { text: "屏蔽", type: "deepMenu", forms: [ { text: "", type: "forms", forms: [ UISwitch( "【屏蔽】底部推荐阅读", "JianShuShieldRecommendedReading", false ), UISwitch("【屏蔽】评论区", "JianShuShieldUserComments", false), UISwitch( "【屏蔽】相关文章", "JianShuShieldRelatedArticles", false ), UISwitch( "【屏蔽】客户端弹窗", "jianshu-shieldClientDialog", true, void 0, "弹出的【扫码安装简书客户端 畅享全文阅读体验】" ), UISwitch("【屏蔽】顶部导航栏", "jianshu-shieldTopNav", false), UISwitch( "【屏蔽】底部工具栏", "jianshu-shieldBottomToolbar", false, void 0, "屏蔽掉底部悬浮的评论输入框、评论、点赞..." ) ] } ] }, { text: "劫持/拦截", type: "deepMenu", forms: [ { text: "", type: "forms", forms: [ UISwitch( "拦截-剪贴板", "JianShuRemoveClipboardHijacking", true, void 0, "去除禁止复制" ) ] } ] } ] } ] }; PanelContent.addContentConfig([SettingUICommon, SettingUIPC, SettingUIMobile]); Panel.init(); let isMobile = utils.isPhone(); let CHANGE_ENV_SET_KEY = "change_env_set"; let chooseMode = _GM_getValue(CHANGE_ENV_SET_KEY); GM_Menu.add({ key: CHANGE_ENV_SET_KEY, text: `⚙ 自动: ${isMobile ? "移动端" : "PC端"}`, autoReload: false, isStoreValue: false, showText(text) { if (chooseMode == null) { return text; } return text + ` 手动: ${chooseMode == 1 ? "移动端" : chooseMode == 2 ? "PC端" : "未知"}`; }, callback: () => { let allowValue = [0, 1, 2]; let chooseText = window.prompt( "请输入当前脚本环境判定\n\n自动判断: 0\n移动端: 1\nPC端: 2", "0" ); if (!chooseText) { return; } let chooseMode2 = parseInt(chooseText); if (isNaN(chooseMode2)) { Qmsg.error("输入的不是规范的数字"); return; } if (!allowValue.includes(chooseMode2)) { Qmsg.error("输入的值必须是0或1或2"); return; } if (chooseMode2 == 0) { _GM_deleteValue(CHANGE_ENV_SET_KEY); } else { _GM_setValue(CHANGE_ENV_SET_KEY, chooseMode2); } } }); if (chooseMode != null) { log.info(`手动判定为${chooseMode === 1 ? "移动端" : "PC端"}`); if (chooseMode == 1) { M_Jianshu.init(); } else if (chooseMode == 2) { Jianshu.init(); } else { Qmsg.error("意外,手动判定的值不在范围内"); _GM_deleteValue(CHANGE_ENV_SET_KEY); } } else { if (isMobile) { log.info("自动判定为移动端"); M_Jianshu.init(); } else { log.info("自动判定为PC端"); Jianshu.init(); } } })(Qmsg, DOMUtils, Utils, pops);