diff --git a/example/gm_download.js b/example/gm_download.js index ea0e70b6b..b34674ed6 100644 --- a/example/gm_download.js +++ b/example/gm_download.js @@ -18,6 +18,9 @@ * - 自定义 header * - 进度回调 / 完成回调 */ + +// 1. 下载网络资源 + GM_download({ url: "https://scriptcat.org/api/v2/open/crx-download/ndcooeababalnlpkfedmmbbbgkljhpjf", name: "scriptcat.crx", @@ -35,3 +38,23 @@ GM_download({ console.log("load", data); }, }); + +// 2. 下载 Blob 资源 +// 参考: https://github.com/Tampermonkey/tampermonkey/issues/2591 + +const pngData = new Uint8Array([ + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4, 0x89, 0x00, 0x00, 0x00, + 0x0a, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0x00, + 0x00, 0x03, 0x01, 0x01, 0x00, 0xae, 0xb4, 0xfa, 0x77, 0x00, 0x00, 0x00, + 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 +]); + +const testImageUrl = URL.createObjectURL(new Blob([pngData], { type: 'image/png' })); + +GM_download({ + url: testImageUrl, + name: 'test/test.png', // 储存在 test 资料夹内 + conflictAction: 'overwrite', // 每次都使用固定的档案名 +}); diff --git a/src/app/service/content/gm_api/gm_api.ts b/src/app/service/content/gm_api/gm_api.ts index ee37cabda..d08022046 100644 --- a/src/app/service/content/gm_api/gm_api.ts +++ b/src/app/service/content/gm_api/gm_api.ts @@ -887,6 +887,7 @@ export default class GMApi extends GM_Base { name: details.name, headers: details.headers, saveAs: details.saveAs, + conflictAction: details.conflictAction, timeout: details.timeout, cookie: details.cookie, anonymous: details.anonymous, @@ -938,6 +939,7 @@ export default class GMApi extends GM_Base { name: details.name, headers: details.headers, saveAs: details.saveAs, + conflictAction: details.conflictAction, timeout: details.timeout, cookie: details.cookie, anonymous: details.anonymous,