Reddit old new swticher link

Adds links to old.reddit on new reddit pages, and links to new reddit on old.reddit pages.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Reddit old new swticher link
// @namespace    https://reddit.com/
// @version      2
// @description  Adds links to old.reddit on new reddit pages, and links to new reddit on old.reddit pages.
// @author       Tehhund
// @match        *://*.reddit.com/*
// @match        *://reddit.com/*
// @icon         https://www.redditstatic.com/shreddit/assets/favicon/64x64.png
// @run-at       document-start
// @license      MIT
// ==/UserScript==

addLinks = () => {
  if (document.getElementsByClassName(`oldNewRedditSwitcher`)[0]) { return } // If the script already ran, do nothing.
  let oldOrNew = new URL(window.location.href).host.includes(`old.reddit`) ? `New` : `Old`;
  let myUrl = new URL(window.location.href);
  myUrl.host = `${(oldOrNew) == `Old` ? `old` : `www`}.reddit.com`;
  if (oldOrNew == `Old`) {
    const link = document.getElementById(`create-post`).cloneNode(false);
    link.classList.add(`oldNewRedditSwitcher`);
    link.textContent = `${oldOrNew} Reddit`;
    link.href = myUrl.href;
    document.getElementById(`create-post`).insertAdjacentElement(`afterend`, link);
  } else {
    const link = document.createElement(`a`)
    link.classList.add(`oldNewRedditSwitcher`);
    link.textContent = `${oldOrNew} Reddit`;
    link.href = myUrl.href;
    document.getElementById(`redesign-beta-optin-btn`).insertAdjacentElement(`afterend`, link);
  }
}

try { addLinks(); } catch (e) { }// If the script runs after DOMContentLoaded this will add the links. If it runs before DOMContentLoaded, this will error and the listener below will run it instead.
window.addEventListener('DOMContentLoaded', addLinks);