feat: add preinit setting

This commit is contained in:
Gabe
2025-09-25 11:31:12 +08:00
parent 1dabbfc4de
commit 393f1a29d5
10 changed files with 613 additions and 538 deletions

View File

@@ -70,7 +70,8 @@ export const syncData = async (key, value) => {
syncMeta = {},
} = await getSyncWithDefault();
if (!syncUrl || !syncKey || (syncType === OPT_SYNCTYPE_WEBDAV && !syncUser)) {
throw new Error("sync args err");
// throw new Error("sync args err");
return;
}
let { updateAt = 0, syncAt = 0 } = syncMeta[key] || {};

View File

@@ -325,13 +325,19 @@ export class Translator {
this.#enableMouseHover();
}
// 是否默认启动
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => this.#run());
} else {
this.#run();
}
}
// 启动
#run() {
if (this.#rule.transOpen === "true") {
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => this.enable());
} else {
this.enable();
}
this.enable();
} else if (this.#setting.preInit) {
this.#init();
}
}
@@ -1242,13 +1248,17 @@ export class Translator {
// 注入JS/CSS
#initInjector() {
const { injectJs, injectCss } = this.#rule;
if (isExt) {
injectJs && sendBgMsg(MSG_INJECT_JS, injectJs);
injectCss && sendBgMsg(MSG_INJECT_CSS, injectCss);
} else {
injectJs && injectInlineJs(injectJs);
injectCss && injectInternalCss(injectCss);
try {
const { injectJs, injectCss } = this.#rule;
if (isExt) {
injectJs && sendBgMsg(MSG_INJECT_JS, injectJs);
injectCss && sendBgMsg(MSG_INJECT_CSS, injectCss);
} else {
injectJs && injectInlineJs(injectJs);
injectCss && injectInternalCss(injectCss);
}
} catch (err) {
kissLog("inject js");
}
}