mirror of
https://git.zavage.net/Zavage-Software/search-with-chatgpt-powered-by-openai-extension.git
synced 2026-08-10 13:40:29 -06:00
fix: add doctype and stop self-echoed saves overwriting active edits
This commit is contained in:
parent
b42b11755c
commit
5e56503244
@ -1,3 +1,4 @@
|
||||
<!doctype html>
|
||||
<!-- Rendered inline inside about:addons. Keep it narrow-friendly and do not
|
||||
rely on window sizing; a pref can degrade this to a standalone tab. -->
|
||||
<meta charset="utf-8" />
|
||||
|
||||
@ -14,11 +14,19 @@ let applying = false;
|
||||
|
||||
function render(settings) {
|
||||
applying = true;
|
||||
field("model").value = settings.model;
|
||||
field("temporaryChat").checked = settings.temporaryChat;
|
||||
field("webSearch").checked = settings.webSearch;
|
||||
field("openIn").value = settings.openIn;
|
||||
field("promptTemplate").value = settings.promptTemplate;
|
||||
for (const [id, value] of Object.entries(settings)) {
|
||||
const element = field(id);
|
||||
// Never overwrite the control the user is actively editing — this page's
|
||||
// own saves echo back through storage.onChanged (see below).
|
||||
if (element === document.activeElement) {
|
||||
continue;
|
||||
}
|
||||
if (typeof value === "boolean") {
|
||||
element.checked = value;
|
||||
} else {
|
||||
element.value = value;
|
||||
}
|
||||
}
|
||||
applying = false;
|
||||
}
|
||||
|
||||
@ -69,12 +77,18 @@ for (const id of Object.keys(DEFAULT_SETTINGS)) {
|
||||
|
||||
field("restore").addEventListener("click", () => {
|
||||
clearTimeout(saveTimer);
|
||||
// Restoring defaults is an explicit user action, so it should reset every
|
||||
// field even if one currently has focus. Blur first so render()'s
|
||||
// activeElement guard (see below) has nothing to skip.
|
||||
document.activeElement?.blur();
|
||||
render(DEFAULT_SETTINGS);
|
||||
persist({ ...DEFAULT_SETTINGS });
|
||||
});
|
||||
|
||||
// A remote sync landing while the panel is open must update the controls rather
|
||||
// than being clobbered by stale field values on the next edit.
|
||||
// browser.storage.onChanged fires for every write to the "sync" area, not just
|
||||
// a remote sync landing on another device — this page's own debounced
|
||||
// autosaves and its Restore-defaults save re-enter this listener too, which
|
||||
// render()'s activeElement guard makes safe to react to unconditionally.
|
||||
browser.storage.onChanged.addListener(async (changes, area) => {
|
||||
if (area !== "sync") {
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user