Reddit to Teddit Redirect

Redirects Reddit links to teddit.net links automatically.

Από την 27/06/2023. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Reddit to Teddit Redirect
// @namespace    https://kbin.social/u/LollerCorleone
// @version      1.0
// @description  Redirects Reddit links to teddit.net links automatically.
// @author       LollerCorleone
// @license      GNU GPLv3
// @match        *://www.reddit.com/*
// @match        *://old.reddit.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 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 the teddit.net homepage
        window.location.replace('https://teddit.net/');
        return; // Stop further script execution
    } else if (currentUrl.match(/https?:\/\/(?:www|old)\.reddit\.com\/r\/\w+\//)) {
        // Construct the teddit.net subreddit URL
        var tedditUrl = currentUrl.replace(/https?:\/\/(?:www|old)\.reddit\.com/, 'https://teddit.net');
        
        // Redirect to the teddit.net subreddit URL
        window.location.replace(tedditUrl);
        return; // Stop further script execution
    } else if (currentUrl.match(/https?:\/\/(?:www|old)\.reddit\.com\/r\/\w+\/comments\/\w+\//)) {
        // Construct the teddit.net post URL
        var tedditUrl = currentUrl.replace(/https?:\/\/(?:www|old)\.reddit\.com/, 'https://teddit.net');
        
        // Redirect to the teddit.net post URL
        window.location.replace(tedditUrl);
        return; // Stop further script execution
    }
})();