// ==UserScript== // @name 万能去广告+隐私保护 · 合一版 // @namespace https://greasyfork.org/zh-CN/users/ayu // @version 2.0.0 // @description 全能去广告+隐私保护:清除广告容器、智能弹窗清理、视频广告自动跳过与16倍速快进、反反广告拦截、滚动解锁、百度/CSDN/知乎/B站专属净化;隐私保护含清Cookie/Storage、剥离追踪参数、拦截统计脚本、降低浏览器指纹、清除Referrer。无面板,装上即生效,全自动运行。 // @author 阿宇 // @match *://*/* // @exclude *://*icbc.com.cn/* // @exclude *://*ccb.com/* // @exclude *://*boc.cn/* // @exclude *://*abchina.com/* // @exclude *://*alipay.com/* // @exclude *://*.bank*/* // @run-at document-start // @grant GM_addStyle // @license MIT // ==/UserScript== (function () { 'use strict'; /* ========== 一、广告关键词与规则库 ========== */ const AD_KEYWORDS = [ 'adsbygoogle', 'adsense', 'advertis', 'ad-container', 'adcontainer', 'ad-wrapper', 'adwrapper', 'ad-box', 'adbox', 'ad-banner', 'adbanner', 'ad-slot', 'adslot', 'ad-area', 'ad-layer', 'adlayer', 'ad-float', 'adfloat', 'ad-pop', 'adpop', 'ad-frame', 'adframe', 'ad-widget', 'adwidget', 'ad-block', 'adblock-container', 'ads-container', 'ads-wrap', 'adswrap', 'ads-box', 'ads-banner', 'ads-slot', 'banner-ads', 'sidebar-ads', 'float-ads', 'pop-ads', 'popup-ads', 'sponsor-ads', 'native-ad', 'nativead', 'taboola', 'outbrain', 'pub_300x250', 'pub_728x90', 'pub_250x250', 'pub_160x600', 'ad-300x250', 'ad-728x90', '300x250-ad', 'gg300', 'gg250', 'ads300', 'ads250', 'cpro', 'ec-tuiguang', 'ec_ad', 'baidu-ad', 'bd-ad', 'ad-mask', 'banner', 'popup', 'splash', 'modal-ad', 'promo', 'promotion', 'sponsor', 'google_ads', 'data-ad', 'ggad', 'ad-right', 'ad-left', 'side-ad', 'top-ad', 'bottom-ad', 'tracker', 'analytics', 'float-ad', 'floatAd' ]; const AD_IFRAME_HOSTS = [ 'doubleclick.net', 'googlesyndication.com', 'googleadservices.com', 'adnxs.com', 'advertising.com', 'amazon-adsystem.com', 'criteo.com', 'taboola.com', 'outbrain.com', 'pubmatic.com', 'rubiconproject.com', 'openx.net', 'casalemedia.com', 'adtech.com', 'serving-sys.com', '360yield.com', 'pos.baidu.com', 'cbjs.baidu.com', 'eclick.baidu.com', 'cpro.baidu', 'popads.net', 'popcash.net', 'exoclick.com', 'juicyads.com', 'hilltopads.net', 'ad-master', 'adservice', 'showad', 'ads', 'advert', 'baidu.com/cpro' ]; const BLOCKED_SCRIPT_HOSTS = [ 'googlesyndication.com', 'doubleclick.net', 'googleadservices.com', 'baidu.com/cpro', 'tanx.com', 'alimama.com', 'tbcdn.cn', 'umeng.com', 'umengcloud.com', 'cnzz.com', 'scorecardresearch.com', 'quantserve.com', 'nr-data.net', 'hotjar.com', 'google-analytics.com', 'googletagmanager.com', 'gtag/js', 'analytics.js', 'facebook.net', 'connect.facebook.net', 'ads-twitter.com', 'analytics.twitter.com', 't.co', 'bing.com/ads', 'clarity.ms', 'microsoft.clarity', 'sentry.io', 'bugsnag.com', 'datadoghq.com', 'baidu.com/hm.js', 'bdstatic.com/hm', 'hm.baidu.com', 'gtimg.com/qq', 'qq.com/ptlogin', 'qq.com/cgi-bin/report', 'alipayobjects.com/oss', 'amap.com/log' ]; const ANTI_ADBLOCK_SELECTORS = [ '[class*="adblock"]', '[id*="adblock"]', '[class*="anti-adblock"]', '[id*="anti-adblock"]', '[class*="anti-ad"]', '[id*="anti-ad"]', '[class*="disable-adblock"]', '[class*="please-disable"]', '[class*="ad-blocker-detected"]', '[class*="adblocker-detected"]', '[class*="ads-not-allowed"]', '[class*="support-us"]' ]; const POPUP_KW = [ '下载app', '打开app', '打开应用', '扫码下载', '立即下载app', '订阅我们', 'newsletter', '订阅最新', '开启通知', '开启消息通知', '猜你喜欢', '热门推荐下载', 'ad-popup', 'app-download' ]; const SKIP_CLASS = [ '.ytp-ad-skip-button', '.ytp-ad-skip-button-modern', '[class*="ad-skip"]', '[class*="skip-ad"]', '[class*="skipad"]' ]; const SKIP_TEXT = ['跳过广告', 'skip ad', 'skip ads', '跳过此广告', '跳过推广']; const AD_PLAYING = [ '.ad-showing', '.ytp-ad-player-overlay', '[class*="ad-playing"]', '[class*="video-ad"]', '[class*="adshowing"]' ]; const TRACKING_PARAMS = [ 'utm_source','utm_medium','utm_campaign','utm_term','utm_content', 'utm_id','utm_cid','utm_reader','utm_referrer','utm_social', 'fbclid','gclid','gbraid','wbraid','msclkid','mc_cid','mc_eid', '_hsenc','_hsmi','__hssc','__hstc','hsCtaTracking', 'yclid','_openstat','vero_id','wickedid','oly_anon_id','oly_enc_id', 'rb_clickid','twclid','igshid','ttclid','scid','s_cid', 'ref','referrer','source','campaign_id','ad_id','adset_id', 'spm','from','sourceType','share_source','share_medium', 'v','_from','_wv','_ts','bili_source','redirect_from' ]; /* ========== 二、构建选择器并注入 CSS ========== */ const AD_SELECTORS = AD_KEYWORDS .map(k => `[class*="${k}"],[id*="${k}"]`) .concat(ANTI_ADBLOCK_SELECTORS) .join(',\n'); GM_addStyle(` ${AD_SELECTORS} { display: none !important; visibility: hidden !important; } /* 百度搜索结果广告 */ .result-op.c-container.xpath-log, .result.c-container[data-click*="rsv_ad_"], [mu*="rsv.ad"], .c-container[data-tuiguang], #content_left .c-container[data-ad], div[class*="推广"] { display: none !important; } /* 百度首页信息流广告卡片 */ #s_top_wrap .s-top-left-ad, .s-top-feed-item[class*="ad"], #head .s-news-list-wrapper li[class*="ad"] { display: none !important; } /* CSDN:登录弹窗、VIP、广告位 */ .passport-login-mark, .passport-login-pop, .adblock, .adsbygoogle, .recommend-ad, .blog_container_aside, .csdn-common-logo-ad, #dmp_ad_58, #csdn-toolbar-feedback, .csdn-side-toolbar .has-button, .recommend-tit-mod, .extension_ul, [class*="more-plugin"], [class*="aside-box"] { display: none !important; } #article_content, .article_content, .markdown_views { user-select: text !important; -webkit-user-select: text !important; } /* 知乎:广告、登录弹窗 */ .AdTag, .TopstoryItem--advertCard, [class*="Advert"], [class*="adCard"], .Modal-closeButton ~ .Modal-content { display: none !important; } /* B站:广告、推广 */ .ad-report, .bili-ad, [class*="ad-report"], [class*="bili-video-card__wrap"][class*="ad"], .video-page-special-card-small, [class*="card-mark-ad"] { display: none !important; } /* 微博:广告 */ [class*="ad-"], [class*="card_ad"], [class*="wbpro-side-ad"], [action-type="feed_list_ad"], [class*="weibo_ad"] { display: none !important; } /* 简书:广告 */ .ad-card, [class*="advertise"] { display: none !important; } /* 视频站:暂停广告、弹窗 */ [class*="pause-ad"], [class*="puase-ad"], [class*="preroll-ad"], [class*="midroll-ad"], [class*="video-ad"] { display: none !important; } `); /* ========== 三、防误删保护 ========== */ function isSafeToRemove(el, allowFullscreen) { if (!el || el.nodeType !== 1) return false; const tag = el.tagName; if (tag === 'BODY' || tag === 'HTML') return false; if (el.closest('video,audio')) return false; if (!allowFullscreen) { const r = el.getBoundingClientRect(); if (r.width > innerWidth * 0.95 && r.height > innerHeight * 0.95) return false; } const txt = el.textContent || ''; if (txt.length > 1500) return false; return true; } /* ========== 四、清除广告容器 ========== */ function cleanAds() { try { document.querySelectorAll(AD_SELECTORS).forEach(el => { if (isSafeToRemove(el) && el.parentNode) el.remove(); }); } catch (e) {} // 广告联盟 iframe try { document.querySelectorAll('iframe').forEach(f => { const src = f.src || ''; if (AD_IFRAME_HOSTS.some(h => src.includes(h))) { if (isSafeToRemove(f)) f.remove(); } }); } catch (e) {} } /* ========== 五、智能弹窗/遮罩清理 ========== */ function cleanPopups() { const els = document.querySelectorAll('body > div, body > section, body > aside, body > span'); for (const el of els) { const r = el.getBoundingClientRect(); if (r.width < 180 || r.height < 90) continue; const st = getComputedStyle(el); if (st.position !== 'fixed' && st.position !== 'absolute') continue; const txt = (el.textContent || '').toLowerCase(); let hitKw = POPUP_KW.some(k => txt.indexOf(k.toLowerCase()) !== -1); const isOverlay = r.width >= innerWidth * 0.7 && r.height >= innerHeight * 0.6; const hasForm = !!el.querySelector('form, input, textarea'); const hasMedia = !!el.querySelector('video, canvas'); if ((hitKw || (isOverlay && !hasForm)) && !hasMedia) { if (isSafeToRemove(el, true)) { el.remove(); unlockScroll(); } } } } /* ========== 六、跳过视频广告 ========== */ function skipVideoAd() { let btns; try { btns = document.querySelectorAll('button, a, ' + SKIP_CLASS.join(', ')); } catch (e) { return; } for (const el of btns) { if (el.offsetParent === null && !el.matches(SKIP_CLASS.join(','))) continue; const t = (el.textContent || '').trim().toLowerCase(); if (!t || t.length > 24) continue; let hit = el.matches(SKIP_CLASS.join(',')); if (!hit) hit = SKIP_TEXT.some(s => t.indexOf(s) !== -1); if (hit) el.click(); } } /* ========== 七、视频广告 16 倍速快进 ========== */ const savedRate = new WeakMap(); function fastForwardAd() { let playing = false; try { playing = !!document.querySelector(AD_PLAYING.join(', ')); } catch (e) { return; } document.querySelectorAll('video').forEach(v => { if (playing) { if (!savedRate.has(v)) savedRate.set(v, v.playbackRate); v.muted = true; v.playbackRate = 16; } else if (savedRate.has(v)) { v.playbackRate = savedRate.get(v); savedRate.delete(v); } }); } /* ========== 八、反反广告拦截 ========== */ function antiAnti() { try { document.querySelectorAll(ANTI_ADBLOCK_SELECTORS.join(',')).forEach(el => { if (el.tagName === 'BODY' || el.tagName === 'HTML') return; const r = el.getBoundingClientRect(); if (r.width >= innerWidth * 0.9 && r.height >= innerHeight * 0.8) { el.remove(); unlockScroll(); } }); } catch (e) {} // 自动点击"关闭广告拦截"类按钮 try { document.querySelectorAll('button, .close, [class*="close"]').forEach(btn => { const t = (btn.innerText || btn.title || '').trim(); if (/关闭|我知道了|继续浏览|无视/.test(t)) { const box = btn.closest('[class*="adblock"], [class*="detected"], [id*="adblock"], [class*="modal"]'); if (box && /广告|adblock/i.test(box.innerText || '')) btn.click(); } }); } catch (e) {} } /* ========== 九、解除滚动锁定 ========== */ function unlockScroll() { [document.documentElement, document.body].forEach(el => { if (!el) return; const st = getComputedStyle(el); if (st.overflow === 'hidden' || st.overflowY === 'hidden') { el.style.setProperty('overflow', 'visible', 'important'); el.style.setProperty('overflow-y', 'visible', 'important'); } if (st.position === 'fixed') { el.style.setProperty('position', 'static', 'important'); } }); } /* ========== 十、站点专属清理 ========== */ function siteSpecificClean() { const host = location.hostname; if (host.includes('baidu.com')) { document.querySelectorAll('.result.c-container, .result-op.c-container').forEach(r => { const click = r.getAttribute('data-click') || ''; if (/rsv_ad|tuiguang|promote/i.test(click)) { if (isSafeToRemove(r)) r.remove(); return; } if (r.querySelector('.c-icon-mark, .c-color-text[data-mark="ad"], [class*="推广"]')) { if (isSafeToRemove(r)) r.remove(); } }); document.querySelectorAll('#s_top_wrap li, .s-news-list-wrapper li').forEach(li => { if (/广告|推广/.test(li.innerText || '') && !li.querySelector('a[href*="baidu.com/link?"]')) { const adTag = li.querySelector('[class*="ad"], [class*="推广"]'); if (adTag && isSafeToRemove(li)) li.remove(); } }); } if (host.includes('csdn.net')) { document.querySelectorAll('.passport-login-pop .close, .login-mark + .passport-login-pop .close').forEach(b => b.click && b.click()); document.addEventListener('copy', e => e.stopPropagation(), true); document.addEventListener('contextmenu', e => e.stopPropagation(), true); document.addEventListener('selectstart', e => e.stopPropagation(), true); } if (host.includes('zhihu.com')) { const close = document.querySelector('.Modal-closeButton'); if (close) close.click(); } } /* ========== 十一、隐私保护 ========== */ // 剥离链接追踪参数 function stripTrackingParams(url) { try { const u = new URL(url, location.href); let changed = false; TRACKING_PARAMS.forEach(p => { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : null; } catch (e) { return null; } } function cleanAllLinks(root) { if (!root || root.nodeType !== 1) return; root.querySelectorAll('a[href]').forEach(a => { const cleaned = stripTrackingParams(a.getAttribute('href')); if (cleaned) a.setAttribute('href', cleaned); }); } // 降低浏览器指纹 (function reduceFingerprint() { try { Object.defineProperty(navigator, 'webdriver', { get: () => false, configurable: true }); } catch (e) {} try { const getImageData = CanvasRenderingContext2D.prototype.getImageData; CanvasRenderingContext2D.prototype.getImageData = function () { try { const imgData = getImageData.apply(this, arguments); const d = imgData.data; for (let i = 0; i < d.length; i += 4) d[i] = (d[i] + 1) & 0xff; return imgData; } catch (e) { return getImageData.apply(this, arguments); } }; } catch (e) {} try { const getParameter = WebGLRenderingContext.prototype.getParameter; WebGLRenderingContext.prototype.getParameter = function (p) { if (p === 37445 || p === 37446) return ''; return getParameter.apply(this, arguments); }; } catch (e) {} })(); // 清除 referrer const refMeta = document.createElement('meta'); refMeta.name = 'referrer'; refMeta.content = 'no-referrer'; document.head.appendChild(refMeta); // 清 Cookie / Storage function clearTrackingData() { document.cookie.split(';').forEach(c => { const name = c.split('=')[0].trim(); if (!name) return; document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=' + location.hostname; document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; }); try { const ls = localStorage, ss = sessionStorage; for (let i = ls.length - 1; i >= 0; i--) ls.removeItem(ls.key(i)); for (let i = ss.length - 1; i >= 0; i--) ss.removeItem(ss.key(i)); } catch (e) {} } window.addEventListener('beforeunload', clearTrackingData); window.addEventListener('pagehide', clearTrackingData); clearTrackingData(); // 拦截广告/统计脚本 const scriptObserver = new MutationObserver(muts => { for (const m of muts) { for (const n of m.addedNodes) { if (n.nodeType === 1 && n.tagName === 'SCRIPT') { const src = n.src || ''; if (BLOCKED_SCRIPT_HOSTS.some(h => src.includes(h))) n.remove(); } } } }); if (document.documentElement) { scriptObserver.observe(document.documentElement, { childList: true, subtree: true }); } // 持续清理追踪链接 const linkObserver = new MutationObserver(muts => { for (const m of muts) { for (const n of m.addedNodes) { if (n.nodeType === 1) cleanAllLinks(n); } } }); if (document.documentElement) { linkObserver.observe(document.documentElement, { childList: true, subtree: true }); } cleanAllLinks(document.documentElement); /* ========== 十二、调度执行 ========== */ let scheduled = false; function schedule() { if (scheduled) return; scheduled = true; setTimeout(() => { scheduled = false; run(); }, 400); } function run() { try { cleanAds(); cleanPopups(); skipVideoAd(); fastForwardAd(); antiAnti(); unlockScroll(); siteSpecificClean(); } catch (e) {} } function boot() { run(); const mo = new MutationObserver(schedule); mo.observe(document.documentElement, { childList: true, subtree: true }); setInterval(run, 3000); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', boot); } else { boot(); } window.addEventListener('load', () => setTimeout(run, 500)); console.log('[万能去广告+隐私保护 v2.0] 已启动:去广告 + 视频跳过 + 隐私保护'); })();