// ==UserScript== // @name anti-rickroll // @namespace http://tampermonkey.net/ // @version 11.1 // @description fuck rickroll // @author dext // @match *://*/* // @grant GM_xmlhttpRequest // @grant GM_addStyle // @connect anti-rickroll.dext.top // @run-at document-start // @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; GM_addStyle(` #rick-breaker-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.95); z-index:2147483647; display:flex; justify-content:center; align-items:center; backdrop-filter:blur(15px); } .rick-card { background:#fff; padding:40px; border-radius:20px; width:350px; text-align:center; border:6px solid #ff4444; font-family:sans-serif; box-shadow: 0 10px 30px rgba(0,0,0,0.5); } .rick-btn { padding:15px; border-radius:10px; cursor:pointer; border:none; font-weight:bold; width:100%; margin-top:15px; font-size:14px; } .btn-safe { background:#eee; color:#333; } .btn-danger { background:#ff4444; color:#fff; } a.rickroll-danger { border-bottom: 2px dashed #ff4444 !important; color:#ff4444 !important; background:rgba(255,0,0,0.05) !important; } `); // 1. 脱壳逻辑 function getRealUrl(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'); } catch (e) {} return url; } // 2. 入境自检 (已更名为 ASCII 兼容名称) function checkIncoming() { 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 data = JSON.parse(res.responseText); if (data.isRickroll) { window.stop(); renderBlockPage("入境检测拦截", url); } } catch (e) {} } }); } // 3. UI 渲染函数 function renderBlockPage(title, url) { if (document.getElementById('rick-breaker-overlay')) return; document.documentElement.innerHTML = ""; const div = document.createElement('div'); div.id = 'rick-breaker-overlay'; div.innerHTML = `

🚫

${title}

目标链接经穿透分析确认为 Rickroll

`; document.documentElement.appendChild(div); document.getElementById('r-back').onclick = () => history.length > 1 ? history.back() : window.close(); document.getElementById('r-go').onclick = () => { const a = document.createElement('a'); a.href = url; a.dataset.rickSafe = '1'; a.click(); }; } // 4. 并发预检 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 data = JSON.parse(res.responseText); cache.set(url, data.isRickroll); if (data.isRickroll) { document.querySelectorAll('a').forEach(a => { if(getRealUrl(a.href) === url) a.classList.add('rickroll-danger'); }); } } catch (e) {} activeRequests--; processQueue(); }, onerror: () => { activeRequests--; processQueue(); } }); } function scanPage() { const EXCLUDE = /\.(jpg|jpeg|png|gif|css|js|woff|zip|pdf|mp4)($|\?)/i; document.querySelectorAll('a[href]').forEach(a => { const url = getRealUrl(a.href); if (!url.startsWith('http') || url.includes(window.location.hostname) || EXCLUDE.test(url) || cache.has(url)) return; cache.set(url, 'pending'); queue.push(url); }); processQueue(); } // 5. 点击接管 window.addEventListener('click', function(e) { const a = e.target.closest('a'); if (!a || !a.href || !a.href.startsWith('http') || a.dataset.rickSafe === '1') return; const url = getRealUrl(a.href); e.preventDefault(); e.stopPropagation(); GM_xmlhttpRequest({ method: "POST", url: API_ENDPOINT, data: JSON.stringify({ url }), headers: { "Content-Type": "application/json" }, onload: (res) => { try { const data = JSON.parse(res.responseText); if (data.isRickroll) { renderBlockPage("重定向拦截", url); } else { a.dataset.rickSafe = '1'; a.click(); } } catch (e) { a.dataset.rickSafe = '1'; a.click(); } } }); }, true); checkIncoming(); window.addEventListener('load', () => { scanPage(); setInterval(scanPage, 5000); }); })();