Greasy Fork

Greasy Fork is available in English.

Desu Image Downloader

Download images with original filenames on desuarchive.org (all boards)

当前为 2024-08-06 提交的版本,查看 最新版本

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Desu Image Downloader
// @version      1.15
// @description  Download images with original filenames on desuarchive.org (all boards)
// @author       Anonimas
// @match        https://desuarchive.org/*
// @grant        GM_download
// @namespace http://greasyfork.icu/users/1342214
// ==/UserScript==

(function() {
    'use strict';

    function getFullFilename(element) {
        return element.getAttribute('title') || element.textContent.trim();
    }

    function downloadImage(imageUrl, originalFilename) {
        if (imageUrl && originalFilename) {
            GM_download({
                url: imageUrl,
                name: originalFilename,
                onload: () => {},
                onerror: (error) => console.error('Download error:', error)
            });
        }
    }

    function handleDownload(event) {
        event.preventDefault();
        const imageLink = event.target.closest('a[href*="//desu-usergeneratedcontent.xyz/"]');
        if (!imageLink) return;

        const imageUrl = imageLink.href;
        let filenameElement = imageLink.closest('div.post_file, article.thread, article.post')?.querySelector('a.post_file_filename');
        if (!filenameElement) return;

        const originalFilename = getFullFilename(filenameElement);
        downloadImage(imageUrl, originalFilename);
    }

    document.querySelectorAll('a[href*="//desu-usergeneratedcontent.xyz/"] i.icon-download-alt').forEach(button => {
        button.closest('a').addEventListener('click', handleDownload);
    });

    document.querySelectorAll('a.post_file_filename').forEach(link => {
        link.addEventListener('click', handleDownload);
    });
})();