Reddit Original + External Image Downloader

Download i.redd.it original images and external images from Reddit posts; button hides while scrolling and shows when stopped

目前為 2025-10-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit Original + External Image Downloader
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Download i.redd.it original images and external images from Reddit posts; button hides while scrolling and shows when stopped
// @author       ChatGPT
// @license      MIT
// @match        https://www.reddit.com/r/*/comments/*
// @match        https://old.reddit.com/r/*/comments/*
// @grant        GM_download
// ==/UserScript==

(function() {
    'use strict';

    // Create minimalistic download button
    const btn = document.createElement('button');
    btn.innerHTML = '⬇️'; // Download arrow
    btn.style.position = 'fixed';
    btn.style.top = '80px';
    btn.style.right = '20px';
    btn.style.zIndex = '9999';
    btn.style.border = 'none';
    btn.style.background = 'transparent';
    btn.style.color = '#1d72b8';
    btn.style.fontSize = '28px';
    btn.style.cursor = 'pointer';
    btn.style.transition = 'transform 0.2s, opacity 0.3s';
    btn.style.opacity = '1';
    document.body.appendChild(btn);

    // Hover effect: scale up slightly
    btn.addEventListener('mouseenter', () => {
        btn.style.transform = 'scale(1.3)';
    });
    btn.addEventListener('mouseleave', () => {
        btn.style.transform = 'scale(1)';
    });

    // Scroll hide / show logic
    let scrollTimer;
    window.addEventListener('scroll', () => {
        btn.style.opacity = '0'; // hide while scrolling
        clearTimeout(scrollTimer);
        scrollTimer = setTimeout(() => {
            btn.style.opacity = '1'; // show after stop
        }, 300); // 300ms after scrolling stops
    });

    btn.addEventListener('click', () => {
        const imgs = new Set();

        // Scan all <img> tags
        document.querySelectorAll('img').forEach(img => {
            const src = img.src;
            // Conditions:
            // 1. Must have src
            // 2. Exclude base64 inline images
            // 3. Exclude preview.redd.it
            // 4. Exclude Reddit tracking GIFs (rlcdn.com)
            // 5. Exclude other reddit internal resources, except i.redd.it
            if (src &&
                !src.startsWith('data:image') &&
                !src.includes('preview.redd.it') &&
                !src.includes('rlcdn.com') &&
                (!src.includes('reddit') || src.includes('i.redd.it'))) {
                imgs.add(src);
            }
        });

        if (imgs.size === 0) {
            alert('No images found! Please scroll the page to load all images.');
            return;
        }

        alert(`Found ${imgs.size} images. Starting download (browser may prompt multiple times).`);

        // Download all collected images
        imgs.forEach(url => {
            const name = url.split('/').pop().split('?')[0];
            GM_download({ url: url, name: name, saveAs: false });
        });
    });
})();