Old Reddit Open Thread Instead of Post

Replace main links from home subreddits to threads directly rather than posts (Images, other websites, etc.)

目前為 2024-10-05 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Old Reddit Open Thread Instead of Post
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Replace main links from home subreddits to threads directly rather than posts (Images, other websites, etc.)
// @author       Berkay
// @match        https://old.reddit.com/r/*
// @match        https://www.reddit.com/r/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to replace post links with comment/thread links
    function replacePostLinks() {
        // Select all post containers
        const postContainers = document.querySelectorAll('div.thing');

        postContainers.forEach(container => {
            // Find the title link within the container
            const titleLink = container.querySelector('a[data-event-action="title"]');
            // Find the comments link within the container
            const commentsLink = container.querySelector('a[data-event-action="comments"]');

            if (titleLink && commentsLink) {
                // Replace the href of the title link with the href of the comments link
                titleLink.href = commentsLink.href;
            }
        });
    }

    // Run the function when the page loads
    window.addEventListener('load', replacePostLinks);

    // Optionally, observe DOM changes to handle dynamically loaded content
    const observer = new MutationObserver((mutations) => {
        mutations.forEach(() => {
            replacePostLinks();
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();