打包下载图片
This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/565289/1749527/GM_archiveImages.js
需要引入以下依赖:GM_pLimit|GM_request|JSZip|FileSaver
// @require https://update.greasyfork.org/scripts/565266/1749341/GM_pLimit.js
// @require https://update.greasyfork.org/scripts/565272/1749374/GM_request.js
// @require https://update.greasyfork.org/scripts/565290/1749444/JSZip-v391.js
// @require https://update.greasyfork.org/scripts/565291/1749445/FileSaver-205.js
// @grant GM_xmlhttpRequest
使用:
GM_archiveImages({
images: [
{ name: "01.jpg", url: "https://..." },
{ name: "02.jpg", url: "https://..." },
],
zip: "test.zip",
concurrency: 10,
maxRetries: 5,
onload({ loaded, total }) {
console.log(`下载图片:${loaded}/${total}`);
},
onretry({ url, currentRetry, maxRetries }) {
console.warn(`下载失败,重试 ${currentRetry}/${maxRetries}:${url}`);
},
onerror({ url }) {
console.warn(`下载失败:${url}`);
},
onloaded() {
console.log("下载完成,开始打包…");
},
onarchive(percent) {
console.log(`正在打包:${percent.toFixed(2)}%`);
},
oncomplete() {
console.log("完成!");
},
});