语雀文档链接直达,避免语雀提醒风险:"如需浏览,请复制后访问。"

在语雀文档中,点开链接跳转时,直达目标地址。把语雀强行附加的中转链接,还原为原始链接。不再提示:“该链接疑似存在风险,请谨慎操作。如需浏览,请复制后访问。”

// ==UserScript==
// @name         语雀文档链接直达,避免语雀提醒风险:"如需浏览,请复制后访问。"
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  在语雀文档中,点开链接跳转时,直达目标地址。把语雀强行附加的中转链接,还原为原始链接。不再提示:“该链接疑似存在风险,请谨慎操作。如需浏览,请复制后访问。”
// @author       yezi_jinn
// @match        *://www.yuque.com/r/goto*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 性能优化:使用最高效的URL参数解析
    const getUrlParam = (name) => {
        // 直接操作URL字符串避免创建URL对象
        const queryStart = window.location.href.indexOf('?');
        if (queryStart === -1) return null;

        const params = window.location.href.slice(queryStart + 1);
        const nameEq = name + '=';
        const pairs = params.split('&');

        for (let i = 0; i < pairs.length; i++) {
            const pair = pairs[i];
            if (pair.startsWith(nameEq)) {
                return pair.slice(nameEq.length);
            }
        }
        return null;
    };

    // 主执行函数(无任何UI操作)
    const redirectImmediately = () => {
        // 1. 获取URL参数
        const encodedUrl = getUrlParam('url');
        if (!encodedUrl) return;

        try {
            // 2. 直接使用原生解码(最快方法)
            const decodedUrl = decodeURIComponent(encodedUrl);

            // 3. 极简URL验证
            if (decodedUrl.startsWith('http://') || decodedUrl.startsWith('https://')) {
                // 4. 最高效重定向方式
                window.stop(); // 立即停止页面加载
                window.location.replace(decodedUrl); // 不产生历史记录
            }
        } catch(e) {
            // 最小化错误处理
        }
    };

    // 立即执行(不等待DOM)
    redirectImmediately();
})();