InviTube/options/options.js
2024-08-21 09:52:16 +02:00

29 lines
761 B
JavaScript

// Restore options
document.addEventListener("DOMContentLoaded", () => {
browser.storage.local.get({
instance: "yewtu.be",
}).then((storage) => {
document.querySelector("#instance").value = storage.instance;
});
});
// Save options
const saveBtn = document.getElementById("saveBtn");
saveBtn.addEventListener("click", (e) => {
e.preventDefault();
const instance = document.querySelector("#instance").value.trim().replace(/^https?:\/\/*|\/$/g, '');
if (!instance) return alert("Please fill out the fields!");
browser.storage.local.set({
instance,
}).then(() => {
saveBtn.disabled = true;
saveBtn.value = "Saved!";
setTimeout(() => {
saveBtn.disabled = false;
saveBtn.value = "Save";
}, 3000)
});
});