Skip to content

Commit 2af2845

Browse files
authored
⚡️ 改善 charset detection (#1140)
1 parent a3abaf0 commit 2af2845

File tree

5 files changed

+474
-45
lines changed

5 files changed

+474
-45
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"eslint-plugin-react-hooks": "^5.2.0",
8282
"eslint-plugin-userscripts": "^0.5.6",
8383
"globals": "^16.5.0",
84+
"iconv-lite": "^0.7.2",
8485
"jsdom": "^26.1.0",
8586
"jszip": "^3.10.1",
8687
"mock-xmlhttprequest": "^8.4.1",

pnpm-lock.yaml

Lines changed: 11 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/install/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key";
3333
import { cacheInstance } from "@App/app/cache";
3434
import { formatBytes, prettyUrl } from "@App/pkg/utils/utils";
3535
import { ScriptIcons } from "../options/routes/utils";
36-
import { detectEncoding } from "@App/pkg/utils/encoding";
36+
import { bytesDecode, detectEncoding } from "@App/pkg/utils/encoding";
3737

3838
const backgroundPromptShownKey = "background_prompt_shown";
3939

@@ -118,7 +118,7 @@ const fetchScriptBody = async (url: string, { onProgress }: { [key: string]: any
118118
// 使用检测到的 charset 解码
119119
let code;
120120
try {
121-
code = new TextDecoder(encode).decode(chunksAll);
121+
code = bytesDecode(encode, chunksAll);
122122
} catch (e: any) {
123123
console.warn(`Failed to decode response with charset ${encode}: ${e.message}`);
124124
// 回退到 UTF-8

0 commit comments

Comments
 (0)