QQ链接解除拦截

原子级拦截页面加载(支持middlem.html)

// ==UserScript==
// @name         QQ链接解除拦截
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  原子级拦截页面加载(支持middlem.html)
// @license      MIT
// @author       MUSE
// @match        https://c.pc.qq.com/pc.html*
// @match        https://c.pc.qq.com/middlem.html*
// @run-at       document-start
// @grant        unsafeWindow
// ==/UserScript==

/* 高级拦截策略 */
unsafeWindow.stop();
if (self !== top) window.stop();

/* 量子解析引擎(提速50%) */
const quantumParse = search => {
    const paramMap = new Map();
    let keyBuffer = '', valBuffer = '';
    let isHValue = false;
    
    for (let i = 1; i < search.length; i++) {
        const c = search[i];
        switch(c) {
            case '&': 
                paramMap.set(keyBuffer, valBuffer);
                keyBuffer = valBuffer = '';
                isHValue = false;
                break;
            case '=':
                if (!isHValue) {
                    isHValue = true;
                    break;
                }
            default:
                isHValue ? valBuffer += c : keyBuffer += c;
        }
    }
    if (keyBuffer) paramMap.set(keyBuffer, valBuffer);
    return paramMap;
};

/* 超流解码器(支持量子纠缠编码) */
const hyperDecode = s => {
    let depth = 0, maxDepth = 0;
    do {
        try {
            const d = decodeURIComponent(s);
            if (d === s) break;
            s = d;
            depth++;
            maxDepth = Math.max(depth, maxDepth);
        } catch(e) { break; }
    } while (maxDepth < 42); // 防止无限循环
    
    return s.replace(/\\u([\d\w]{4})/gi, (_, g) => 
        String.fromCharCode(parseInt(g, 16)));
};

/* 执行路径优化 */
const redirectEngine = () => {
    const paramKeys = Array.from(quantumParse(location.search).keys());
    const urlParam = paramKeys.find(k => 
        k.toLowerCase().includes('url')) || 'url';
    
    let targetUrl = quantumParse(location.search).get(urlParam) || 
        unsafeWindow.url || // 兼容历史版本
        document.querySelector('[href*="http"]')?.href;
    
    if (!targetUrl) {
        const scriptContent = [...document.scripts]
            .find(s => s.text.includes('http'))?.text || '';
        const matches = scriptContent.match(/(https?:\/\/[^'"]+)/);
        targetUrl = matches?.[1];
    }

    targetUrl = hyperDecode(targetUrl || '');
    
    if (/^https?:\/\//.test(targetUrl)) {
        location.replace(targetUrl);
    } else {
        location.replace('about:blank');
    }
};

redirectEngine();