ExternallinkDoctor

Convert external links to the raw link.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ExternallinkDoctor
// @namespace    [email protected]
// @version      0.1
// @description  Convert external links to the raw link.
// @author       gwentmaster <[email protected]>
// @match        *://juejin.cn/*
// @match        *://www.jianshu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let hostMap = {
        juejin: "juejin.cn",
        jianshu: "jianshu.com"
    };
    let doctorMap = {
        juejin: () => {
            document.querySelectorAll("a").forEach((a) => {
                let link = a.getAttribute("href");
                if (/.+\:\/\/link\.juejin\.cn\/?\?.*target=/.test(link)) {
                    let params = new URLSearchParams(new URL(link).search);
                    a.setAttribute("href", params.get("target"));
                }
            });
        },
        jianshu: () => {
            document.querySelectorAll("a").forEach((a) => {
                let link = a.getAttribute("href");
                if (/.+\:\/\/links.jianshu.com\/go\/?\?.*to=/.test(link)) {
                    let params = new URLSearchParams(new URL(link).search);
                    a.setAttribute("href", params.get("to"))
                }
            });
        }
    };

    let hostname = window.location.hostname;
    for (let site in hostMap) {
        if (hostname.indexOf(hostMap[site]) !== -1) {
            window.onload = doctorMap[site];
            break;
        }
    }

})();