您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Changes hrefs to old.reddit.com for all posts and comment pages, and redirects to them if necessary. Keeps all other pages as the default design. For this script to work it requires that you NOT opt into old.reddit.com in preferences.
// ==UserScript== // @name New Reddit for Everything but Post Pages // @namespace plennhar-new-reddit-for-everything-but-post-pages // @version 3.1 // @description Changes hrefs to old.reddit.com for all posts and comment pages, and redirects to them if necessary. Keeps all other pages as the default design. For this script to work it requires that you NOT opt into old.reddit.com in preferences. // @author Plennhar // @match *://*reddit.com/* // @license GPL-3.0-or-later // @grant none // ==/UserScript== // SPDX-FileCopyrightText: 2025 Plennhar // SPDX-License-Identifier: GPL-3.0-or-later (function () { 'use strict'; const oldRedditPrefix = 'https://old.reddit.com'; const redditDomainRe = /^https?:\/\/(?:www\.)?reddit\.com/; const videoLinkRe = /^https?:\/\/(?:www\.)?reddit\.com\/link\/[^/]+\/video\//; // Rewrite links so that post pages open on old Reddit, while everything else prefers new Reddit. function updateLinks() { document.querySelectorAll('a[href]').forEach(anchor => { const href = anchor.getAttribute('href'); // Skip anchors without an href. if (!href) return; // Fast flag checks to avoid repeated regexes later. const hasNewParam = href.includes('new_reddit=true'); const isComments = href.includes('/comments/'); const isRelative = href.startsWith('/'); const isModernAbs = redditDomainRe.test(href); const isOldAbs = href.startsWith(oldRedditPrefix); if (isComments && !hasNewParam) { // For all post links land on the old Reddit equivalent (except for in-line video links). let oldUrl; if (isRelative) { oldUrl = oldRedditPrefix + href; } else if (isModernAbs) { oldUrl = href.replace(redditDomainRe, oldRedditPrefix); } if (oldUrl) anchor.setAttribute('href', oldUrl); } else { // For all other links land on the new Reddit equivalent. let newUrl; if (isRelative && location.hostname.startsWith('old.')) { newUrl = 'https://www.reddit.com' + href; } else if (isOldAbs) { newUrl = href.replace(oldRedditPrefix, 'https://www.reddit.com'); } if (newUrl) anchor.setAttribute('href', newUrl); } // Preserve middle‑click behaviour; hijack left‑click to mimic normal in‑page navigation (prevents some extensions/sites from opening extra tabs). anchor.addEventListener('click', evt => { if (evt.button === 1) return; // If middle click then let the browser handle it. if (evt.button === 0 && !anchor.target) { // If left click then open in same‑tab only. evt.preventDefault(); location.href = anchor.href; } }); }); } // If the user lands on a new Reddit post page (not via a video‐link redirect and not explicitly forced), bounce them to the old Reddit equivalent. function redirectIfNecessary() { const onModern = location.hostname.endsWith('reddit.com') && !location.hostname.startsWith('old.'); const fromVideo = videoLinkRe.test(document.referrer); const forcedNew = new URLSearchParams(location.search).get('new_reddit') === 'true'; if (onModern && location.pathname.includes('/comments/') && !fromVideo && !forcedNew) { const oldUrl = location.href.replace(redditDomainRe, oldRedditPrefix); location.replace(oldUrl); // No history entry left behind. } } // Watch for dynamically injected content (stuff like infinite scroll). function observeDOMChanges() { const obs = new MutationObserver(updateLinks); obs.observe(document.body, { childList: true, subtree: true }); } // Initialise everything once the page has fully loaded. window.addEventListener('load', () => { redirectIfNecessary(); updateLinks(); observeDOMChanges(); }); })();