Skip to content

Commit 43652e0

Browse files
authored
🐛 GM_download 添加 conflictAction 参数 (#1250)
* fix: `GM_download` 补回 `conflictAction` * 加例子
1 parent 7307705 commit 43652e0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

example/gm_download.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
* - 自定义 header
1919
* - 进度回调 / 完成回调
2020
*/
21+
22+
// 1. 下载网络资源
23+
2124
GM_download({
2225
url: "https://scriptcat.org/api/v2/open/crx-download/ndcooeababalnlpkfedmmbbbgkljhpjf",
2326
name: "scriptcat.crx",
@@ -35,3 +38,23 @@ GM_download({
3538
console.log("load", data);
3639
},
3740
});
41+
42+
// 2. 下载 Blob 资源
43+
// 参考: https://github.com/Tampermonkey/tampermonkey/issues/2591
44+
45+
const pngData = new Uint8Array([
46+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
47+
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
48+
0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4, 0x89, 0x00, 0x00, 0x00,
49+
0x0a, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0x00,
50+
0x00, 0x03, 0x01, 0x01, 0x00, 0xae, 0xb4, 0xfa, 0x77, 0x00, 0x00, 0x00,
51+
0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
52+
]);
53+
54+
const testImageUrl = URL.createObjectURL(new Blob([pngData], { type: 'image/png' }));
55+
56+
GM_download({
57+
url: testImageUrl,
58+
name: 'test/test.png', // 储存在 test 资料夹内
59+
conflictAction: 'overwrite', // 每次都使用固定的档案名
60+
});

src/app/service/content/gm_api/gm_api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ export default class GMApi extends GM_Base {
887887
name: details.name,
888888
headers: details.headers,
889889
saveAs: details.saveAs,
890+
conflictAction: details.conflictAction,
890891
timeout: details.timeout,
891892
cookie: details.cookie,
892893
anonymous: details.anonymous,
@@ -938,6 +939,7 @@ export default class GMApi extends GM_Base {
938939
name: details.name,
939940
headers: details.headers,
940941
saveAs: details.saveAs,
942+
conflictAction: details.conflictAction,
941943
timeout: details.timeout,
942944
cookie: details.cookie,
943945
anonymous: details.anonymous,

0 commit comments

Comments
 (0)