// ==UserScript== // @name 移动端限制弹窗解除 // @namespace https://viayoo.com/hrgow0 // @version 1.4 // @description 自用脚本,解除滑动禁止、触控禁止,移除弹窗。 // @author Via // @match *://*/* // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDQ4IDQ4Ij4KICA8IS0tIOa3seiJsuiDjOaZryAtLT4KICA8cmVjdCB3aWR0aD0iNDgiIGhlaWdodD0iNDgiIHJ4PSIxMiIgZmlsbD0iIzBkMTExNyIvPgoKICA8IS0tIGlQaG9uZSA2cyDpk7boibLmnLrouqvvvIjnnJ/lrp7mr5TkvovvvIkgLS0+CiAgPHJlY3QgeD0iMTAiIHk9IjUiIHdpZHRoPSIyOCIgaGVpZ2h0PSIzOCIgcng9IjYiIGZpbGw9IiNmNWY1ZjciIHN0cm9rZT0iI2QxZDFkNiIgc3Ryb2tlLXdpZHRoPSIxLjQiLz4KCiAgPCEtLSDpu5HoibLlsY/luZUgLS0+CiAgPHJlY3QgeD0iMTIiIHk9IjkiIHdpZHRoPSIyNCIgaGVpZ2h0PSIzMCIgcng9IjMiIGZpbGw9IiMwMDAiLz4KCiAgPCEtLSDnnJ/lrp7mr5TkvovotoXlsI8gSG9tZSDplK7vvIjlrozlhajlnKjnmb3oibLmnLrouqvlhoXvvIzkuI3ljovlsY/luZXvvIkgLS0+CiAgPGNpcmNsZSBjeD0iMjQiIGN5PSI0MC42IiByPSIxLjkiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2JiYiIgc3Ryb2tlLXdpZHRoPSIwLjgiLz4KICA8Y2lyY2xlIGN4PSIyNCIgY3k9IjQwLjYiIHI9IjEuMiIgZmlsbD0iI2ZkZmRmZCIvPgoKICA8IS0tIOWxj+W5leWGheS4ieaMh+a7keWKqOi9qOi/ue+8iOS4peagvOWcqOWxj+W5leWuieWFqOWMuiAxMy41fjM3Lj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yNCIgY3k9IjE1LjUiIHI9IjIiIGZpbGw9IiMxYWJjOWMiIG9wYWNpdHk9IjAuNyIvPgogIDxjaXJjbGUgY3g9IjE3IiBjeT0iMzQiIHI9IjEuNyIgZmlsbD0iIzFhYmM5YyIgb3BhY2l0eT0iMC41NSIvPgogIDxjaXJjbGUgY3g9IjMxIiBjeT0iMzQiIHI9IjEuNyIgZmlsbD0iIzFhYmM5YyIgb3BhY2l0eT0iMC41NSIvPgo8L3N2Zz4= // @grant GM_addStyle // @run-at document-start // @license MIT // ==/UserScript== (function() { 'use strict'; let cleanupCount = 0, removeSelectors = [], clickSelectors = [], stayRules = new Set(); const MAX_CLEANUP_COUNT = 10; // 弹窗和元素隐藏规则 // ##+js(dpopup, 元素名称,是否持续监控)。 // 例如 ##+js(dpopup, .ad),点击一次包含.ad的按钮,然后隐藏。 // ##+js(dpopup, .ad,stay),就是点击后不隐藏,持续监控点击多个.ad。 // 其他##就是普通的Adblock规则 // bing.com###ads_popup就是隐藏#ads_popup元素 // ###ads_popup就是通用规则 // *bing.com###ads_popup,就是模糊匹配,例如www.bing.com或者cn.bing.com都会被匹配 const Adblock_Rules = ` ###ads_popup ##.ads-popup ##.g-pop ##.mobile-download-popup ##.modal-mask ##.overlay-mask ##.popup-mask ##.popup-overlay ##.q-dialog ##.top-advert ##.van-overlay ##[data-role="overlay"] ##+js(dpopup, .ad-area-close, stay) ##+js(dpopup, .gg-close) ##+js(dpopup, .js-adv-close) ##+js(dpopup, .popup-close, stay) ##+js(dpopup, [onclick^="closePopup"], stay) bing.com##+js(dpopup, #sacs_close) `.trim(); const log = (msg) => console.log(`%c[弹窗解除] ${msg}`, 'color:#1abc9c;font-weight:bold;background:#000;border-radius:4px;padding:2px 6px;'); function parseAdblockRules() { const currentHost = window.location.hostname; Adblock_Rules.split('\n').filter(line => line.trim()).forEach(line => { if (line.includes('##+js(dpopup,')) { const match = line.match(/##\+js\(dpopup,\s*([^,)]+)(?:,\s*(stay))?\)/); if (match) { clickSelectors.push(match[1].replace(/['"]/g, '').trim()); if (match[2] === 'stay') stayRules.add(match[1]); } } else if (line.startsWith('##')) { removeSelectors.push(line.replace(/^#{2,3}/, '').trim()); } else if (line.includes('##')) { const [domains, rule] = line.split('##'), domainList = domains.split(','); const domainMatch = domainList.some(domain => { const cleanDomain = domain.trim().replace(/^[*]+\.?/, ''); return !cleanDomain || currentHost === cleanDomain || currentHost.endsWith('.' + cleanDomain) || (cleanDomain.startsWith('*') && currentHost.endsWith(cleanDomain.slice(1))); }); if (domainMatch) { if (rule.includes('+js(dpopup,')) { const match = rule.match(/\+js\(dpopup,\s*([^,)]+)(?:,\s*(stay))?\)/); if (match) { clickSelectors.push(match[1].replace(/['"]/g, '').trim()); if (match[2] === 'stay') stayRules.add(match[1]); } } else { removeSelectors.push(rule.trim()); } } } }); removeSelectors = [...new Set(removeSelectors)]; clickSelectors = [...new Set(clickSelectors)]; } function addScrollStyles() { const css = `body.no-scroll,body.scroll-locked,body.overflow-hidden,.scroll-lock,.no-scroll{overflow:auto!important;position:relative!important;height:auto!important;max-height:none!important}.modal-backdrop,.popup-backdrop,.overlay-mask{display:none!important}`; if (typeof GM_addStyle !== 'undefined') GM_addStyle(css); else { const style = document.createElement('style'); style.textContent = css; (document.head || document.documentElement).appendChild(style); } } function removePopups() { removeSelectors.forEach(selector => { try { const elements = document.querySelectorAll(selector); let hit = 0; elements.forEach(element => { if (element.offsetParent !== null) { element.style.display = 'none'; element.style.visibility = 'hidden'; element.style.opacity = '0'; if (typeof element.remove === 'function') { element.remove(); } hit++; } }); if (hit > 0) { log(`当前网页: ${location.href}\n运行规则: ${selector} ,原因: 匹配到弹窗/遮罩元素 ,状态: 成功 (已移除 ${hit} 个)`); } } catch(e) {} }); let blackHit = 0; document.querySelectorAll('body > *').forEach(element => { if (!element.tagName) return; const style = window.getComputedStyle(element); if (style.position === 'fixed' && parseInt(style.zIndex) > 9999 && (style.backgroundColor.includes('rgba(0, 0, 0') || style.backgroundColor.includes('rgba(0,0,0'))) { if (typeof element.remove === 'function') { element.remove(); } blackHit++; } }); if (blackHit > 0) { log(`当前网页: ${location.href}\n运行规则: 通用黑遮罩检测 ,原因: fixed+高zIndex+黑背景 ,状态: 成功 (已移除 ${blackHit} 个)`); } } function clickCloseButtons() { clickSelectors.forEach(selector => { try { const buttons = document.querySelectorAll(selector); let hit = 0; buttons.forEach(button => { if (button.offsetParent !== null && button.getBoundingClientRect().width > 0 && button.getBoundingClientRect().height > 0) { button.click(); hit++; if (!stayRules.has(selector)) { button.style.display = 'none'; button.style.visibility = 'hidden'; } } }); if (hit > 0) { log(`当前网页: ${location.href}\n运行规则: ${selector} ,原因: 模拟点击关闭按钮 ,状态: 成功`); } } catch(e) {} }); } function initStayObserver() { if (stayRules.size === 0) return; const observer = new MutationObserver(mutations => { stayRules.forEach(selector => { document.querySelectorAll(selector).forEach(button => { if (button.offsetParent !== null && button.getBoundingClientRect().width > 0 && button.getBoundingClientRect().height > 0) { button.click(); log(`当前网页: ${location.href}\n[stay监控] 运行规则: ${selector} ,原因: 新出现关闭按钮自动点击 ,状态: 成功`); } }); }); }); observer.observe(document.body, { childList: true, subtree: true, attributes: true }); } function restoreBodyScroll() { let changed = false; ['no-scroll', 'scroll-locked', 'modal-open'].forEach(className => { if (document.body.classList.contains(className)) { document.body.classList.remove(className); changed = true; log(`当前网页: ${location.href}\n触发解除滚动,原因: 移除禁止滚动类 ${className} ,状态: 成功`); } }); const bodyStyle = window.getComputedStyle(document.body); if (bodyStyle.overflow === 'hidden' || bodyStyle.position === 'fixed') { document.body.style.overflow = 'auto'; document.body.style.position = 'relative'; document.body.style.height = 'auto'; changed = true; log(`当前网页: ${location.href}\n触发解除滚动,原因: 强制恢复 body overflow/position ,状态: 成功`); } } function cleanup() { if (cleanupCount >= MAX_CLEANUP_COUNT) return; try { removePopups(); clickCloseButtons(); restoreBodyScroll(); cleanupCount++; } catch (error) {} } function initObserver() { const observer = new MutationObserver(mutations => { cleanup(); }); observer.observe(document.body, { childList: true, subtree: true, attributes: false }); } function reInject() { log(`手动触发脚本(双击页面)…… 当前网页: ${location.href}`); addScrollStyles(); removePopups(); clickCloseButtons(); restoreBodyScroll(); } function init() { parseAdblockRules(); addScrollStyles(); setTimeout(() => { cleanup(); initObserver(); initStayObserver(); }, 500); setInterval(cleanup, 1500); document.addEventListener('dblclick', reInject); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else setTimeout(init, 100); })();