Reddit to Libreddit Redirect

Redirects Reddit links to Libreddit links automatically.

目前為 2023-06-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Reddit to Libreddit Redirect
// @namespace    https://kbin.social/u/LollerCorleone
// @version      1.0
// @description  Redirects Reddit links to Libreddit 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 Libreddit homepage
        window.location.replace('https://libreddit.privacy.com.de/');
        return; // Stop further script execution
    } else if (currentUrl.match(/https?:\/\/(?:www|old)\.reddit\.com\/r\/\w+\//)) {
        // Construct the Libreddit subreddit URL
        var libredditUrl = currentUrl.replace(/https?:\/\/(?:www|old)\.reddit\.com/, 'https://libreddit.privacy.com.de');
        
        // Redirect to the Libreddit subreddit URL
        window.location.replace(libredditUrl);
        return; // Stop further script execution
    } else if (currentUrl.match(/https?:\/\/(?:www|old)\.reddit\.com\/r\/\w+\/comments\/\w+\//)) {
        // Construct the Libreddit post URL
        var libredditUrl = currentUrl.replace(/https?:\/\/(?:www|old)\.reddit\.com/, 'https://libreddit.privacy.com.de');
        
        // Redirect to the Libreddit post URL
        window.location.replace(libredditUrl);
        return; // Stop further script execution
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址