// ==UserScript== // @name 智能广告脚本移除助手 // @namespace https://greasyfork.org/zh-CN/users/1373566 // @version 1.0.0 // @license MIT // @description 🛡️ 智能移除网页内嵌广告脚本,支持自定义关键词和网站排除。本工具仅为学习研究用途,请尊重网站服务条款。支持开发者:点击设置面板中的"支持开发者"。 // @author 智能辅助工具 // @homepageURL https://scriptcat.org/zh-CN/script-show-page/2796 // @supportURL https://github.com/user/script-issues // @match http*://*/* // @exclude *://*.baidu.*/* // @exclude *://*.bing.*/* // @exclude *://*.douban.com/* // @exclude *://*.douyin.com/* // @exclude *://*.github.com/* // @exclude *://*.google.*/* // @exclude *://*.ifeng.com/* // @exclude *://*.iqiyi.com/* // @exclude *://*.mgtv.com/* // @exclude *://*.pptv.com/* // @exclude *://*.qq.com/* // @exclude *://*.sina.com.cn/* // @exclude *://*.sohu.com/* // @exclude *://*.v.qq.com/* // @exclude *://*.wandoujia.com/* // @exclude *://*.yandex.*/* // @exclude *://github.com/* // @exclude *://greasyfork.org/* // @exclude *://m.douban.com/* // @exclude *://scriptcat.org/* // @exclude *://twitter.com/* // @exclude *://x.com/* // @exclude *://*.wikipedia.org/* // @exclude *://*.openai.com/* // @exclude *://*.anthropic.com/* // @exclude *://*.deepseek.com/* // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAXhSURBVGiB7VpdbBRVGD3n7g/bH8v2JynsNgTa7hIbfdhqIoIao2IkQSVAK9KWogRMiDHRB19MSH3QFxONJiY2sUJxS7RJI/iiRhEDhCaaFqix0XbbIukfFNqCLdB2dz4furudtruzs5XsqulJNpn7zZlvzrnz3bl3ZpaIDWt5efljAMpExB6HkzKQnAbQ2d7efhpAcN6+hWSfz/ckyXqSJakSaBYiEiB5oK2t7VQkNs+Az+fbQvI4ybT3ejyIyDSA59vb278FdAbKysqyHQ5HF8nVaVNnEiIyG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LMNr1lpHJkYiGv1J+Xo5gxADAbYHauY8WOa8CRhTy9leJGt8dqwQ6Ar4FYFd0BNHdVDf6QUJspA0pFy0EELbHEA0CgevQmBMejgXhlJNzlaXK3epvcV61W/gHyXb14gbSO3pnab0pbIoK3Md8twKZwYhGhUY9CKI3RBvGot7nIvZBDopTgBoAF844V0USkfnJCnopZejGQsIS0kG2aVk4BcBDo7u7pP23E77YNnvLOuC8BXEtAcDviRfszfn/JdSFPBIP8sK+2v8OMcNMGAi8PjxT73Vst5OYQ2JDw3l6JUKhJ26nEclCAbwK1/QMAMGafecc5Y58huFqg3RLBdZKXRdM6AreGfk10t1myAQDorR44CeCk2aQ9VUNtAPbpYyOVIxMjwKHk5CXG8muVdGPZQLrx/zUQDAYTrtpTiRh6BJhvYDyyQZJOp/OBVAgzi/z8/AfJeW9CxoD580ArgAORhlLqS5/P9z7JtH+lFJE8EXldr19EzgELvhNnZGR0A3OLqn8r9N+JoyXU2dk5ISJ7RWQqneJM4I6maXs7OjomAcCi3zM0NNRTWFh4luQmkvnp0WeI30Wk8vz587H/K6GD1efzbcTs01FWSqQZgOQEyd/a2tpaAYTSreeu4m8HsQDCyNnessAAAABJRU5ErkJggg== // @grant GM_setValue // @grant GM_getValue // @grant GM_getResourceText // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_notification // @grant GM_xmlhttpRequest // @resource license https://raw.githubusercontent.com/user/license/master/EULA.txt // @run-at document-start // @connect * // ==/UserScript== (function() { 'use strict'; // ============================================ // 免责声明和法律条款 // ============================================ const DISCLAIMER = `免责声明: 1. 本脚本仅供学习和研究目的使用 2. 使用本脚本前,请确认您有权限修改目标网页 3. 本脚本移除广告可能违反网站服务条款 4. 开发者不对使用本脚本导致的任何后果负责 5. 请支持您喜爱的网站,考虑将他们的广告加入白名单`; const USER_AGREEMENT = `用户协议: 1. 您确认已年满18周岁 2. 您确认遵守当地法律法规 3. 您理解并接受使用风险 4. 您同意仅在合法范围内使用本工具 5. 您承诺不将本工具用于商业用途`; // ============================================ // 配置存储键名 // ============================================ const STORAGE_KEYS = { KEYWORDS: 'removeAdScriptsKeywords', EXCLUDE_SITES: 'excludeSites', SPOOF_UA_SITES: 'spoofUASites', SPOOF_UA_GLOBAL_MODE: 'spoofUAGlobalMode', SPOOF_UA_EXCLUDE: 'spoofUAExcludeSites', TOTAL_REMOVED: 'totalRemovedCount', USER_AGREEMENT_ACCEPTED: 'userAgreementAccepted', LAST_SHOW_DISCLAIMER: 'lastShowDisclaimer', SCRIPT_HASHES: 'blockedScriptHashes', // 记录已拦截脚本的哈希 SITE_SPECIFIC_RULES: 'siteSpecificRules', // 站点特定规则 LEARNING_MODE: 'learningModeEnabled', PERFORMANCE_STATS: 'performanceStats' }; // ============================================ // 默认配置 // ============================================ const DEFAULT_CONFIG = { KEYWORDS: [ 'htmlAds', '_ffc1();', '_ffc2();', '_ffc3();', '_ffc4();', '_ffp();', 'kbbaidu1();', 'kbbaidu2();', 'kbbaidu3();', 'html5player.checkVideoAds', 'ads_codes', '{return void 0!==b[a]?b[a]:a}).join("")}', '${scripts[randomIndex]}', '${scripts[Math.random()', '"https://"+Date.parse(new Date())+', '"https://"+(new Date().getDate())+', 'https://hongosi.xn--', 'https://{randomstr}.', 'new Function(t)()', 'new Function(b)()', 'new Function(c)()', 'new Function(t);', 'new Function(b);', 'new Function(c);', 'new Function(\'d\',e)', 'new Function(document[', 'new Function(function(p,a,c,k,e,d)', 'function a(a){', 'function b(b){', 'function c(c){', 'function updateCarousel()', 'Math.floor(2147483648 * Math.random());', 'Math.floor(Math.random()*url.length)', 'Math.floor(Math.random() * urls.length)', 'new Date()[\'getTime\']()', 'newDate=new window', 'Math.floor(((new Date()).getTime()', '&&navigator[', '=navigator;', 'navigator.platform){setTimeout(function', 'disableDebugger', 'blockDeveloperTools', '["Date"]())[\'getTime\']()', '\'+\'s\'+\'c\'+\'ri\'+\'pt\'+\'>\');', '<\\/\'+\'s\'+\'c\'+\'ri\'+\'pt\'+\'>\');', 'class=\\"zdhf\\"', '(\'#htmlContenthtml\').html', 'D.createElement(\'span\');', 'class=\\"app_tj\\"', 'window.$m(', 'jsjiami.com.v4', 'histats.com', 'hm.baidu.com', 'adbyunion', '{win:false,mac:false,xll:false}', 'mainCell:".bd",effect:"leftLoop"', '/invoke.js">', 'function|getDate', 'parseInt(Math[\'random\']', 'pc.stgowan.com', 'google-analytics.com', 'doubleclick.net', 'googlesyndication.com', 'amazon-adsystem.com', 'adsystem.com', 'adnxs.com', 'openx.net', 'rubiconproject.com', 'pubmatic.com', 'criteo.com', 'taboola.com', 'outbrain.com', 'revcontent.com', 'mgid.com', 'zemanta.com', 'content.ad', 'nativeads.com', 'triplelift.com', 'sharethrough.com', 'yahoo.com', 'yimg.com', 'yieldmo.com', 'spotxchange.com', 'spotx.tv', 'freewheel.tv', 'teads.tv', 'distroscale.com', 'sovrn.com', 'appnexus.com', 'indexexchange.com', 'improvedigital.com', 'a9.com', 'amazon.com', 'facebook.com/tr/', 'fbq(', 'connect.facebook.net', 'twitter.com/i/jot', 'pinterest.com/ct.html', 'linkedin.com/li/track', 't.co/i/adsct', 'redditstatic.com/ads', 'adsafeprotected.com', 'casalemedia.com', 'contextweb.com', 'lijit.com', 'sonobi.com', 'undertone.com', 'videologygroup.com', 'brightcom.com', 'springserve.com', 'uniconsent.com', 'quantcast.mgr.consensu.org', 'consensu.org', 'iab.com', 'iabtechlab.com', 'adsrvr.org', 'adsymptotic.com', 'adtech.com', 'advertising.com', 'aerserv.com', 'amobee.com', 'audiencescience.com', 'bidswitch.net', 'brightroll.com', 'c.amazon-adsystem.com', 'c.amazon-adsystem.com/aax2/apstag.js', 'c.amazon-adsystem.com/aax2/apstag.js#sync', 'c.amazon-adsystem.com/aax2/amzn_ads.js', 'c.amazon-adsystem.com/aax2/amzn_ads.js#sync', 'c.amazon-adsystem.com/aax2/3p/amzn_ads.js', 'c.amazon-adsystem.com/aax2/3p/amzn_ads.js#sync', 'c.amazon-adsystem.com/aax2/3p/aps.js', 'c.amazon-adsystem.com/aax2/3p/aps.js#sync', 'c.amazon-adsystem.com/aax2/3p/aps_async.js', 'c.amazon-adsystem.com/aax2/3p/aps_async.js#sync', 'c.amazon-adsystem.com/aax2/3p/aps_tag.js', 'c.amazon-adsystem.com/aax2/3p/aps_tag.js#sync', 'c.amazon-adsystem.com/aax2/3p/aps_tag_async.js', 'c.amazon-adsystem.com/aax2/3p/aps_tag_async.js#sync' ], EXCLUDED_SITES: [ '*.baidu.*', '*.bing.*', '*.douban.com', '*.douyin.com', '*.github.com', '*.google.*', '*.ifeng.com', '*.iqiyi.com', '*.mgtv.com', '*.pptv.com', '*.qq.com', '*.sina.com.cn', '*.sohu.com', '*.v.qq.com', '*.wandoujia.com', '*.yandex.*', 'github.com', 'greasyfork.org', 'm.douban.com', 'scriptcat.org', 'twitter.com', 'x.com', '*.wikipedia.org', '*.openai.com', '*.anthropic.com', '*.deepseek.com' ], WHITELISTED_SITES: [ 'wikipedia.org', 'stackoverflow.com', 'stackexchange.com', 'medium.com', 'reddit.com', 'quora.com', 'patreon.com', 'ko-fi.com', 'buymeacoffee.com' ] }; // ============================================ // 工具函数 // ============================================ class Utils { static hashString(str) { let hash = 0; for (let i = 0; i < str.length; i++) { const char = str.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash = hash & hash; } return hash.toString(36); } static escapeRegex(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } static isSiteExcluded(hostname, excludeList) { return excludeList.some(pattern => { if (pattern.includes('*')) { const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\./g, '\\.') + '$'); return regex.test(hostname); } return hostname === pattern || hostname.endsWith('.' + pattern); }); } static formatNumber(num) { if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M'; if (num >= 1000) return (num / 1000).toFixed(1) + 'k'; return num.toString(); } static getCurrentDomain() { return window.location.hostname.replace(/^www\./, ''); } static async loadLicense() { try { const licenseText = await GM_getResourceText('license'); return licenseText || 'MIT License - 仅供学习研究使用'; } catch (e) { return 'MIT License - 仅供学习研究使用'; } } } // ============================================ // 主应用类 // ============================================ class AdRemover { constructor() { this.keywords = GM_getValue(STORAGE_KEYS.KEYWORDS, []); this.excludeSites = GM_getValue(STORAGE_KEYS.EXCLUDE_SITES, []); this.spoofUASites = GM_getValue(STORAGE_KEYS.SPOOF_UA_SITES, []); this.spoofUAExclude = GM_getValue(STORAGE_KEYS.SPOOF_UA_EXCLUDE, []); this.uaMode = GM_getValue(STORAGE_KEYS.SPOOF_UA_GLOBAL_MODE, 0); this.totalRemoved = GM_getValue(STORAGE_KEYS.TOTAL_REMOVED, 0); this.agreementAccepted = GM_getValue(STORAGE_KEYS.USER_AGREEMENT_ACCEPTED, false); this.blockedHashes = GM_getValue(STORAGE_KEYS.SCRIPT_HASHES, {}); this.siteRules = GM_getValue(STORAGE_KEYS.SITE_SPECIFIC_RULES, {}); this.learningMode = GM_getValue(STORAGE_KEYS.LEARNING_MODE, false); this.performanceStats = GM_getValue(STORAGE_KEYS.PERFORMANCE_STATS, { scriptsScanned: 0, scriptsBlocked: 0, averageTime: 0, lastReset: Date.now() }); this.removedScripts = []; this.observer = null; this.shadowRoot = null; this.regexCache = new Map(); this.processedScripts = new WeakSet(); this.performanceTimer = null; this.init(); } init() { this.showDisclaimerIfNeeded(); this.setupMutationObserver(); this.setupPerformanceMonitor(); this.initUASpoofing(); this.registerMenuCommands(); this.setupGlobalListeners(); this.scanExistingScripts(); } showDisclaimerIfNeeded() { const lastShow = GM_getValue(STORAGE_KEYS.LAST_SHOW_DISCLAIMER, 0); const now = Date.now(); const oneWeek = 7 * 24 * 60 * 60 * 1000; if (!this.agreementAccepted || (now - lastShow > oneWeek)) { this.showAgreementDialog(); } } async showAgreementDialog() { const license = await Utils.loadLicense(); const dialog = document.createElement('div'); dialog.style.cssText = ` position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); z-index: 2147483647; display: flex; align-items: center; justify-content: center; padding: 20px; `; dialog.innerHTML = `
本工具仅供学习、研究和合理使用目的。
${license}
点击"我已阅读并同意"即表示您接受以上条款
本工具会每隔7天提醒您查看协议
感谢您使用 AdRemover!本工具完全免费开源,由个人开发者维护。 如果您觉得这个工具对您有帮助,请考虑支持开发工作:
重要: 本工具仅供学习研究使用。
请尊重网站服务条款,合理使用。