// ==UserScript== // @name 移动端限制弹窗解除 // @namespace https://viayoo.com/hrgow0 // @version 1.3 // @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(); 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 { document.querySelectorAll(selector).forEach(element => { if (element.offsetParent !== null) { element.style.display = 'none'; element.style.visibility = 'hidden'; element.style.opacity = '0'; } }); } catch(e) {} }); document.querySelectorAll('body > *').forEach(element => { if (!element.tagName) return; const style = window.getComputedStyle(element); const bgColor = style.backgroundColor; if (style.position === 'fixed' && parseInt(style.zIndex) > 1000 && (bgColor.includes('rgba(0, 0, 0') || bgColor.includes('rgba(0,0,0'))) { element.style.display = 'none'; } }); } function clickCloseButtons() { clickSelectors.forEach(selector => { try { document.querySelectorAll(selector).forEach(button => { if (button.offsetParent !== null && button.getBoundingClientRect().width > 0 && button.getBoundingClientRect().height > 0) { try { button.click(); if (!stayRules.has(selector)) { button.style.display = 'none'; button.style.visibility = 'hidden'; } } catch (e) {} } }); } catch(e) {} }); } function initStayObserver() { if (stayRules.size === 0) return; const observer = new MutationObserver(mutations => { stayRules.forEach(selector => { try { document.querySelectorAll(selector).forEach(button => { if (button.offsetParent !== null && button.getBoundingClientRect().width > 0 && button.getBoundingClientRect().height > 0) { try { button.click(); } catch (e) {} } }); } catch(e) {} }); }); observer.observe(document.body, { childList: true, subtree: true, attributes: true }); return observer; } function restoreBodyScroll() { ['no-scroll', 'scroll-locked', 'modal-open'].forEach(className => { if (document.body.classList.contains(className)) document.body.classList.remove(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'; } } function cleanup() { if (cleanupCount >= MAX_CLEANUP_COUNT) return; try { removePopups(); clickCloseButtons(); restoreBodyScroll(); cleanupCount++; } catch (error) {} } function initObserver() { const observer = new MutationObserver(mutations => { if (cleanupCount < MAX_CLEANUP_COUNT) cleanup(); }); observer.observe(document.body, { childList: true, subtree: true, attributes: false }); return observer; } function reInject() { addScrollStyles(); removePopups(); clickCloseButtons(); restoreBodyScroll(); } function init() { parseAdblockRules(); addScrollStyles(); setTimeout(() => { cleanup(); initObserver(); initStayObserver(); }, 500); const timer = setInterval(() => { if (cleanupCount >= MAX_CLEANUP_COUNT) clearInterval(timer); else cleanup(); }, 2000); document.addEventListener('dblclick', reInject); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else setTimeout(init, 100); })();