Frontend-Redirectr

Redirect popular sites to alternative privacy-friendly frontends

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Frontend-Redirectr
// @namespace    https://github.com/NimiGames68/Frontend-Redirectr
// @version      1.0
// @description  Redirect popular sites to alternative privacy-friendly frontends
// @license      MIT
// @author       NimiGames68
// @match        *://genius.com/*
// @match        *://*.genius.com/*
// @match        *://imgur.com/*
// @match        *://*.imgur.com/*
// @match        *://medium.com/*
// @match        *://*.medium.com/*
// @match        *://pastebin.com/*
// @match        *://*.pastebin.com/*
// @match        *://*.pinterest.com/*
// @match        *://tenor.com/*
// @match        *://*.tenor.com/*
// @match        *://twitch.tv/*
// @match        *://*.twitch.tv/*
// @match        *://music.youtube.com/*
// @match        *://youtube.com/*
// @match        *://*.youtube.com/*
// @match        *://youtu.be/*
// @match        *://translate.google.com/*
// @include      /^https?:\/\/translate\.google\.[^/]+\/.*/
// @match        *://*.stackexchange.com/*
// @match        *://*.stackoverflow.com/*
// @match        *://*.superuser.com/*
// @match        *://*.serverfault.com/*
// @match        *://*.askubuntu.com/*
// @match        *://*.stackapps.com/*
// @match        *://*.mathoverflow.net/*
// @match        *://*.bing.com/*
// @match        *://*.tumblr.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    const host = location.hostname;

    // Google Translate → Mozhi
    if (/^translate\.google\.[^/]+$/i.test(host)) {
        location.replace(
            "https://mozhi.canine.tools" +
            location.pathname +
            location.search +
            location.hash
        );
        return;
    }

    // YouTube Music → Ytify
    if (/^music\.youtube\.com$/i.test(host)) {
        const videoId = new URLSearchParams(location.search).get('v');

        location.replace(
            videoId
                ? `https://ytify.pp.ua/?s=${encodeURIComponent(videoId)}`
                : 'https://ytify.pp.ua/'
        );
        return;
    }

    // YouTube → Invidious
    if (/^(www\.)?youtube\.com$/i.test(host)) {
        location.replace(
            "https://inv.nadeko.net" +
            location.pathname +
            location.search +
            location.hash
        );
        return;
    }

    // youtu.be → Invidious
    if (/^youtu\.be$/i.test(host)) {
        location.replace(
            "https://inv.nadeko.net/watch?v=" +
            encodeURIComponent(location.pathname.slice(1))
        );
        return;
    }

    // Stack Exchange → AnonymousOverflow
    if (
        /(^|\.)stackexchange\.com$/i.test(host) ||
        /(^|\.)stackoverflow\.com$/i.test(host) ||
        /(^|\.)superuser\.com$/i.test(host) ||
        /(^|\.)serverfault\.com$/i.test(host) ||
        /(^|\.)askubuntu\.com$/i.test(host) ||
        /(^|\.)stackapps\.com$/i.test(host) ||
        /(^|\.)mathoverflow\.net$/i.test(host)
    ) {
        let newUrl;

        if (
            host === "stackoverflow.com" ||
            host === "www.stackoverflow.com"
        ) {
            newUrl =
                "https://overflow.hostux.net" +
                location.pathname +
                location.search +
                location.hash;
        } else {
            newUrl =
                "https://overflow.hostux.net/exchange/" +
                host +
                location.pathname +
                location.search +
                location.hash;
        }

        location.replace(newUrl);
        return;
    }

    const redirects = {
        "genius.com": "https://genius.fsky.io",
        "imgur.com": "https://imgur.artemislena.eu",
        "medium.com": "https://m.opnxng.com",
        "pinterest.com": "https://pinterest.bunk.im",
        "tenor.com": "https://tenor.fsky.io",
        "twitch.tv": "https://safetwitch.darkness.services",
        "tumblr.com": "https://priviblur.canine.tools",
        "www.bing.com": "https://startpage.com"
    };

    for (const domain in redirects) {
        if (host === domain || host.endsWith("." + domain)) {
            location.replace(
                redirects[domain] +
                location.pathname +
                location.search +
                location.hash
            );
            return;
        }
    }
})();