资源下载器(下载资源、Zip 压缩、下载到本地)
이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/559087/1716149/zip-downloader.js을(를) 사용하여 포함하는 라이브러리입니다.
资源下载器(下载资源、Zip 压缩、下载到本地)
Options 参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
filename |
string | 否 | 保存的文件名,添加此参数时会将压缩包保存到本地,未配置返回压缩包的 Blob 对象 | |
resources |
Resource[] | 是 | 资源列表,数组,每个元素为对象,包含 name 和 url 或者 blob 字段 |
|
concurrency |
number | 否 | 10 |
并发数,默认 10 |
onProgress |
(index: number) => Promise | 否 | 下载进度回调函数,参数为当前正在下载的资源索引 |
Resource 参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
name |
string | 是 | 资源名称 | |
url |
string | 否 | URL 类型资源 | |
blob |
Blob | 否 | Blob 类型资源 |
下载,压缩,并保存到本地
await zipDownloader({
filename: 'index.zip',
resources: [
{ name: 'index.html', url: location.href },
{
name: 'hello.txt',
blob: new Blob(['hello world'], { type: 'text/plain' }),
},
],
concurrency: 10,
async onProgress(index) {
console.log(`正在下载第 ${index + 1} 个资源`)
},
})
仅下载和压缩
const blob = await zipDownloader({
resources: [
{ name: 'index.html', url: location.href },
{
name: 'hello.txt',
blob: new Blob(['hello world'], { type: 'text/plain' }),
},
],
concurrency: 10,
async onProgress(index) {
console.log(`正在下载第 ${index + 1} 个资源`)
},
})
// 自行处理
// GM_download(URL.createObjectURL(blob), 'index.zip')
// ==UserScript==
// @require https://**/zip-downloader.js?*
// @grant GM_download
// ==/UserScript==
(async function () {
'use strict'
await zipDownloader({
filename: 'index.zip',
resources: [
{ name: 'index.html', url: location.href },
{
name: 'hello.txt',
blob: new Blob(['hello world'], { type: 'text/plain' }),
},
],
concurrency: 10,
async onProgress(index) {
console.log(`正在下载第 ${index + 1} 个资源`)
},
})
})()
npm create monkey
npm i @xiaohuohumax/zip-downloader
import zipDownloader from '@xiaohuohumax/zip-downloader'
await zipDownloader({
filename: 'index.zip',
resources: [
{ name: 'index.html', url: location.href },
{
name: 'hello.txt',
blob: new Blob(['hello world'], { type: 'text/plain' }),
},
],
concurrency: 10,
async onProgress(index) {
console.log(`正在下载第 ${index + 1} 个资源`)
},
})
import { defineConfig } from 'vite'
import monkey, { cdn } from 'vite-plugin-monkey'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
monkey({
build: {
externalGlobals: {
'@xiaohuohumax/zip-downloader': cdn.jsdelivr('zipDownloader', 'dist/index.lib.js'),
},
},
userscript: {
grant: ['GM_download']
},
}),
],
})
GreasyFork 或者 ScriptCat 回复不及时,问题反馈推荐直接在 Github 提 Issue。
如果觉得本脚本对你有帮助,欢迎点个 ⭐ Star 支持一下!