Greasy Fork

Greasy Fork is available in English.

劲到六七之图片打包下载工具

A tool to help you quickly package and download images on the web

当前为 2024-04-17 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         劲到六七之图片打包下载工具
// @namespace    http://tampermonkey.net/
// @version      2024-04-16
// @description  A tool to help you quickly package and download images on the web
// @description:zh-CN  一个帮你快速打包下载网页上图片的工具
// @author       <[email protected]>
// @license      GPLv3
// @match        https://www.cnblogs.com/
// @icon         https://s21.ax1x.com/2024/04/16/pFxNgjH.jpg
// @require      https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js
// @grant        GM_xmlhttpRequest
// @include     *://medium.com/*
// @include     *://twitter.com/*
// @include     *://*.twitter.com/*
// @include     *://weibo.com/*
// @include     *://*.weibo.com/*
// @include     *://*.vmgirls.com/*
// @include     *://wallpaperhub.app/*
// @include     *://*.bing.com/*
// @include     *://*.msn.cn/*
// @include     *://instagram.com/*
// @include     *://*.instagram.com/*
// @include     *://instagram.com/*
// @include     *://*.instagram.com/*
// @include     *://tiktok.com/*
// @include     *://*.tiktok.com/*
// @include     *://*.douyin.com/*
// @include     *://*.kuaishou.com/*
// @include     *://*.xiaohongshu.com/*

// ==/UserScript==

(function() {
    let imgs = document.querySelectorAll('img')
    let urls = []
    imgs.forEach(item=>{
        if(!item.src)return
        urls.push(item.src)
    })
    const imageUrls = urls
    const zip = new JSZip();
    Promise.all(imageUrls.map((url, index) =>{
        return new Promise((resolve, reject) =>{
            GM_xmlhttpRequest({
                method: "GET",
                url: url,
                responseType: "blob",
                onload: function(response) {
                    if (response.status === 200) {
                        let blob = response.response
                        const filename = `image${index + 1}.jpg`;
                        zip.file(filename, blob, { binary: true });

                    } else {
                        console.error("Request failed with status " + response.status);
                    }
                    resolve()
                },
                onerror: function(e) {
                    console.error("Request failed: " + e.message);
                    resolve()
                }
            });
        })

    })).then(() => {
        zip.generateAsync({ type: 'blob' }).then(blob => {
            saveAs(blob, 'images.zip');
        });
    }).catch(error => {
        console.error('Error downloading images:', error);
    });
})();