InviTube/options/options.js
2023-06-17 14:12:32 +02:00

23 lines
No EOL
631 B
JavaScript

// Save options
document.querySelector("form").addEventListener("submit", (e) => {
e.preventDefault();
let instance = document.querySelector("#instance").value.trim();
instance = instance.replace(/^https?:?\/?\/?/, '').replace('\/$');
if (!instance) {
return alert("Please fill out the fields!");
}
browser.storage.local.set({
instance: instance,
}).then(() => alert("Saved!"));
});
// Restore options
document.addEventListener("DOMContentLoaded", () => {
browser.storage.local.get({
instance: "yewtu.be",
}).then((item) => {
document.querySelector("#instance").value = item.instance;
});
});