Reddit Hot Redirect with Logo Click Handler

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Reddit Hot Redirect with Logo Click Handler
// @namespace   https://greasyfork.org/en/users/594496-divided-by
// @author      dividedby
// @description Redirects default frontpage from 'best' to 'hot' and handles logo clicks
// @version     1.4
// @license     GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @contributionURL     https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&item_name=Reddit+Hot+Donation
// @contributionAmount  $1
// @match       https://www.reddit.com/*
// @run-at      document-start

// ==/UserScript==

(function() {
    'use strict';

    function redirectToHot() {
        // Automatically redirect only on homepage
        if (window.location.pathname === '/') {
            window.location.href = 'https://www.reddit.com/hot';
        }
    }

    function handleLogoClick(e) {
        e.preventDefault();
        // Always redirect to hot regardless of current page
        window.location.href = 'https://www.reddit.com/hot';
    }

    function attachLogoListener() {
        const logo = document.querySelector('#reddit-logo');
        if (logo && !logo.dataset.hotRedirect) {
            logo.dataset.hotRedirect = true;
            logo.addEventListener('click', handleLogoClick);
        }
    }

    // Initial redirect only on homepage
    redirectToHot();

    // Set up MutationObserver to handle dynamically loaded content
    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            if (mutation.type === 'childList') {
                attachLogoListener();
            }
        }
    });

    // Start observing the document with the configured parameters
    observer.observe(document.body, { childList: true, subtree: true });

    // Attach listener to initial logo if it exists
    attachLogoListener();

    // Listen for navigation events (popstate)
    window.addEventListener('popstate', redirectToHot);
})();