Reddit Old Auto-Expand ↕️

Automatically expands posts on old.reddit.com

当前为 2023-07-23 提交的版本,查看 最新版本

// ==UserScript==
// @name         Reddit Old Auto-Expand ↕️
// @version      1.7
// @description  Automatically expands posts on old.reddit.com
// @match        https://old.reddit.com/*
// @grant        GM_addStyle
// @icon         https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png
// @namespace    old.reddit.com
// @license      MIT
// ==/UserScript==



(function() {
    'use strict';

    function expandImagePosts() {
        // Select all post elements on the page
        const posts = document.querySelectorAll('.thing');

        // Loop through each post element
        posts.forEach((post) => {
            // Check if the post is an image post with data-type="link"
            if (post.dataset.type === 'link') {
                const expandoButton = post.querySelector('.expando-button');

                // Check if the post has a thumbnail image and is not already expanded
                if (expandoButton && !expandoButton.classList.contains('expanded')) {
                    // Simulate a click event on the expando button to expand the post
                    expandoButton.click();
                }
            }
        });
    }


var customCSS = `

        /* Adjust the size of the thumbnail container */
        .thumbnail {display:none}
        .expando-button {opacity:0 !important}
        .arrow.up {display:block !important}
        .arrow.down {display:block !important}

        .link .title {margin-top:30px; font-weight:bold}
        .link .midcol {margin-top:35px; background:none !important; position:relative !important}
              .midcol {overflow:visible !important}
        .link .score {color: gray !important}
        .link .tagline {margin-top:20px !important}
        .link {border:none !important}

        /* Rounded Corners for Expanded Posts */
        .media-preview {border-radius: 15px;}

        `
GM_addStyle(customCSS);



// Move Comments Button UNDER the expanded Posts -> Buggy!
//////////////////////////////////////////////////////////////////////////////////////////
//     // Function to move the <ul> element under the <div> element
//     function moveElements(ulElement, divElement) {
//         divElement.parentNode.insertBefore(ulElement, divElement.nextSibling);
//     }

//     // Event handler for newly inserted posts
//     function handleNewPost(event) {
//         var target = event.target;
//         if (target.matches('.thing')) {
//             // Get the <ul> and <div> elements within the post
//             var ulElement = target.querySelector('ul.flat-list.buttons');
//             var divElement = target.querySelector('div.expando[data-cachedhtml]');
//             if (ulElement && divElement) {
//                 // Move the <ul> element under the <div> element
//                 moveElements(ulElement, divElement);
//             }
//         }
//     }

//     // Listen for the 'DOMNodeInserted' event on the document body
//     document.body.addEventListener('DOMNodeInserted', handleNewPost);

//     // Move the existing <ul> elements under the corresponding <div> elements
//     var ulElements = document.querySelectorAll('ul.flat-list.buttons');
//     var divElements = document.querySelectorAll('div.expando[data-cachedhtml]');
//     for (var i = 0; i < Math.min(ulElements.length, divElements.length); i++) {
//         moveElements(ulElements[i], divElements[i]);
//     }
 ///////////////////////////////////////////////////////////////////////////////////////


    // Expand image posts initially
    expandImagePosts();
    // Repeat the expansion 
    setInterval(expandImagePosts, 3000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址