From 8780556a66129998ee008c8e0d82db61e877c0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E7=AE=80=E5=8D=95=E5=8D=95?= Date: Sun, 17 May 2026 08:04:40 +0200 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20node.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 node.js diff --git a/node.js b/node.js new file mode 100644 index 0000000..add0498 --- /dev/null +++ b/node.js @@ -0,0 +1,30 @@ +// 你的 Gitee Raw 地址 +const jsonUrl = 'https://gittea.dev/Vibrantly/Try/raw/branch/master/duox.json'; + +fetch(jsonUrl) + .then(response => response.text()) // 获取原始的 Base64 文本 + .then(base64String => { + // --- 核心解码逻辑 (完美支持中文) --- + // 1. atob 将 Base64 转为二进制字符串 + const binaryString = atob(base64String.trim()); + // 2. 将二进制字符串映射为字节数组 + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + // 3. 使用 TextDecoder 将字节数组解码为正常的 UTF-8 字符串 + const jsonString = new TextDecoder('utf-8').decode(bytes); + + // --- 自动解析并运行 --- + try { + const configData = JSON.parse(jsonString); // 变回正常的 JS 对象 + console.log("【自动转换并解析成功】:", configData); + + // 在这里写你拿到数据后要执行的后续代码 + // 例如:configData.urls.forEach(item => console.log(item.name)); + } catch (e) { + console.error("JSON 解析失败:", e); + } + }) + .catch(error => console.error("请求失败:", error)); + \ No newline at end of file