URL Redirect Redirecter

Redirect the Redirected Url

目前为 2023-07-14 提交的版本。查看 最新版本

// ==UserScript==
// @name            URL Redirect Redirecter
// @namespace       FaustVXUrlRedirect
// @version         0.3
// @description     Redirect the Redirected Url
// @author          FaustVX
// @match           http*://www.curseforge.com/*
// @match           http*://legacy.curseforge.com/*
// @match           http*://*.youtube.com/*
// @match           http*://twitter.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"));
    } else if (domainName[0] === "twitter") {
        document.querySelectorAll('a[href*="t.co/"]').forEach(function(a) {
            if (a.innerHTML.startsWith('<span')) {
                a.href = a.innerHTML = a.innerText.replace(/…$/, '');
            }
        });
    }
};

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

runWhenReady(run);