Reddit to Teddit Redirect

Redirects Reddit links to random teddit.net instances automatically and provides an option to reload in a different instance.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit to Teddit Redirect
// @namespace    https://kbin.social/u/LollerCorleone
// @version      1.2
// @description  Redirects Reddit links to random teddit.net instances automatically and provides an option to reload in a different instance.
// @author       LollerCorleone
// @license      GNU GPLv3
// @match        *://www.reddit.com/*
// @match        *://old.reddit.com/*
// @match        *://teddit.net/*
// @match        *://teddit.pussthecat.org/*
// @match        *://teddit.sethforprivacy.com/*
// @match        *://teddit.bus-hit.me/*
// @match        *://teddit.adminforge.de/*
// @match        *://teddit.totaldarkness.net/*
// @match        *://teddit.zaggy.nl/*
// @match        *://teddit.froth.zone/*
// @match        *://teddit.projectsegfau.lt/*
// @match        *://rdt.trom.tf/*
// @match        *://i.opnxng.com/*
// @match        *://teddit.garudalinux.org/*
// @match        *://teddit.no-logs.com/*
// @match        *://teddit.hostux.net/*
// @match        *://teddit.artemislena.eu/*
// @match        *://teddit.rawbit.ninja/*
// @match        *://teddit.privacytools.io/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // List of teddit instances
    var tedditInstances = [
        'https://teddit.net',
        'https://teddit.pussthecat.org',
        'https://teddit.sethforprivacy.com',
        'https://teddit.bus-hit.me',
        'https://teddit.adminforge.de',
        'https://teddit.totaldarkness.net',
        'https://teddit.zaggy.nl',
        'https://teddit.froth.zone',
        'https://teddit.projectsegfau.lt',
        'https://rdt.trom.tf',
        'https://i.opnxng.com',
        'https://teddit.garudalinux.org',
        'https://teddit.no-logs.com',
        'https://teddit.hostux.net',
        'https://teddit.artemislena.eu',
        'https://teddit.rawbit.ninja',
        'https://teddit.privacytools.io'
    ];

    // Get the current URL
    var currentUrl = window.location.href;

    // Check if the URL matches the Reddit homepage
    if (currentUrl === 'https://www.reddit.com/' || currentUrl === 'https://old.reddit.com/') {
        // Redirect to a random teddit instance's homepage
        var randomInstance = tedditInstances[Math.floor(Math.random() * tedditInstances.length)];
        var tedditUrl = randomInstance + '/r/all';
        window.location.replace(tedditUrl);
        return; // Stop further script execution
    } else if (currentUrl.match(/https?:\/\/(?:www|old|teddit)\.reddit\.com\/r\/\w+\//)) {
        // Construct the teddit.net subreddit URL
        var randomInstance = tedditInstances[Math.floor(Math.random() * tedditInstances.length)];
        var tedditUrl = currentUrl.replace(/https?:\/\/(?:www|old|teddit)\.reddit\.com/, randomInstance);

        // Redirect to the random teddit instance's subreddit URL
        window.location.replace(tedditUrl);
        return; // Stop further script execution
    } else if (currentUrl.match(/https?:\/\/(?:www|old|teddit)\.reddit\.com\/r\/\w+\/comments\/\w+\//)) {
        // Construct the teddit.net post URL
        var randomInstance = tedditInstances[Math.floor(Math.random() * tedditInstances.length)];
        var tedditUrl = currentUrl.replace(/https?:\/\/(?:www|old|teddit)\.reddit\.com/, randomInstance);

        // Redirect to the random teddit instance's post URL
        window.location.replace(tedditUrl);
        return; // Stop further script execution
    }

    // Add a reload button to the teddit page
    function addReloadButton() {
        var button = document.createElement('button');
        button.innerText = 'Reload in Another Instance';
        button.style.position = 'fixed';
        button.style.bottom = '2vh';
        button.style.right = '2vh';
        button.style.zIndex = '9999';
        button.style.padding = '10px';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.backgroundColor = '#007BFF';
        button.style.color = '#fff';
        button.style.cursor = 'pointer';
        button.style.fontSize = '16px';

        button.addEventListener('click', function() {
            // Redirect to a different random teddit instance when clicked
            var randomInstance = tedditInstances[Math.floor(Math.random() * tedditInstances.length)];
            window.location.href = randomInstance + window.location.pathname;
        });

        document.body.appendChild(button);
    }

    // Add the reload button when the teddit page is loaded
    window.addEventListener('load', addReloadButton);
})();