Skip to content

Commit

Permalink
🐛 处理页面回退 #277
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jul 7, 2024
1 parent 3ef9fbc commit f6f0a80
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/pages/options/routes/script/ScriptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ const emptyScript = async (template: string, hotKeys: any, target?: string) => {

type visibleItem = "scriptStorage" | "scriptSetting" | "scriptResource";

const popstate = () => {
// eslint-disable-next-line no-restricted-globals
if (confirm("脚本已修改, 离开后会丢失修改, 是否继续?")) {

Check warning on line 154 in src/pages/options/routes/script/ScriptEditor.tsx

View workflow job for this annotation

GitHub Actions / Build

Unexpected confirm
window.history.back();
window.removeEventListener("popstate", popstate);
} else {
window.history.pushState(null, "", window.location.href);
}
return false;
};

function ScriptEditor() {
const scriptDAO = new ScriptDAO();
const scriptCtrl = IoC.instance(ScriptController) as ScriptController;
Expand Down Expand Up @@ -426,6 +437,10 @@ function ScriptEditor() {
return true;
};
window.onbeforeunload = beforeunload;
window.history.pushState(null, "", window.location.href);
window.addEventListener("popstate", popstate);
} else {
window.removeEventListener("popstate", popstate);
}

return () => {
Expand Down

0 comments on commit f6f0a80

Please sign in to comment.