Zotero-PDF-Copier-Renamer/src/modules/preferenceScript.ts
2026-06-10 23:10:05 +06:00

33 lines
1.4 KiB
TypeScript

export async function registerPrefsScripts(prefWindow: Window) {
const doc = prefWindow.document;
// Get input elements from XHTML
const serverInput = doc.getElementById("zotero-prefpane-researchossync-serverUrl") as HTMLInputElement;
const tokenInput = doc.getElementById("zotero-prefpane-researchossync-apiToken") as HTMLInputElement;
if (serverInput && tokenInput) {
// Read currently saved preferences
const serverUrl = Zotero.Prefs.get("extensions.zotero.researchossync.serverUrl") as string || "http://localhost:3000";
const apiToken = Zotero.Prefs.get("extensions.zotero.researchossync.apiToken") as string || "";
// Populate the inputs
serverInput.value = serverUrl;
tokenInput.value = apiToken;
// Save settings immediately to preference branch as the user types or changes value
serverInput.addEventListener("input", () => {
Zotero.Prefs.set("extensions.zotero.researchossync.serverUrl", serverInput.value.trim());
});
serverInput.addEventListener("change", () => {
Zotero.Prefs.set("extensions.zotero.researchossync.serverUrl", serverInput.value.trim());
});
tokenInput.addEventListener("input", () => {
Zotero.Prefs.set("extensions.zotero.researchossync.apiToken", tokenInput.value.trim());
});
tokenInput.addEventListener("change", () => {
Zotero.Prefs.set("extensions.zotero.researchossync.apiToken", tokenInput.value.trim());
});
}
}