// ==UserScript== // @name mk-playZip-BanJumpingAds // @namespace http://tampermonkey.net/ // @version 1.2 // @description 拦截playzip.com点击页面时弹出的广告跳转(阻断abcd.js广告脚本、handleAdClick注册及广告域名window.open弹窗) // @author byhgz // @icon https://static.hdslb.com/images/favicon.ico // @license Apache-2.0 // @run-at document-start // @match https://playzip.com/* // @grant none // ==/UserScript== (function(){'use strict';const TAG = "[mk-playzip]"; const AD_SCRIPT_RE = /\/abcd\.js(\?.*)?$/; const PAGE_PATCH = `(function () { var FLAG = '__mkPlayzipPagePatch'; if (window[FLAG]) return; window[FLAG] = true; var TAG = '[mk-playzip]'; var AD_HOSTS = ['jopeki.com', '23.225.187.244', 'brimvale.xyz', 'aiyeyu.org']; var origAdd = EventTarget.prototype.addEventListener; EventTarget.prototype.addEventListener = function (type, listener, options) { if (type === 'click' && typeof listener === 'function' && listener.name === 'handleAdClick') { console.warn(TAG, '已拦截 handleAdClick 注册, 目标:', this); return; } return origAdd.call(this, type, listener, options); }; function strip() { try { if (document.body && typeof window.handleAdClick === 'function') { document.body.removeEventListener('click', window.handleAdClick); } } catch (e) { } } strip(); setInterval(strip, 500); var origOpen = window.open.bind(window); window.open = function (url, target, features) { var href = url == null ? '' : String(url); var host = ''; try { host = new URL(href, location.href).hostname; } catch (e) { } if (AD_HOSTS.some(function (h) { return host === h || host.endsWith('.' + h); })) { console.warn(TAG, '已拦截广告弹窗:', href); return null; } return origOpen(url, target, features); }; console.info(TAG, '页面补丁已安装'); })();`; console.info(TAG, "脚本已加载, readyState:", document.readyState); function sweepExisting() { document.querySelectorAll("script").forEach((node) => { const src = node.src; if (AD_SCRIPT_RE.test(src)) { console.warn(TAG, "已移除现存广告脚本标签:", src); node.remove(); } }); } function watchNewScripts() { const mo = new MutationObserver((mutations) => { for (const m of mutations) { for (const node of m.addedNodes) { if (node instanceof HTMLScriptElement && AD_SCRIPT_RE.test(node.src)) { console.warn(TAG, "已阻断广告脚本:", node.src); node.remove(); } } } }); mo.observe(document, { childList: true, subtree: true }); } function onDocumentElement(fn) { if (document.documentElement) return fn(); const mo = new MutationObserver(() => { if (document.documentElement) { mo.disconnect(); fn(); } }); mo.observe(document, { childList: true, subtree: true }); } function installPagePatch() { try { (0, eval)(PAGE_PATCH); } catch (e) { console.warn(TAG, "当前世界 eval 补丁失败:", e); } onDocumentElement(() => { const s = document.createElement("script"); s.textContent = `document.documentElement.dataset.mkPlayzipPage='ok';` + PAGE_PATCH; (document.head || document.documentElement).appendChild(s); s.remove(); if (document.documentElement.dataset.mkPlayzipPage === "ok") { console.info(TAG, "页面世界补丁注入成功"); } else { console.warn(TAG, "页面世界注入未确认(可能被CSP拦截或隔离环境), 若广告仍弹窗请反馈此条日志"); } }); } sweepExisting(); watchNewScripts(); installPagePatch();})();