Greasy Fork is available in English.

Old Reddit Open Thread Instead of Post

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

// ==UserScript==
// @name         Old Reddit Open Thread Instead of Post
// @namespace    http://tampermonkey.net/
// @version      1.1
// @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() {
    const currentUrl = window.location.href;
    // Get comment/thread links
    const links2 = document.getElementsByTagName('a');
    const linksArray = Array.from(links2);
    const commentLinks = linksArray.filter(link => {
        const eventAction = link.getAttribute('data-event-action');
        return eventAction === 'comments';
    });
    // Function to replace post links with comment/thread links
    function replacePostLinks() {
        const links = document.querySelectorAll('a[data-event-action="title"]');

        for (let i = 0; i < links.length; i++) {
            const href = links[i].getAttribute('href');

            // Check if the href attribute is a valid URL
            if (href && href.startsWith('http') && !currentUrl.includes('comments')) {
                try {
                    const url = new URL(href);
                    links[i].setAttribute('href', commentLinks[i]);
                } catch (e) {
                    // If the URL is invalid, log the error (or handle it accordingly)
                    console.error(`Invalid URL: ${href}`, e);
                }
            }
        }
    }
    // Run the function when the page loads
    window.addEventListener('load', replacePostLinks);
})()