// ==UserScript== // @name Reddit Button: Old → New // @namespace https://github.com/hectorlizard // @version 1.0 // @description Adds and maintains a ‘New’ button that redirects to the new.reddit.com version of the current page // @homepageURL https://github.com/hectorlizard/reddit-button-old-to-new // @downloadURL https://raw.githubusercontent.com/hectorlizard/reddit-button-old-to-new/main/reddit-button-old-to-new.user.js // @updateURL https://raw.githubusercontent.com/hectorlizard/reddit-button-old-to-new/main/reddit-button-old-to-new.user.js // @match https://old.reddit.com/* // @run-at document-idle // ==/UserScript== (function insertNewRedditLink() { const BUTTON_ID = 'new-reddit-link'; function createListItem() { const li = document.createElement('li'); li.id = BUTTON_ID; const a = document.createElement('a'); a.textContent = 'NR'; a.style.cssText = ` padding-right: 6px; `; a.href = location.href.replace('old.reddit.com', 'www.reddit.com'); a.style.marginRight = '6px'; li.appendChild(a); return li; } function tryInject() { const ul = document.querySelector('ul.flat-list.sr-bar.hover'); if (!ul || ul.querySelector(`#${BUTTON_ID}`)) return; const newLi = createListItem(); const firstLi = ul.querySelector('li'); if (firstLi) { ul.insertBefore(newLi, firstLi); } else { ul.appendChild(newLi); } } tryInject(); const observer = new MutationObserver(tryInject); observer.observe(document.body, { childList: true, subtree: true }); })();