fix: api hooks

This commit is contained in:
Gabe
2025-09-25 23:08:39 +08:00
parent 533a0e2d5b
commit 6b9a1a49bb
12 changed files with 523 additions and 444 deletions

View File

@@ -70,6 +70,9 @@ const BatchQueue = (
try {
const payloads = tasksToProcess.map((item) => item.payload);
const responses = await sendBatchRequest(payloads);
if (!Array.isArray(responses)) {
throw new Error("responses format error");
}
tasksToProcess.forEach((taskItem, index) => {
const response = responses[index];

View File

@@ -62,10 +62,11 @@ async function trySetObj(key, obj) {
async function getObj(key) {
const val = await get(key);
if (val === null || val === undefined) return null;
try {
return JSON.parse(val);
} catch (err) {
kissLog("parse json: ", key);
kissLog("parse json in storage err: ", key);
}
return null;
}

View File

@@ -255,6 +255,7 @@ export class Translator {
#setting; // 设置选项
#rule; // 规则
#isInitialized = false; // 初始化状态
#isJsInjected = false; // 注入用户JS
#mouseHoverEnabled = false; // 鼠标悬停翻译
#enabled = false; // 全局默认状态
#runId = 0; // 用于中止过期的异步请求
@@ -1248,6 +1249,11 @@ export class Translator {
// 注入JS/CSS
#initInjector() {
if (this.#isJsInjected) {
return;
}
this.#isJsInjected = true;
try {
const { injectJs, injectCss } = this.#rule;
if (isExt) {
@@ -1258,7 +1264,7 @@ export class Translator {
injectCss && injectInternalCss(injectCss);
}
} catch (err) {
kissLog("inject js");
kissLog("inject js", err);
}
}