Zhihu Link Replacer

Remove 'leaving zhihu' prompt when accessing external link

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name               Zhihu Link Replacer
// @name:zh-CN         禁用知乎外链跳转提示
// @version            0.3
// @description        Remove 'leaving zhihu' prompt when accessing external link
// @description:zh-CN  移除网页版知乎的 "即将离开知乎" 外链跳转提示
// @author             ReekyStive
// @match              *://*.zhihu.com/*
// @icon               https://static.zhihu.com/heifetz/favicon.ico
// @grant              none
// @license            MIT
// @namespace http://reeky.org/
// ==/UserScript==

(function () {
    'use strict';

    const replace = function () {
        console.log('[Zhihu Link Replacer] Replacing...');
        const links = document.querySelectorAll('.external, .LinkCard');
        let count = 0;
        for (let item of links) {
            const link = item.getAttribute('href');
            const matcher = /.*?link\.zhihu\.com\/\?target=/i;
            const originalLink = decodeURIComponent(link.replace(matcher, ''));
            if (link !== originalLink) {
                console.log('[Zhihu Link Replacer] Replaced ' + originalLink);
                count += 1;
            }
            item.setAttribute('href', originalLink);
        }
        console.log(`[Zhihu Link Replacer] Replaced ${count} links`);
    };

    const intervalId = setInterval(() => { replace(); }, 3000);
    setTimeout(() => {
        clearInterval(intervalId);
        console.log(`[Zhihu Link Replacer] Stopped replace task`);
    }, 60000);
})();