feat: add advanced context actions and optional translation
This commit is contained in:
+10
-7
@@ -1,5 +1,7 @@
|
||||
import { DEFAULT_SETTINGS, MAX_MODEL_CHARS } from "../lib/defaults.js";
|
||||
import { DEFAULT_SETTINGS } from "../lib/defaults.js";
|
||||
import { load, save } from "../lib/settings.js";
|
||||
import { initializeMenuSettings, MENU_SETTING_KEYS } from "./menu-settings.js";
|
||||
import { initializeShortcut } from "./shortcut.js";
|
||||
|
||||
const SAVE_DEBOUNCE_MS = 400;
|
||||
const STATUS_CLEAR_MS = 1500;
|
||||
@@ -9,8 +11,12 @@ const field = (id) => document.getElementById(id);
|
||||
let saveTimer = null;
|
||||
let statusTimer = null;
|
||||
|
||||
const menuSettings = initializeMenuSettings({ document, onChange: scheduleSave });
|
||||
|
||||
function render(settings) {
|
||||
menuSettings.render(settings);
|
||||
for (const [id, value] of Object.entries(settings)) {
|
||||
if (MENU_SETTING_KEYS.includes(id)) continue;
|
||||
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).
|
||||
@@ -27,7 +33,7 @@ function render(settings) {
|
||||
|
||||
function collect() {
|
||||
return {
|
||||
model: field("model").value,
|
||||
...menuSettings.collect(),
|
||||
temporaryChat: field("temporaryChat").checked,
|
||||
webSearch: field("webSearch").checked,
|
||||
openIn: field("openIn").value,
|
||||
@@ -59,15 +65,12 @@ function scheduleSave() {
|
||||
saveTimer = setTimeout(() => persist(collect()), SAVE_DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
// Derived rather than hard-coded in the markup: if the two ever disagreed, the
|
||||
// input would accept a model that mergeSettings() then silently discards,
|
||||
// blanking the setting with no explanation.
|
||||
field("model").maxLength = MAX_MODEL_CHARS;
|
||||
|
||||
// Module scripts are deferred, so the DOM is already parsed here.
|
||||
void initializeShortcut({ commands: browser.commands, document, window });
|
||||
render(await load());
|
||||
|
||||
for (const id of Object.keys(DEFAULT_SETTINGS)) {
|
||||
if (MENU_SETTING_KEYS.includes(id)) continue;
|
||||
field(id).addEventListener("input", scheduleSave);
|
||||
field(id).addEventListener("change", scheduleSave);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user