New Reddit for Everything but Post Pages

Redirects Reddit pages to new.reddit.com except for post pages, which it redirects to old.reddit.com. This is mainly to allow for compatibility with the Reddit Enhancement Suite, and its ignore user feature, while still maintaining the nice overview of the new.reddit.com home page timeline and profile pages.

目前為 2024-06-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name         New Reddit for Everything but Post Pages
// @namespace    plennhar-new-reddit-for-everything-but-post-pages
// @version      1.0
// @description  Redirects Reddit pages to new.reddit.com except for post pages, which it redirects to old.reddit.com.  This is mainly to allow for compatibility with the Reddit Enhancement Suite, and its ignore user feature, while still maintaining the nice overview of the new.reddit.com home page timeline and profile pages.
// @author       Plennhar
// @match        *://*.reddit.com/*
// @license      MIT
// @grant        none
// ==/UserScript==
// SPDX-FileCopyrightText: 2024 Plennhar
// SPDX-License-Identifier: MIT

(function() {
    'use strict';

    const currentUrl = window.location.href;

    const isPostPage = currentUrl.match(/\/comments\/[a-z0-9]+/i);

    if (isPostPage) {
        if (!currentUrl.includes("old.reddit.com")) {
            const newUrl = currentUrl.replace(/(?:www|new)\.reddit\.com/, "old.reddit.com");
            window.location.replace(newUrl);
        }
    } else {
        if (!currentUrl.includes("new.reddit.com")) {
            const newUrl = currentUrl.replace(/(?:www|old)\.reddit\.com/, "new.reddit.com");
            window.location.replace(newUrl);
        }
    }
})();