禁用知乎外链跳转提示

移除网页版知乎的"即将离开知乎"外链跳转提示

As of 06.12.2021. See ბოლო ვერსია.

// ==UserScript==
// @name         禁用知乎外链跳转提示
// @namespace    http://reeky.org/
// @version      0.2
// @description  移除网页版知乎的"即将离开知乎"外链跳转提示
// @author       ReekyStive
// @match        *://*.zhihu.com/*
// @icon         https://static.zhihu.com/heifetz/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    let replace = function () {
        console.log('Replacing');
        let links = document.querySelectorAll('.external, .LinkCard');
        for (let item of links) {
            let link = item.getAttribute('href');
            let matcher = /.*?link\.zhihu\.com\/\?target=/i;
            let originalLink = decodeURIComponent(link.replace(matcher, ''));
            if (link !== originalLink) {
                console.log(originalLink);
            }
            item.setAttribute('href', originalLink);
        }
    };

    let intervalId = setInterval(() => { replace(); }, 3000);
    setTimeout(() => { clearInterval(intervalId); }, 60000);
})();