Frontend-Redirectr

Redirect popular sites to alternative privacy-friendly frontends

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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;
        }
    }
})();