catch global error and display on top of page

This commit is contained in:
Gabe Yuan
2023-08-27 16:41:14 +08:00
parent c4980d9eb7
commit e1d74aae6a
2 changed files with 42 additions and 16 deletions

View File

@@ -12,7 +12,7 @@ import { isIframe } from "./libs/iframe";
/**
* 入口函数
*/
(async () => {
const init = async () => {
const href = isIframe ? document.referrer : document.location.href;
const setting = await getSetting();
const rules = await getRules();
@@ -38,4 +38,15 @@ import { isIframe } from "./libs/iframe";
}
return { data: translator.rule };
});
};
(async () => {
try {
await init();
} catch (err) {
const $err = document.createElement("div");
$err.innerText = `KISS-Translator Error: ${err.message}`;
$err.style.cssText = "background:red; color:#fff; z-index:10000;";
document.body.prepend($err);
}
})();

View File

@@ -13,7 +13,7 @@ import { isIframe } from "./libs/iframe";
/**
* 入口函数
*/
(async () => {
const init = async () => {
// 设置页面
if (
document.location.href.includes(process.env.REACT_APP_OPTIONSPAGE_DEV) ||
@@ -74,6 +74,7 @@ import { isIframe } from "./libs/iframe";
// 注册菜单
if (isGm) {
try {
GM.registerMenuCommand(
"Toggle Translate",
(event) => {
@@ -88,8 +89,22 @@ import { isIframe } from "./libs/iframe";
},
"C"
);
} catch (err) {
console.log("[registerMenuCommand]", err);
}
}
// 同步订阅规则
trySyncAllSubRules(setting);
};
(async () => {
try {
await init();
} catch (err) {
const $err = document.createElement("div");
$err.innerText = `KISS-Translator Error: ${err.message}`;
$err.style.cssText = "background:red; color:#fff; z-index:10000;";
document.body.prepend($err);
}
})();