// ==UserScript== // @name Porn Blocker | 色情内容过滤器 // @name:en Porn Blocker // @name:zh-CN 色情内容过滤器 // @name:zh-TW 色情內容過濾器 // @name:zh-HK 色情內容過濾器 // @name:ja アダルトコンテンツブロッカー // @name:ko 성인 컨텐츠 차단기 // @name:ru Блокировщик порнографии // @namespace https://noctiro.moe // @version 2.0.5 // @description A powerful content blocker that helps protect you from inappropriate websites. Features: Auto-detection of adult content, Multi-language support, Smart scoring system, Safe browsing protection. // @description:en A powerful content blocker that helps protect you from inappropriate websites. Features: Auto-detection of adult content, Multi-language support, Smart scoring system, Safe browsing protection. // @description:zh-CN 强大的网页过滤工具,帮助你远离不良网站。功能特点:智能检测色情内容,多语言支持,评分系统,安全浏览保护,支持自定义过滤规则。为了更好的网络环境,从我做起。 // @description:zh-TW 強大的網頁過濾工具,幫助你遠離不良網站。功能特點:智能檢測色情內容,多語言支持,評分系統,安全瀏覽保護,支持自定義過濾規則。為了更好的網絡環境,從我做起。 // @description:zh-HK 強大的網頁過濾工具,幫助你遠離不良網站。功能特點:智能檢測色情內容,多語言支持,評分系統,安全瀏覽保護,支持自定義過濾規則。為了更好的網絡環境,從我做起。 // @description:ja アダルトコンテンツを自動的にブロックする強力なツールです。機能:アダルトコンテンツの自動検出、多言語対応、スコアリングシステム、カスタマイズ可能なフィルタリング。より良いインターネット環境のために。 // @description:ko 성인 컨텐츠를 자동으로 차단하는 강력한 도구입니다. 기능: 성인 컨텐츠 자동 감지, 다국어 지원, 점수 시스템, 안전 브라우징 보호, 맞춤형 필터링 규칙。 // @description:ru Мощный инструмент для блокировки неприемлемого контента. Функции: автоматическое определение, многоязычная поддержка, система оценки, настраиваемые правила фильтрации。 // @license Apache-2.0 // @match *://*/* // @run-at document-start // @run-at document-end // @run-at document-idle // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; // 多语言支持 const i18n = { 'en': { title: '🚫 Access Blocked', message: 'This webpage has been identified as inappropriate content.', redirect: 'Redirecting in 4 seconds...', footer: 'Stay healthy · Stay away from harmful content' }, 'zh-CN': { title: '🚫 访问已被拦截', message: '该网页已被识别为不健康内容。', redirect: '4 秒后自动跳转...', footer: '注意身心健康 · 远离不良网站' }, 'zh-TW': { title: '🚫 訪問已被攔截', message: '該網頁已被識別為不健康內容。', redirect: '4 秒後自動跳轉...', footer: '注意身心健康 · 遠離不良網站' }, 'zh-HK': { title: '🚫 訪問已被攔截', message: '該網頁已被識別為不健康內容。', redirect: '4 秒後自動跳轉...', footer: '注意身心健康 · 遠離不良網站' }, 'ja': { title: '🚫 アクセスがブロックされました', message: 'このページは不適切なコンテンツとして識別されました。', redirect: '4 秒後にリダイレクトします...', footer: '健康に注意 · 有害サイトに近づかない' }, 'ko': { title: '🚫 접근이 차단됨', message: '이 웹페이지가 부적절한 콘텐츠로 식별되었습니다.', redirect: '4초 후 자동으로 이동됩니다...', footer: '건강 관리 · 유해 사이트 멀리하기' }, 'ru': { title: '🚫 Доступ заблокирован', message: 'Эта веб-страница определена как неподходящий контент.', redirect: 'Перенаправление через 4 секунды...', footer: 'Будьте здоровы · Держитесь подальше от вредного контента' } }; // 获取用户语言 const getUserLanguage = () => { const lang = navigator.language || navigator.userLanguage; // 检查完整语言代码 if (i18n[lang]) return lang; // 处理中文的特殊情况 if (lang.startsWith('zh')) { const region = lang.toLowerCase(); if (region.includes('tw') || region.includes('hant')) return 'zh-TW'; if (region.includes('hk')) return 'zh-HK'; return 'zh-CN'; } // 检查简单语言代码 const shortLang = lang.split('-')[0]; if (i18n[shortLang]) return shortLang; return 'en'; }; // 浏览器检测函数 const getBrowserType = () => { const ua = navigator.userAgent.toLowerCase(); // Add more browser detection if (ua.includes('ucbrowser')) return 'uc'; if (ua.includes('qqbrowser')) return 'qq'; if (ua.includes('2345explorer')) return '2345'; if (ua.includes('360') || ua.includes('qihu')) return '360'; if (ua.includes('maxthon')) return 'maxthon'; if (ua.includes('firefox')) return 'firefox'; if (ua.includes('edg')) return 'edge'; if (ua.includes('opr') || ua.includes('opera')) return 'opera'; if (ua.includes('brave')) return 'brave'; if (ua.includes('vivaldi')) return 'vivaldi'; if (ua.includes('yabrowser')) return 'yandex'; if (ua.includes('chrome')) return 'chrome'; if (ua.includes('safari') && !ua.includes('chrome')) return 'safari'; return 'other'; }; // 获取浏览器主页URL const getHomePageUrl = () => { switch (getBrowserType()) { case 'firefox': return 'about:home'; case 'chrome': return 'chrome://newtab'; case 'edge': return 'edge://newtab'; case 'safari': return 'topsites://'; case 'opera': return 'opera://startpage'; case 'brave': return 'brave://newtab'; case 'vivaldi': return 'vivaldi://newtab'; case 'yandex': return 'yandex://newtab'; case 'uc': return 'ucenterhome://'; case 'qq': return 'qbrowser://home'; case '360': return 'se://newtab'; case 'maxthon': return 'mx://newtab'; case '2345': return '2345explorer://newtab'; default: // Fallback to a safe default return 'about:blank'; } }; // ----------------- 预编译正则规则 (性能优化) ----------------- const regexCache = { // 色情关键词正则(预编译,避免重复生成) pornRegex: null, // 白名单正则(预编译) whitelistRegex: null, // .xxx后缀正则 xxxRegex: /\.xxx$/i }; // ----------------- 配置项(用户可按需修改) ----------------- const config = { // ================== 域名专用黑名单词汇 ================== domainKeywords: { // 常见成人网站域名关键词(权重4) 'pornhub': 4, 'xvideo': 4, 'redtube': 4, 'xnxx': 4, 'xhamster': 4, '4tube': 4, 'youporn': 4, 'spankbang': 4, 'myfreecams': 4, 'missav': 4, 'rule34': 4, 'youjizz': 4, 'onlyfans': 4, 'paidaa': 4, '3c5g9': 4, 'haijiao': 4, // 核心违规词(权重3-4) 'porn': 3, 'nsfw': 3, 'hentai': 3, 'incest': 4, 'rape': 4, 'childporn': 4, // 身体部位关键词(权重2) 'pussy': 2, 'cock': 2, 'dick': 2, 'boobs': 2, 'tits': 2, 'ass': 2, 'beaver': 1, // 特定群体(权重2-3) 'teen': 3, 'sis': 2, 'milf': 2, 'cuckold': 3, 'virgin': 2, 'luoli': 2, 'gay': 2, // 具体违规行为(权重2-3) 'anal': 3, 'blowjob': 3, 'creampie': 2, 'bdsm': 2, 'masturbat': 2, 'handjob': 3, 'footjob': 3, 'rimjob': 3, // 其他相关词汇(权重1-2) 'camgirl': 2, 'webcam': 2, 'leaked': 2, 'fap': 2, 'erotic': 1, 'escort': 3, 'nude': 3, 'naked': 3, 'upskirt': 2, // 特定地区成人站点域名特征(权重4) 'jav': 4, // 域名变体检测(权重3) 'p0rn': 3, 'pr0n': 3, 'pron': 3, 's3x': 3, 'sexx': 3, }, // ================== 内容检测关键词 ================== contentKeywords: { // 核心违规词(权重3-4)- 严格边界检测 '\\b(?:po*r*n|pr[o0]n)\\b': 3, // porn及其变体 'nsfw': 3, '\\bhentai\\b': 3, '\\binces*t\\b': 4, '\\br[a@]pe\\b': 4, '(?:child|kid)(?:po*r*n)': 4, // 身体部位关键词(权重2)- 优化边界和上下文检测 'puss(?:y|ies)\\b': 2, '\\bco*ck(?:s)?(?!tail|roach|pit|er)\\b': 2, // 排除cocktail等 '\\bdick(?:s)?(?!ens|tionary|tate)\\b': 2, // 排除dickens等 '\\bb[o0]{2,}bs?\\b': 2, '\\btits?\\b': 2, '(? { return config.domainPatterns.some(pattern => pattern.test(hostname)); }; // 检查是否需要进行内容检测 const shouldCheckContent = (hostname) => { return config.contentCheckDomains.some(pattern => pattern.test(hostname)); }; // 内容检测辅助函数 const contentUtils = { // 优化文本获取算法 getAllText: (element) => { if (!element) return ""; // 使用Set去重 const textSet = new Set(); try { const walker = document.createTreeWalker( element, NodeFilter.SHOW_TEXT, { acceptNode: (node) => { const parent = node.parentElement; // 优化过滤条件 if (!parent || /^(SCRIPT|STYLE|NOSCRIPT|IFRAME|META|LINK)$/i.test(parent.tagName) || parent.hidden || getComputedStyle(parent).display === 'none') { return NodeFilter.FILTER_REJECT; } const text = node.textContent.trim(); if (!text || text.length < config.contentCheck.textNodeMinLength) { return NodeFilter.FILTER_REJECT; } return NodeFilter.FILTER_ACCEPT; } } ); let node; while (node = walker.nextNode()) { textSet.add(node.textContent.trim()); } } catch (e) { console.error('Error in getAllText:', e); } return Array.from(textSet).join(' '); }, // 优化可疑元素获取 getSuspiciousElements: () => { try { const elements = new Set(); // 使用更高效的选择器 const fastSelectors = [ 'article', 'main', '.content', '[class*="content"]', '[class*="text"]', 'h1', 'h2', 'h3' ]; fastSelectors.forEach(selector => { document.querySelectorAll(selector).forEach(el => elements.add(el)); }); return Array.from(elements); } catch (e) { console.error('Error in getSuspiciousElements:', e); return []; } } }; // 优化内容检测函数 function detectAdultContent() { let totalScore = 0; let totalElements = 0; let violationCount = 0; try { const scoreCache = new WeakMap(); // 获取高风险元素 const highRiskElements = document.querySelectorAll( config.contentCheck.localizedCheck.highRiskSelectors.join(',') ); // 检查高风险元素 for (const element of highRiskElements) { const score = getElementScore(element, scoreCache); if (score >= config.contentCheck.localizedCheck.elementThreshold) { return true; // 高风险区域发现违规内容直接拦截 } } // 排除不需要检测的元素 const excludeSelector = config.contentCheck.localizedCheck.excludeSelectors.join(','); const excludeElements = new Set(document.querySelectorAll(excludeSelector)); // 检查其他内容 const mainElements = contentUtils.getSuspiciousElements(); for (const element of mainElements) { // 跳过被排除的元素 if (excludeElements.has(element) || Array.from(excludeElements).some(excluded => excluded.contains(element))) { continue; } totalElements++; const score = getElementScore(element, scoreCache); if (score >= config.contentCheck.localizedCheck.elementThreshold) { violationCount++; totalScore += score; } // 检查违规比例 if (violationCount >= config.contentCheck.localizedCheck.minViolationCount && (violationCount / totalElements) >= config.contentCheck.localizedCheck.violationRatio) { return true; } } // 优化图片检测 const images = document.querySelectorAll('img[alt], img[title]'); for (const img of images) { const imgText = `${img.alt} ${img.title}`.trim(); if (imgText) { totalScore += calculateScore(imgText) * 0.5; // 降低图片文本权重 } } // 优化元数据检测 const metaTags = document.querySelectorAll('meta[name="description"], meta[name="keywords"]'); for (const meta of metaTags) { const content = meta.content; if (content) { totalScore += calculateScore(content) * 0.3; // 降低元数据权重 } } } catch (e) { console.error('Error in detectAdultContent:', e); return false; } return totalScore >= config.contentCheck.adultContentThreshold; } // 添加获取元素评分的辅助函数 function getElementScore(element, scoreCache) { if (scoreCache.has(element)) { return scoreCache.get(element); } const text = contentUtils.getAllText(element); const score = calculateScore(text); scoreCache.set(element, score); return score; } // Refactored content detector using helper function const checkPageContent = () => { return detectAdultContent(); }; // 预处理正则(仅初始化一次) (function initRegex() { // 域名关键词正则 const domainTerms = Object.keys(config.domainKeywords).join('|'); regexCache.domainRegex = new RegExp(`(${domainTerms})`, 'gi'); // 内容关键词正则 const contentTerms = Object.keys(config.contentKeywords).join('|'); regexCache.contentRegex = new RegExp(`(${contentTerms})`, 'gi'); // 白名单正则 const whitelistTerms = Object.keys(config.whitelist).join('|'); regexCache.whitelistRegex = new RegExp(`(${whitelistTerms})`, 'gi'); })(); // Helper function to sum weights from regex matches function sumMatches(text, regex, weightMap) { return (text.match(regex) || []).reduce((total, match) => { return total + (weightMap[match.toLowerCase()] || 0); }, 0); } // 优化后的评分计算函数 const calculateScore = (text, isDomain = false) => { let score = isDomain ? sumMatches(text, regexCache.domainRegex, config.domainKeywords) : sumMatches(text, regexCache.contentRegex, config.contentKeywords); if (score >= config.thresholds.whitelist) { score += sumMatches(text, regexCache.whitelistRegex, config.whitelist); } return score; }; // 添加内容检测防抖函数 const debounce = (func, wait) => { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; }; // 检测结果处理函数 const handleBlockedContent = () => { const lang = getUserLanguage(); const text = i18n[lang]; window.stop(); document.documentElement.innerHTML = `
${text.message}
${text.redirect}