diff --git a/app.js b/app.js index 8d940e9..9ca95bd 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,7 @@ const pages = $("#pages"); const previewError = $("#preview-error"); const previewErrorText = $("#preview-error-text"); const previewStatus = $("#preview-status"); +const engineButton = $("#toggle-engine"); const saveStatus = $("#save-status"); const openFilePath = $("#open-file-path"); const projectTitle = $("#project-title"); @@ -35,6 +36,7 @@ const state = { previewController: null, previewRequest: 0, toastTimer: 0, + routeD: localStorage.getItem("texrra-route-d") === "1", }; function escapeHtml(value) { @@ -450,6 +452,11 @@ function scheduleSave() { state.saveTimer = setTimeout(saveFile, 450); } +function updateEngineButton() { + engineButton.textContent = state.routeD ? "引擎: Route-D" : "引擎: v1"; + engineButton.classList.toggle("primary", state.routeD); +} + function schedulePreview(delay) { clearTimeout(state.previewTimer); state.previewTimer = setTimeout(refreshPreview, delay === undefined ? 90 : delay); @@ -463,7 +470,8 @@ async function refreshPreview() { state.previewController = controller; setPreviewStatus("排版中…"); try { - const response = await fetch(projectPath("/preview"), { + const engineQuery = state.routeD ? "?engine=route-d" : ""; + const response = await fetch(projectPath("/preview") + engineQuery, { method: "POST", signal: controller.signal, }); @@ -728,3 +736,11 @@ workspace.addEventListener("drop", event => { window.addEventListener("hashchange", route); route(); + +engineButton.addEventListener("click", () => { + state.routeD = !state.routeD; + localStorage.setItem("texrra-route-d", state.routeD ? "1" : "0"); + updateEngineButton(); + schedulePreview(0); +}); +updateEngineButton(); diff --git a/index.html b/index.html index 86c9312..5b19049 100644 --- a/index.html +++ b/index.html @@ -66,6 +66,7 @@ 实时预览 +