Greasy Fork 还支持 简体中文。

Reddit Hot Redirect with Logo Click Handler

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

目前為 2024-09-15 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.3
// @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() {
        if (window.location.pathname === '/' || window.location.pathname.startsWith('/r/')) {
            window.location.href = 'https://www.reddit.com/hot';
        }
    }

    function handleLogoClick(e) {
        e.preventDefault();
        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
    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
    window.addEventListener('popstate', redirectToHot);
})();