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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 });
        });
    });
})();