知乎真實鏈接地址重定向

讓知乎網頁中的站外鏈接直接跳轉至目標網址,而不經過壹個二次跳轉頁面。重定向處理將會在點擊鏈接瞬間自動觸發

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                Zhihu Link Redirect Fix
// @name:zh-CN          知乎真实链接地址重定向
// @name:zh-TW          知乎真實鏈接地址重定向
// @description         Avoid link redirect for zhihu.com
// @description:zh-CN   让知乎网页中的站外链接直接跳转至目标网址,而不经过一个二次跳转页面。重定向处理将会在点击链接瞬间自动触发
// @description:zh-TW   讓知乎網頁中的站外鏈接直接跳轉至目標網址,而不經過壹個二次跳轉頁面。重定向處理將會在點擊鏈接瞬間自動觸發

// @author              Moshel
// @namespace           https://hzy.pw
// @homepageURL         https://hzy.pw/p/2056
// @supportURL          https://github.com/h2y/link-fix
// @license             GPL-3.0
// @icon                https://pic1.zhimg.com/2e33f063f1bd9221df967219167b5de0_m.jpg

// @grant               none
// @run-at              document-start
// @include             *.zhihu.com/*

// @date                06/10/2016
// @modified            05/22/2019
// @version             1.3.2.7
// ==/UserScript==


if(location.host==='link.zhihu.com') {
    let regRet = location.search.match(/target=(.+?)(&|$)/);
    if(regRet && regRet.length==3)
        location.href = decodeURIComponent(regRet[1]);
}
else
    window.addEventListener('click', function(e){
        let dom = e.target,
            max_times = 5;
        while(dom && max_times--) {
            if(dom.nodeName.toUpperCase()==='A') {
                let regRet = dom.search.match(/target=(.+?)(&|$)/);
                if(regRet && regRet.length==3)
                    dom.href = decodeURIComponent(regRet[1]);
                return;
            }
            else
                dom = dom.parentNode;
        }
    });