Advertisement
Guest User

Reddit 2nd gen UI

a guest
Aug 26th, 2024
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // ==UserScript==
  2. // u/name Reddit 2nd Gen UI Switcher
  3. // u/namespace
  4. // u/version 0.6
  5. // 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.
  6. // u/author almightyco
  7. // u/match https://new.reddit.com/
  8. // u/match https://new.reddit.com/message/inbox/
  9. // u/grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const homepageUrl = 'https://new.reddit.com/';
  16. const messagesUrl = 'https://new.reddit.com/message/inbox/';
  17.  
  18. // Function to simulate the logo click
  19. function simulateLogoClick() {
  20. const logoLink = document.querySelector('a[href="/"]');
  21. if (logoLink) {
  22. logoLink.click(); // Click the logo to return to the homepage
  23. } else {
  24. setTimeout(simulateLogoClick, 100); // Retry if the logo is not yet available
  25. }
  26. }
  27.  
  28. if (window.location.href === homepageUrl && !sessionStorage.getItem('returningFromMessages')) {
  29. // If on homepage and haven't yet redirected, go to messages page
  30. sessionStorage.setItem('returningFromMessages', 'true');
  31. window.location.href = messagesUrl;
  32. } else if (window.location.href === messagesUrl) {
  33. // If on messages page, simulate the logo click to return to homepage
  34. setTimeout(simulateLogoClick, 500); // Delay to ensure page elements load
  35. } else if (sessionStorage.getItem('returningFromMessages')) {
  36. // When back on homepage, clear the flag
  37. sessionStorage.removeItem('returningFromMessages');
  38. }
  39. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement