feat: fetch roles at runtime and prepare solver
This commit is contained in:
@@ -26,3 +26,24 @@ chrome.runtime.onMessage.addListener((message: SimulateClickMessage) => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const checkForUpdate = async (): Promise<void> => {
|
||||
try {
|
||||
const res = await fetch(`${__GITEA_API__}/branches/main`);
|
||||
const data = await res.json();
|
||||
const latest: string = data.commit.id;
|
||||
const needsUpdate = latest !== __GIT_REVISION__;
|
||||
|
||||
await chrome.storage.local.set({ needsUpdate });
|
||||
|
||||
if (needsUpdate) {
|
||||
chrome.action.setBadgeText({ text: "!" });
|
||||
chrome.action.setBadgeBackgroundColor({ color: "#ef4444" });
|
||||
} else {
|
||||
chrome.action.setBadgeText({ text: "" });
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
|
||||
chrome.runtime.onStartup.addListener(checkForUpdate);
|
||||
chrome.runtime.onInstalled.addListener(checkForUpdate);
|
||||
|
||||
@@ -35,14 +35,14 @@ const onKeyDown = (event: KeyboardEvent): void => {
|
||||
const init = async (): Promise<void> => {
|
||||
const result = await chrome.storage.local.get(STORAGE_KEY);
|
||||
const state = result[STORAGE_KEY] as State | undefined;
|
||||
enabled = state?.enabled ?? true;
|
||||
enabled = state?.keybinds ?? true;
|
||||
|
||||
document.addEventListener("keydown", onKeyDown, { capture: true });
|
||||
|
||||
chrome.storage.onChanged.addListener((changes) => {
|
||||
if (STORAGE_KEY in changes) {
|
||||
const next = changes[STORAGE_KEY].newValue as State;
|
||||
enabled = next.enabled;
|
||||
enabled = next.keybinds;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
2
src/env.d.ts
vendored
Normal file
2
src/env.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const __GIT_REVISION__: string;
|
||||
declare const __GITEA_API__: string;
|
||||
0
src/generated/.gitkeep
Normal file
0
src/generated/.gitkeep
Normal file
@@ -16,17 +16,24 @@ h1 {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 0.75rem;
|
||||
color: #94a3b8;
|
||||
line-height: 1.4;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
#toggle {
|
||||
#update-banner {
|
||||
font-family: monospace;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
color: #fbbf24;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
#tweaks {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.row {
|
||||
width: 100%;
|
||||
padding: 9px;
|
||||
border: none;
|
||||
@@ -36,14 +43,16 @@ p {
|
||||
cursor: pointer;
|
||||
letter-spacing: 0.05em;
|
||||
transition: background 0.15s;
|
||||
font-family: monospace;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#toggle.on {
|
||||
.row.on {
|
||||
background: #22c55e;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#toggle.off {
|
||||
.row.off {
|
||||
background: #3f3f46;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>WoV Tweaks</title>
|
||||
<title>WAC</title>
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Assassins Convention Tweaks</h1>
|
||||
<button id="toggle"></button>
|
||||
<div id="update-banner" style="display:none">[!] Update available — reinstall the extension</div>
|
||||
<div id="tweaks"></div>
|
||||
<script src="../dist/popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
48
src/popup.ts
48
src/popup.ts
@@ -1,34 +1,56 @@
|
||||
import { State, STORAGE_KEY } from "./types";
|
||||
|
||||
const DEFAULT_STATE: State = {
|
||||
enabled: true,
|
||||
const defaultState: State = {
|
||||
keybinds: true,
|
||||
solver: true,
|
||||
};
|
||||
|
||||
const getState = async (): Promise<State> => {
|
||||
const result = await chrome.storage.local.get(STORAGE_KEY);
|
||||
return (result[STORAGE_KEY] as State | undefined) ?? DEFAULT_STATE;
|
||||
return (result[STORAGE_KEY] as State | undefined) ?? defaultState;
|
||||
};
|
||||
|
||||
const setState = async (state: State): Promise<void> => {
|
||||
await chrome.storage.local.set({ [STORAGE_KEY]: state });
|
||||
};
|
||||
|
||||
const render = (btn: HTMLButtonElement, enabled: boolean): void => {
|
||||
btn.textContent = enabled ? "ON" : "OFF";
|
||||
btn.className = enabled ? "on" : "off";
|
||||
const createRow = (label: string, initial: boolean, onChange: (next: boolean) => void): HTMLButtonElement => {
|
||||
let on = initial;
|
||||
const btn = document.createElement("button");
|
||||
|
||||
const render = () => {
|
||||
btn.textContent = `[${on ? "ON" : "OFF"}] ${label}`;
|
||||
btn.className = `row ${on ? "on" : "off"}`;
|
||||
};
|
||||
|
||||
render();
|
||||
btn.addEventListener("click", () => {
|
||||
on = !on;
|
||||
render();
|
||||
onChange(on);
|
||||
});
|
||||
|
||||
return btn;
|
||||
};
|
||||
|
||||
const init = async (): Promise<void> => {
|
||||
const btn = document.getElementById("toggle") as HTMLButtonElement;
|
||||
const container = document.getElementById("tweaks")!;
|
||||
const state = await getState();
|
||||
render(btn, state.enabled);
|
||||
|
||||
btn.addEventListener("click", async () => {
|
||||
const { needsUpdate } = await chrome.storage.local.get("needsUpdate");
|
||||
if (needsUpdate) {
|
||||
document.getElementById("update-banner")!.style.display = "block";
|
||||
}
|
||||
|
||||
container.appendChild(createRow("Keybinds", state.keybinds, async (next) => {
|
||||
const current = await getState();
|
||||
const next = { enabled: !current.enabled };
|
||||
await setState(next);
|
||||
render(btn, next.enabled);
|
||||
});
|
||||
await setState({ ...current, keybinds: next });
|
||||
}));
|
||||
|
||||
container.appendChild(createRow("Solver", state.solver, async (next) => {
|
||||
const current = await getState();
|
||||
await setState({ ...current, solver: next });
|
||||
}));
|
||||
};
|
||||
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export type State = {
|
||||
enabled: boolean;
|
||||
keybinds: boolean;
|
||||
solver: boolean;
|
||||
};
|
||||
|
||||
export const STORAGE_KEY = "wov_assassins_convention_tweaks_state";
|
||||
|
||||
Reference in New Issue
Block a user