// ==UserScript== // @name anti-rickroll // @version 12.1 // @description 修复关闭逻辑与后缀丢失问题,优化回退体验 // @author dext // @match *://*/* // @grant GM_xmlhttpRequest // @grant GM_addStyle // @connect anti-rickroll.dext.top // @run-at document-start // @namespace http://tampermonkey.net/ // @downloadURL none // ==/UserScript== (function() { 'use strict'; const API_ENDPOINT = "https://anti-rickroll.dext.top"; const cache = new Map(); const queue = []; let activeRequests = 0; const MAX_CONCURRENT = 3; // 0. 核心判定:如果已经获得免死金牌,彻底停止脚本运行 if (window.location.hash.includes('force-pass')) { console.log("[Rickroll Hunter] 发现免死金牌,已放行当前页面"); return; } GM_addStyle(` #rick-breaker-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.98); z-index:2147483647; display:flex; justify-content:center; align-items:center; backdrop-filter:blur(25px); } .rick-card { background:#fff; padding:40px; border-radius:24px; width:350px; text-align:center; border:6px solid #ff4444; box-shadow: 0 20px 60px rgba(0,0,0,0.8); font-family: sans-serif; } .rick-btn { padding:15px; border-radius:12px; cursor:pointer; border:none; font-weight:bold; width:100%; margin-top:15px; font-size:16px; transition: 0.2s; } .btn-safe { background:#eee; color:#333; } .btn-safe:hover { background:#ddd; } .btn-danger { background:#ff4444; color:#fff; font-size:11px; opacity:0.5; } .btn-danger:hover { opacity:1; } #rick-report-btn { position: fixed; bottom: 20px; left: 20px; z-index: 2147483646; background: rgba(0,0,0,0.7); color: white; padding: 8px 15px; border-radius: 20px; cursor: pointer; font-size: 13px; backdrop-filter: blur(5px); border: 1px solid rgba(255,255,255,0.2); display: flex; align-items: center; gap: 8px; } a.rickroll-danger { outline: 3px dashed #ff4444 !important; outline-offset: 2px; } `); // --- 逻辑 A: 基础工具 --- function getCleanUrl(url) { try { const u = new URL(url); if (u.hostname.includes('google.com') && u.searchParams.has('q')) return u.searchParams.get('q'); if (u.hostname.includes('baidu.com') && u.searchParams.has('url')) return u.searchParams.get('url'); return u.origin + u.pathname + u.search; } catch (e) { return url; } } function isInternal(url) { try { return new URL(url).hostname === window.location.hostname; } catch (e) { return true; } } function silenceMedia() { document.querySelectorAll('video, audio').forEach(m => { m.pause(); m.muted = true; }); } // --- 逻辑 B: 智能退出与回退 --- function smartExit(isIncoming) { if (!isIncoming) { // 点击拦截的情形,直接移除遮罩 const overlay = document.getElementById('rick-breaker-overlay'); if (overlay) overlay.remove(); return; } // 入境拦截的情形:需要离开当前坏页面 const referrer = document.referrer; if (referrer && !referrer.includes(window.location.hostname)) { window.location.replace(referrer); } else if (window.history.length > 1) { window.history.back(); } else { // 实在没地方去了,尝试关闭,关不掉就跳空白页 window.close(); setTimeout(() => { window.location.href = "about:blank"; }, 100); } } // --- 逻辑 C: UI 渲染 --- function renderOverlay(title, url, isIncoming = false) { if (document.getElementById('rick-breaker-overlay')) return; const silencer = setInterval(silenceMedia, 200); const overlay = document.createElement('div'); overlay.id = 'rick-breaker-overlay'; overlay.innerHTML = `
🛑

${title}

此路径被识别为 Rickroll

`; (document.body || document.documentElement).appendChild(overlay); document.getElementById('r-back').onclick = () => { clearInterval(silencer); smartExit(isIncoming); }; document.getElementById('r-go').onclick = () => { clearInterval(silencer); overlay.remove(); // 确保金牌后缀稳固添加 const separator = url.includes('#') ? '&' : '#'; const jumpUrl = url + separator + 'force-pass'; if (isIncoming) { // 如果是已经进入了页面,直接原地替换 URL 刷新 window.location.replace(jumpUrl); } else { // 如果是点击拦截,新开一个带金牌的标签页 const a = document.createElement('a'); a.href = jumpUrl; a.target = "_blank"; a.click(); } }; } // --- 逻辑 D: 核心功能 (扫描、点击、入境) --- function processQueue() { if (queue.length === 0 || activeRequests >= MAX_CONCURRENT) return; const url = queue.shift(); activeRequests++; GM_xmlhttpRequest({ method: "POST", url: API_ENDPOINT, data: JSON.stringify({ url }), headers: { "Content-Type": "application/json" }, onload: (res) => { try { const d = JSON.parse(res.responseText); cache.set(url, { isRickroll: !!d.isRickroll, status: 'done' }); if (d.isRickroll) document.querySelectorAll(`a`).forEach(a => { if(getCleanUrl(a.href) === url) a.classList.add('rickroll-danger'); }); } catch (e) {} activeRequests--; processQueue(); } }); } function scan() { const EX = /\.(jpg|jpeg|png|gif|css|js|woff|zip|pdf|mp4)($|\?)/i; document.querySelectorAll('a[href]').forEach(a => { const url = getCleanUrl(a.href); if (!url.startsWith('http') || isInternal(url) || EX.test(url) || cache.has(url)) return; cache.set(url, { isRickroll: false, status: 'pending' }); queue.push(url); }); processQueue(); } // 点击拦截逻辑 window.addEventListener('click', (e) => { const a = e.target.closest('a'); if (!a || !a.href.startsWith('http')) return; const url = getCleanUrl(a.href); if (isInternal(url) || a.dataset.rickSafe === '1' || url.includes('force-pass')) return; // 内存缓存优先 const res = cache.get(url); if (res && res.status === 'done' && res.isRickroll) { e.preventDefault(); e.stopPropagation(); renderOverlay("链路风险拦截", url, false); return; } e.preventDefault(); e.stopPropagation(); GM_xmlhttpRequest({ method: "POST", url: API_ENDPOINT, data: JSON.stringify({ url }), headers: { "Content-Type": "application/json" }, onload: (res) => { const d = JSON.parse(res.responseText); cache.set(url, { isRickroll: !!d.isRickroll, status: 'done' }); if (d.isRickroll) renderOverlay("实时风险拦截", url, false); else { a.dataset.rickSafe = '1'; a.click(); } } }); }, true); // 入境自检 function checkCurrent() { const url = window.location.href; if (url.length < 25 || /google|baidu|bing/.test(window.location.hostname)) return; GM_xmlhttpRequest({ method: "POST", url: API_ENDPOINT, data: JSON.stringify({ url }), headers: { "Content-Type": "application/json" }, onload: (res) => { try { const d = JSON.parse(res.responseText); if (d.isRickroll) { window.stop(); renderOverlay("入境风险拦截", url, true); } } catch (e) {} } }); } // 举报按钮逻辑 (V12.0 功能保持) function createReportButton() { if (document.getElementById('rick-report-btn') || sessionStorage.getItem('rick-btn-hidden') === '1') return; const btn = document.createElement('div'); btn.id = 'rick-report-btn'; btn.innerHTML = `🛡️ 我被骗了!×`; document.body.appendChild(btn); document.getElementById('rick-do-report').onclick = () => { const b = document.getElementById('rick-report-btn'); b.innerText = "🔍 AI 正在存入云端..."; GM_xmlhttpRequest({ method: "POST", url: API_ENDPOINT, data: JSON.stringify({ url: window.location.href, isFeedback: true, title: document.title, snippet: document.body.innerText.substring(0, 800) }), headers: { "Content-Type": "application/json" }, onload: (res) => { const d = JSON.parse(res.responseText); if (d.isRickroll) { b.innerText = "✅ 举报成功"; renderOverlay("事后举报生效", window.location.href, true); } else b.innerText = "❌ AI 觉得这不像 Rickroll"; setTimeout(() => b.remove(), 2000); } }); }; document.getElementById('rick-close-report').onclick = (e) => { e.stopPropagation(); btn.remove(); sessionStorage.setItem('rick-btn-hidden', '1'); }; } // --- 启动 --- checkCurrent(); window.addEventListener('load', () => { createReportButton(); setInterval(scan, 4000); }); })();