1818 * - 自定义 header
1919 * - 进度回调 / 完成回调
2020 */
21+
22+ // 1. 下载网络资源
23+
2124GM_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+ } ) ;
0 commit comments