Rewrite Reddit links to use "Old Reddit"

Rewrites all links to Reddit to "old.reddit.com" to automatically use the original UI, not the new one

目前为 2021-05-24 提交的版本。查看 最新版本

// ==UserScript==
// @name         Rewrite Reddit links to use "Old Reddit"
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Rewrites all links to Reddit to "old.reddit.com" to automatically use the original UI, not the new one
// @author       https://gf.qytechs.cn/en/users/728793-nicolasff
// @match        https://*/*
// @match        http://*/*
// @icon         https://www.reddit.com/favicon.ico
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

(function() {
    'use strict';
    /**
     *                                               Description
     *
     * This script looks for links to Reddit on any page and rewrites them to use old.reddit.com which forces
     * the use of the "old" (or original) site theme, which many people prefer to the current theme.
     *
     */


    /**
     * Each object in the `transforms` array below can have the following fields:
     * 1. `regex` matches link targets and selects them for re-writing
     * 2. `match` defines a lambda that takes a regex match object and returns whether this is a valid candidate for re-writing
     * 3. `replace` defines a lambda that takes a regex match object and returns the new target for the link
    */
    const transforms = [
        {regex: /^(https?:\/\/)((www|new)\.)?(reddit\.com\/.*)/,
         match: m => m[3] !== 'old' && m[4].indexOf('reddit.com/poll/') == -1, // not already containing `.old` and not a poll
         replace: m => 'https://old.' + m[4]},
         {regex: /^(https?:\/\/)redd\.it\/(.*)/,
         match: m => true, // always match
         replace: m => 'https://old.reddit.com/' + m[2]}
    ];

    function cleanupLinks() {
        const anchors = document.getElementsByTagName('a');
        for (var i = 0; i < anchors.length; i++) {
            for (const tr of transforms) {
                const target = anchors[i].href || '';
                const match = tr.regex.exec(target);

                if (match && tr.match(match)) { // link matches
                    const newTarget = tr.replace(match);
                    anchors[i].href = newTarget;
                }
            }
        }
    }
    setInterval(cleanupLinks, 1000); // call again to deal with links that were added dynamically
    cleanupLinks(); // call once first
})();

QingJ © 2025

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