外链自动跳转

跳转嘎嘎快,适配语雀,少数派,简书,掘金,CSDN,InfoQ,知乎等大部分网站,打开外链时,自动跳转到目标网站.

目前為 2023-03-28 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         外链自动跳转
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  跳转嘎嘎快,适配语雀,少数派,简书,掘金,CSDN,InfoQ,知乎等大部分网站,打开外链时,自动跳转到目标网站.
// @author       uiliugang
// @run-at       document-start
// @match        *://*/*
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    let url = window.location.href;
    // 经本人观察, 主流网站的重定向页面会包含?, 如果不包含?, 默认不是重定向页面, 不跳转.
    if(url.indexOf('?') == -1) return;
    let processedUrl = processUrl(url);
    if(processedUrl !== url){
        window.location.replace(processedUrl);
    }
    function processUrl(redirectURL) {
        let linkSections;
        let redirectIdentifier = ['?target=', '?to=', '?ac=2&url=', '?url=','?remoteUrl=','?redirect=','?u=','?goto=','?link='];
        for (let i = 0; i < redirectIdentifier.length; i++) {
            let identifier = redirectIdentifier[i];
            if (redirectURL.indexOf(identifier) !== -1) {
                linkSections = redirectURL.split(identifier);
                return decodeURIComponent(linkSections[1]);
            }
        }
        return redirectURL;
    }
})();