@@ -16,6 +16,22 @@ const gamesUrl = "https://fern.best/x7k9m2p.html";
1616 import { SW } from "@utils/proxy.ts";
1717 import { Settings } from "@utils/settings.ts";
1818 import { BareClient } from "@mercuryworkshop/bare-mux";
19+ import { isSavedShortcut, toggleSavedShortcut } from "@utils/shortcuts";
20+
21+ let currentProxyUrl = "";
22+ let currentProxyTitle = "";
23+
24+ const updateShortcutButton = (
25+ proxyShortcut: { button: HTMLButtonElement | null; noShortcut: HTMLElement | null; shortcut: HTMLElement | null },
26+ url: string
27+ ) => {
28+ if (!proxyShortcut.button || !proxyShortcut.noShortcut || !proxyShortcut.shortcut) return;
29+ const saved = url ? isSavedShortcut(url) : false;
30+ proxyShortcut.noShortcut.classList.toggle("hidden", saved);
31+ proxyShortcut.shortcut.classList.toggle("hidden", !saved);
32+ proxyShortcut.button.setAttribute("aria-pressed", saved ? "true" : "false");
33+ proxyShortcut.button.title = saved ? "Remove shortcut" : "Save shortcut";
34+ };
1935
2036 const init = async () => {
2137 const iframe = document.getElementById("iframe") as HTMLIFrameElement;
@@ -27,6 +43,11 @@ const gamesUrl = "https://fern.best/x7k9m2p.html";
2743 const proxyLeft = document.getElementById("pal") as HTMLButtonElement;
2844 const proxyRight = document.getElementById("par") as HTMLButtonElement;
2945 const proxyReload = document.getElementById("prl") as HTMLButtonElement;
46+ const proxyShortcut = {
47+ button: document.getElementById("psc") as HTMLButtonElement,
48+ noShortcut: document.getElementById("noShortcut") as HTMLElement,
49+ shortcut: document.getElementById("shortcut") as HTMLElement
50+ }
3051 const client = new BareClient();
3152
3253 const getURL = async (): Promise<string> => {
@@ -50,6 +71,14 @@ const gamesUrl = "https://fern.best/x7k9m2p.html";
5071 proxyReload.addEventListener("click", () => {
5172 iframeWin!.location.reload();
5273 });
74+ if (proxyShortcut.button && !proxyShortcut.button.dataset.bound) {
75+ proxyShortcut.button.dataset.bound = "true";
76+ proxyShortcut.button.addEventListener("click", () => {
77+ if (!currentProxyUrl) return;
78+ toggleSavedShortcut(currentProxyUrl, currentProxyTitle);
79+ updateShortcutButton(proxyShortcut, currentProxyUrl);
80+ });
81+ }
5382 }
5483
5584 iframe.addEventListener("load", async () => {
@@ -61,6 +90,9 @@ const gamesUrl = "https://fern.best/x7k9m2p.html";
6190 phlImage.src = object;
6291 bhl.classList.add("hidden");
6392 phl.classList.remove("hidden");
93+ currentProxyUrl = pageURL;
94+ currentProxyTitle = iframeWin!.document.title || pageURL;
95+ updateShortcutButton(proxyShortcut, currentProxyUrl);
6496 });
6597
6698 buttons();
@@ -94,4 +126,4 @@ const gamesUrl = "https://fern.best/x7k9m2p.html";
94126 }
95127 catch (_) {}
96128 });
97- </script >
129+ </script >
0 commit comments