downloader

创建于 1 天前
更新于 1 小时前
资源下载器(下载资源、Zip 压缩、下载到本地)。
总安装量
14
今日新增
+10
用户评分
- / 5.0 (0)
当前版本
1.2.1
// @require https://scriptcat.org/lib/4893/1.2.1/downloader.js?sha384-losyR4t8kCt5XEhrN/LCtgKsMpuog8sByWlUHNZ71N/o+0ZEq0uzFqgcxkW8Qf7M
库详情
这是一个用户脚本使用的库,你可以在你的脚本中直接引用它。

Downloader

资源下载器(下载资源、Zip 压缩、下载到本地)

项目地址 开源协议 更新日志 问题反馈

📖 使用方式

✍ 添加元数据

// ==UserScript==
// @require      https://**/downloader.js?*
// @grant        GM_download
// ==/UserScript==

📥 参数说明

Options 参数说明:

参数名 类型 是否必填 默认值 说明
filename string 保存的文件名,添加此参数时会将压缩包保存到本地,未配置返回压缩包的 Blob 对象
resources Resource[] 资源列表,数组,每个元素为对象,包含 nameurl 或者 blob 字段
concurrency number 10 并发数,默认 10
onProgress (index: number) => Promise<void> 下载进度回调函数,参数为当前正在下载的资源索引

Resource 参数说明:

参数名 类型 是否必填 默认值 说明
name string 资源名称
url string URL 类型资源
blob Blob Blob 类型资源

📦 使用示例

下载,压缩,并保存到本地

await downloader({
  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 downloader({
  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')

🚨 免责声明

  • 本脚本仅供学习交流使用
  • 请勿用于任何商业用途
  • 使用本脚本产生的任何后果由用户自行承担

♻ 其他说明

GreasyFork 或者 ScriptCat 回复不及时,问题反馈推荐直接在 Github 提 Issue。

如果觉得本脚本对你有帮助,欢迎点个 ⭐ Star 支持一下!