// ==UserScript== // @name Auto Redirect Purifier (自动重定向净化) // @namespace http://tampermonkey.net/ // @version 3.4 // @description 自动无缝跳过外部链接重定向提示,净化拦截页面,还原最纯净的原始链接。告别"即将离开本站"等繁琐的二次确认步骤,0.1秒光速跳转!占用极低,丝滑体验。目前支持: Google、YouTube、Steam、Gitee、腾讯云开发者社区、知乎、掘金、CSDN、简书、微博、LeetCode、QQ邮箱、QQ客户端、开源中国、百度贴吧、豆瓣、Pixiv、语雀、金山文档、Facebook、Instagram、Telegram、Twitter 等全网超20个平台,并兼容 meta refresh 跳转。 // @author LBCN // @license MIT // @match *://www.google.com/url?* // @match *://gitee.com/link?* // @match *://cloud.tencent.com/developer/tools/blog-entry?* // @match *://link.zhihu.com/?* // @match *://link.juejin.cn/?* // @match *://link.csdn.net/?* // @match *://www.jianshu.com/go-wild* // @match *://www.youtube.com/redirect?* // @match *://steamcommunity.com/linkfilter/* // @match *://l.facebook.com/l.php?* // @match *://l.instagram.com/?* // @match *://vk.com/away.php?* // @match *://leetcode.cn/link/* // @match *://www.oschina.net/action/GoToExtraWeb?* // @match *://c.pc.qq.com/middlem.html?* // @match *://mail.qq.com/cgi-bin/readtemplate?* // @match *://weibo.cn/sinaurl?* // @match *://tieba.baidu.com/mo/q/checkurl?* // @match *://www.douban.com/link2/* // @match *://www.pixiv.net/jump.php?* // @match *://www.yuque.com/r/goto?* // @match *://www.kdocs.cn/office/link?* // @match *://slack-redir.net/link?* // @match *://www.evernote.com/OutboundRedirect.action?* // @match *://t.me/iv?* // @match *://t.co/* // @match *://link.bilibili.com/* // @match *://link.toutiao.com/?* // @grant none // @run-at document-start // @homepageURL https://greasyfork.org/zh-TW/scripts/573126 // ==/UserScript== (function() { 'use strict'; const candidateKeys = ['target', 'url', 'q', 'u', 'to', 'gourl', 'pfurl', 'toasturl', 'goto', 'link', 'href', 'dest', 'r', 'redirect', 'redirect_url', 'target_url']; const safeBase64Decode = (str) => { try { let b64 = str.replace(/-/g, '+').replace(/_/g, '/'); let pad = b64.length % 4; if (pad) b64 += '='.repeat(4 - pad); return decodeURIComponent(escape(atob(b64))); } catch(e) { return null; } }; const extractUrlFromStr = (str) => { if (!str) return null; let s = str, last = "", depth = 0; while (s !== last && depth < 3) { last = s; depth++; try { let d = decodeURIComponent(s); if (d !== s) { s = d; continue; } } catch(e) {} if (s.startsWith('{') && s.endsWith('}')) { try { let j = JSON.parse(s); let ext = j.url || j.target || j.link || j.href; if (ext) { s = ext; continue; } } catch(e) {} } if (/^[A-Za-z0-9\-_+/]+={0,2}$/.test(s) && s.length >= 8) { let decoded = safeBase64Decode(s); if (decoded && decoded !== s) { s = decoded; continue; } } } if (/^https?:\/\//i.test(s)) return s; if (s.startsWith('//')) return window.location.protocol + s; return null; }; const findTargetInParams = (searchParams) => { for (let key of candidateKeys) { let val = searchParams.get(key); let extracted = extractUrlFromStr(val); if (extracted) return extracted; } return null; }; const doRedirect = (initialUrlStr) => { let currentUrl = initialUrlStr; let finalUrl = null; let loopGuard = 0; while (currentUrl && loopGuard < 3) { loopGuard++; try { const parsed = new URL(currentUrl, window.location.href); const params = new URLSearchParams(parsed.search); if (parsed.hash.length > 1) { new URLSearchParams(parsed.hash.substring(1)).forEach((v, k) => params.append(k, v)); } let nested = findTargetInParams(params); if (nested && nested !== currentUrl) { currentUrl = nested; } else { finalUrl = currentUrl; break; } } catch(e) { finalUrl = currentUrl; break; } } if (finalUrl && finalUrl !== window.location.href) { try { window.stop(); } catch(e) {} window.location.replace(finalUrl); return true; } return false; }; // 从 DOM 抢跳:优先 meta refresh,再按"具体→宽泛"匹配链接,避免误跳 const tryDomRedirect = () => { // 1) 解析 ,跳过浏览器刷新计时 const meta = document.querySelector('meta[http-equiv="refresh" i]'); if (meta) { const content = meta.getAttribute('content') || ''; const m = content.match(/url=([^;]+)/i); if (m) { let url = m[1].trim().replace(/^['"]|['"]$/g, ''); let extracted = extractUrlFromStr(url) || url; if (/^https?:\/\//i.test(extracted) && extracted !== window.location.href) { try { window.stop(); } catch(e) {} window.location.replace(extracted); return true; } } } // 2) 链接选择器:具体按钮优先,宽泛规则兜底 const selectors = [ '#go-link', 'a.btn', 'a.button', '.link-btn', 'a[href*="http"]:not([href*="' + window.location.hostname + '"])' ]; for (let sel of selectors) { const el = document.querySelector(sel); if (el && el.href) { let extracted = extractUrlFromStr(el.href) || el.href; if (/^https?:\/\//i.test(extracted) && extracted !== window.location.href) { try { window.stop(); } catch(e) {} window.location.replace(extracted); return true; } } } return false; }; const params = new URLSearchParams(window.location.search); if (window.location.hash.length > 1) { new URLSearchParams(window.location.hash.substring(1)).forEach((val, key) => params.append(key, val)); } let target = findTargetInParams(params); if (target) { doRedirect(target); } else { // 提前触发:readyState 进入 interactive 即尝试 const onReady = () => { if (document.readyState === 'loading') return; if (tryDomRedirect()) { window.removeEventListener('DOMContentLoaded', onReady); window.removeEventListener('readystatechange', onReady); } }; window.addEventListener('DOMContentLoaded', onReady); window.addEventListener('readystatechange', onReady); onReady(); } })();