URL Redirect Redirecter

Redirect the Redirected Url

目前為 2023-07-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            URL Redirect Redirecter
// @namespace       FaustVXUrlRedirect
// @version         0.2
// @description     Redirect the Redirected Url
// @author          FaustVX
// @match           https://www.curseforge.com/*
// @match           https://legacy.curseforge.com/*
// @match           https://*.youtube.com/*
// @grant           none
// @supportURL      https://gist.github.com/FaustVX/0deb00258929a517a6e2796f9020e17c#comments
// @contributionURL https://www.paypal.com/donate/?cmd=_donations&[email protected]&item_name=TamperMonkey+Url+Redirect
// @license         MIT
// ==/UserScript==

const run = function() {
    'use strict';

    function changeHref(query) {
        return function (a) {
            const urlParams = new URLSearchParams(a.search);
            const url = urlParams.get(query);
            a.href = decodeURIComponent(url);
        }
    }

    const urlSplit = window.location.href.split('/');
    const domainName = urlSplit[2].split('.');
    if (domainName[1] === "curseforge") {
        document.querySelectorAll('a[href*="/linkout"]').forEach(changeHref("remoteUrl"));
    } else if (domainName[1] === "youtube") {
        document.querySelectorAll('a[href*="/redirect"]').forEach(changeHref("q"));
    }
};

function runWhenReady(callback) {
    const tryNow = function() {
        try {
            callback();
        } catch { }
        setTimeout(tryNow, 250);
    };
    tryNow();
}

runWhenReady(run);