// ==UserScript== // @name 🚀 极致网页体验增强器 // @namespace https://github.com/pluto // @version 1.0.0 // @description 全网通用:去广告、解除复制限制、自动展开全文、智能阅读模式、暗黑护眼、快捷操作面板 — 一站式网页体验提升 // @author Pluto // @match *://*/* // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant GM_notification // @run-at document-idle // @license MIT // ==/UserScript== (function () { 'use strict'; // ======================== 配置中心 ======================== const CONFIG = { adBlock: true, // 去广告 unblockCopy: true, // 解除复制限制 autoExpand: true, // 自动展开全文 cleanMode: false, // 阅读模式(默认关闭,手动开启) darkMode: false, // 暗黑模式(默认关闭) removePopups: true, // 去弹窗 cleanURL: true, // 清理跟踪参数 showPanel: true, // 显示快捷面板 fontSize: 18, // 阅读模式字体大小 }; // ======================== 工具函数 ======================== const $ = (sel, ctx = document) => ctx.querySelector(sel); const $$ = (sel, ctx = document) => [...ctx.querySelectorAll(sel)]; const log = (msg) => console.log('%c[极致增强]', 'color:#00d4aa;font-weight:bold', msg); // ======================== 1. 广告屏蔽 ======================== const AD_SELECTORS = [ // 通用广告 '[class*="ad-"]', '[class*="ad_"]', '[id*="ad-"]', '[id*="ad_"]', '[class*="ads-"]', '[class*="ads_"]', '[id*="ads-"]', '[id*="ads_"]', '[class*="advert"]', '[id*="advert"]', '[class*="banner"]', '[id*="banner"]', '[class*="sponsor"]', '[id*="sponsor"]', 'iframe[src*="ad"]', 'iframe[src*="doubleclick"]', 'iframe[src*="googlead"]', 'iframe[src*="adservice"]', // 弹窗广告 '[class*="popup"]', '[class*="modal-ad"]', '[class*="float-ad"]', '[class*="fixed-ad"]', '[class*="corner-ad"]', '[class*="overlay"]', // 常见广告容器 '.ad', '.ads', '.advert', '.advertisement', '#ad', '#ads', '#advert', // 百度广告 '[data-tuiguang]', '[class*="ec-tuiguang"]', // CSDN广告 '.recommend-ad', '.blog-footer-bottom', // 知乎广告 '.Pc-card', '.Pc-Business-card', // 简书广告 '.download-app', ]; function blockAds() { if (!CONFIG.adBlock) return; let count = 0; AD_SELECTORS.forEach(sel => { $$(sel).forEach(el => { if (el.offsetHeight > 0) { el.style.display = 'none'; count++; } }); }); if (count > 0) log(`已屏蔽 ${count} 个广告元素`); } // ======================== 2. 解除复制限制 ======================== function unblockCopy() { if (!CONFIG.unblockCopy) return; // 移除事件监听限制 const events = ['copy', 'cut', 'paste', 'selectstart', 'contextmenu', 'mousedown', 'mouseup']; events.forEach(evt => { document.addEventListener(evt, (e) => e.stopPropagation(), true); }); // 移除 CSS 限制 GM_addStyle(` *, *::before, *::after { -webkit-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; user-select: text !important; -webkit-touch-callout: default !important; } `); // 移除 JS 层面限制 try { Object.defineProperty(document, 'oncopy', { get: () => null, set: () => {} }); Object.defineProperty(document, 'oncut', { get: () => null, set: () => {} }); Object.defineProperty(document, 'onselectstart', { get: () => null, set: () => {} }); Object.defineProperty(document, 'oncontextmenu', { get: () => null, set: () => {} }); } catch (e) { } log('已解除复制限制'); } // ======================== 3. 自动展开全文 ======================== function autoExpand() { if (!CONFIG.autoExpand) return; const EXPAND_SELECTORS = [ // 通用 '[class*="expand"]', '[class*="show-more"]', '[class*="read-more"]', '[class*="unfold"]', '[class*="展开"]', '[class*="更多"]', 'a[href*="javascript"]', // CSDN '.hide-article-box', '#readMore', '.readall_box', '.article-show-more', // 知乎 '.RichContent-inner .ContentItem-expandButton', '.QuestionRichText-more', // 百度 '.c-content-display', // 微信公众号 '#js_pc_qr_code', // 通用"展开全文"按钮 'button', 'a', ]; let expanded = 0; EXPAND_SELECTORS.forEach(sel => { $$(sel).forEach(el => { const text = el.textContent || ''; if (/展开|更多|read\s*more|show\s*more|展开全文|查看全部|查看更多/i.test(text)) { el.click(); expanded++; } }); }); // 移除遮罩层 $$('[class*="gradient"]', '[class*="mask"]').forEach(el => { if (el.style.background && el.style.background.includes('gradient')) { el.style.display = 'none'; } }); if (expanded > 0) log(`已自动展开 ${expanded} 处内容`); } // ======================== 4. 去弹窗 ======================== function removePopups() { if (!CONFIG.removePopups) return; const POPUP_SELECTORS = [ '[class*="modal"]', '[class*="dialog"]', '[class*="popup"]', '[class*="overlay"]', '[class*="mask"]', '[class*="toast"]', '[class*="notice"]', '[class*="alert"]', '[class*="tip"]', '[role="dialog"]', '[role="alertdialog"]', '.ant-modal-mask', '.ant-modal-wrap', '.el-dialog__wrapper', '.el-overlay', '.modal-backdrop', '.modal-overlay', ]; POPUP_SELECTORS.forEach(sel => { $$(sel).forEach(el => { const style = window.getComputedStyle(el); if (style.position === 'fixed' && style.zIndex > 999) { // 检查是否是登录弹窗、广告弹窗等 const text = el.textContent || ''; if (/登录|注册|关注|下载app|开会员|VIP|广告|推广|微信/i.test(text)) { el.style.display = 'none'; log('已移除弹窗'); } } }); }); // 移除 body 的 overflow: hidden if (document.body.style.overflow === 'hidden') { document.body.style.overflow = 'auto'; } } // ======================== 5. 阅读模式 ======================== function toggleCleanMode() { CONFIG.cleanMode = !CONFIG.cleanMode; if (CONFIG.cleanMode) { // 提取正文 const article = extractArticle(); if (!article) { GM_notification({ title: '提示', text: '未找到可提取的正文内容', timeout: 2000 }); CONFIG.cleanMode = false; return; } // 创建阅读层 const overlay = document.createElement('div'); overlay.id = 'reading-overlay'; overlay.innerHTML = `