Old Reddit Auto Expand Images and Post Text, Images in comments

expands medias and post text on old Reddit feeds.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Old Reddit Auto Expand Images and Post Text, Images in comments
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @description  expands medias and post text on old Reddit feeds.
// @author       ein
// @match        *://old.reddit.com/*
// @grant        none
// @license      none
// ==/UserScript==

(function() {
    'use strict';
    [...document.querySelectorAll('a')].forEach((element) => {
        if(element.innerHTML == '<image>'){
            const my_img = document.createElement('img');
            my_img.src = element.href;
            my_img.style = 'width:100%';
            element.replaceWith(my_img);
        }
    });
    function expandContent() {
        const elementsToExpand = [
            '.selftext.collapsed',
            '.expando-button.collapsed.video',
            '.expando-button.collapsed.image',
            '.expando-button.crosspost.collapsed'
        ];
        const firstCollapsed = document.querySelector(elementsToExpand.join(','));
        if (firstCollapsed) {
            if (firstCollapsed.classList.contains('selftext')) {
                firstCollapsed.click();
            } else {
                firstCollapsed.click();
            }
        }
    }

    let iterationCount = 0;

    function limitedExpandContent() {
        if (iterationCount < 25) {
            expandContent();
            iterationCount++;
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', () => {
            setInterval(limitedExpandContent, 1000);
        });
    } else {
        setInterval(limitedExpandContent, 1000);
    }
})();