-
Notifications
You must be signed in to change notification settings - Fork 317
fix: GM_download 补回 conflictAction
#1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodFrm
merged 2 commits into
scriptscat:main
from
cyfung1031:pr-GM_download-conflictAction-2
Feb 15, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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', // 每次都使用固定的档案名 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+59
|
||||||||||||||||||||||||||||||||||||||||||||||||
| GM_download({ | |
| url: testImageUrl, | |
| name: 'test/test.png', // 储存在 test 资料夹内 | |
| conflictAction: 'overwrite', // 每次都使用固定的档案名 | |
| function revokeTestImageUrl() { | |
| URL.revokeObjectURL(testImageUrl); | |
| } | |
| GM_download({ | |
| url: testImageUrl, | |
| name: 'test/test.png', // 储存在 test 资料夹内 | |
| conflictAction: 'overwrite', // 每次都使用固定的档案名 | |
| onload() { | |
| revokeTestImageUrl(); | |
| }, | |
| onerror() { | |
| revokeTestImageUrl(); | |
| }, | |
| ontimeout() { | |
| revokeTestImageUrl(); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
示例里
name: 'test/test.png'并注释“储存在 test 资料夹内”,但当前实现会在后台通过 cleanFileName 把/替换成-(因此实际文件名会变成test-test.png,不会创建子目录)。建议要么改成不含路径分隔符的文件名,要么更新注释/示例以符合实际行为。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI 有时候聪明过了