Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // u/name Reddit 2nd Gen UI Switcher
- // u/namespace
- // u/version 0.6
- // u/description Forces Reddit to use the 2nd generation UI on new.reddit.com by navigating from the messages page when loading a new reddit homepage.
- // u/author almightyco
- // u/match https://new.reddit.com/
- // u/match https://new.reddit.com/message/inbox/
- // u/grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const homepageUrl = 'https://new.reddit.com/';
- const messagesUrl = 'https://new.reddit.com/message/inbox/';
- // Function to simulate the logo click
- function simulateLogoClick() {
- const logoLink = document.querySelector('a[href="/"]');
- if (logoLink) {
- logoLink.click(); // Click the logo to return to the homepage
- } else {
- setTimeout(simulateLogoClick, 100); // Retry if the logo is not yet available
- }
- }
- if (window.location.href === homepageUrl && !sessionStorage.getItem('returningFromMessages')) {
- // If on homepage and haven't yet redirected, go to messages page
- sessionStorage.setItem('returningFromMessages', 'true');
- window.location.href = messagesUrl;
- } else if (window.location.href === messagesUrl) {
- // If on messages page, simulate the logo click to return to homepage
- setTimeout(simulateLogoClick, 500); // Delay to ensure page elements load
- } else if (sessionStorage.getItem('returningFromMessages')) {
- // When back on homepage, clear the flag
- sessionStorage.removeItem('returningFromMessages');
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement