去除知乎外部链接拦截

知乎所有外部链接在点击跳转时,会被拦截,并进行二次确认后才能跳转,这个脚本的就是清除所有针对外链的拦截

// ==UserScript==
// @name         去除知乎外部链接拦截
// @namespace    http://tampermonkey.net/
// @version      v1.2
// @description  知乎所有外部链接在点击跳转时,会被拦截,并进行二次确认后才能跳转,这个脚本的就是清除所有针对外链的拦截
// @author       Buddha
// @match        https://*.zhihu.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zhihu.com
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const prefixUrl = /^https?:\/\/link\.zhihu\.com\/\?target=/;
    const replaceUrl = (node)=>{
        if (prefixUrl.test(node.href)) {
            node.href = decodeURIComponent(node.href.replace(prefixUrl, ''));
        }
    };

    const mutationFun = (node)=>{
        if (!node) return;
		const observer = new MutationObserver(mutations=>{
			mutations.filter(m=>m.type==='childList').forEach(mutation=>{
				Array.from(mutation.addedNodes).forEach(item=>mutationFun(item));
				node.querySelectorAll('a[class]').forEach(m=>replaceUrl(m));
			});
		});
        const option = {childList: true, characterData: true, subtree: true};
		observer.observe(node, option);
    };

    /* 适用于知乎首页、个人主页、问题页 动态加载 */
    mutationFun(document.querySelector('.ListShortcut'));

    /* 针对文章详情页 */
    document.querySelectorAll('.RichText a').forEach(link =>replaceUrl(link));

    /* 针对文章详情页 评论区 延时加载 */
    mutationFun(document.querySelector('.Post-Sub'));
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址