Reddit Hot Redirect with Logo Click Handler

Redirects default frontpage from 'best' to 'hot' and handles logo clicks

安装此脚本
作者推荐脚本

您可能也喜欢General URL Cleaner Revived

安装此脚本
  1. // ==UserScript==
  2. // @name Reddit Hot Redirect with Logo Click Handler
  3. // @namespace https://greasyfork.org/en/users/594496-divided-by
  4. // @author dividedby
  5. // @description Redirects default frontpage from 'best' to 'hot' and handles logo clicks
  6. // @version 1.4
  7. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  8. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dividedbyerror@gmail.com&item_name=Reddit+Hot+Donation
  9. // @contributionAmount $1
  10. // @match https://www.reddit.com/*
  11. // @run-at document-start
  12.  
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. function redirectToHot() {
  19. // Automatically redirect only on homepage
  20. if (window.location.pathname === '/') {
  21. window.location.href = 'https://www.reddit.com/hot';
  22. }
  23. }
  24.  
  25. function handleLogoClick(e) {
  26. e.preventDefault();
  27. // Always redirect to hot regardless of current page
  28. window.location.href = 'https://www.reddit.com/hot';
  29. }
  30.  
  31. function attachLogoListener() {
  32. const logo = document.querySelector('#reddit-logo');
  33. if (logo && !logo.dataset.hotRedirect) {
  34. logo.dataset.hotRedirect = true;
  35. logo.addEventListener('click', handleLogoClick);
  36. }
  37. }
  38.  
  39. // Initial redirect only on homepage
  40. redirectToHot();
  41.  
  42. // Set up MutationObserver to handle dynamically loaded content
  43. const observer = new MutationObserver((mutations) => {
  44. for (const mutation of mutations) {
  45. if (mutation.type === 'childList') {
  46. attachLogoListener();
  47. }
  48. }
  49. });
  50.  
  51. // Start observing the document with the configured parameters
  52. observer.observe(document.body, { childList: true, subtree: true });
  53.  
  54. // Attach listener to initial logo if it exists
  55. attachLogoListener();
  56.  
  57. // Listen for navigation events (popstate)
  58. window.addEventListener('popstate', redirectToHot);
  59. })();