28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
function saveOptions(event) {
|
|
event.preventDefault();
|
|
const serverUrl = document.querySelector("#server-url").value;
|
|
const password = document.querySelector("#password").value;
|
|
|
|
if (serverUrl.trim() === "" || password.trim() === "") {
|
|
alert("URL сервера и пароль не могут быть пустыми!");
|
|
return;
|
|
}
|
|
|
|
browser.storage.sync.set({ serverUrl, password }).then(() => {
|
|
const status = document.querySelector("#status");
|
|
status.textContent = "Настройки сохранены!";
|
|
setTimeout(() => (status.textContent = ""), 2000);
|
|
});
|
|
}
|
|
|
|
function restoreOptions() {
|
|
browser.storage.sync.get(["serverUrl", "password"]).then((result) => {
|
|
const serverUrl = result.serverUrl || "http://localhost:5000/submit";
|
|
const password = result.password || "";
|
|
document.querySelector("#server-url").value = serverUrl;
|
|
document.querySelector("#password").value = password;
|
|
});
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", restoreOptions);
|
|
document.querySelector("#settings-form").addEventListener("submit", saveOptions); |