Added basic options import/export

This commit is contained in:
Ajay Ramachandran
2020-03-10 00:33:50 -04:00
parent 50002cfbbd
commit 2ec47d52cd
3 changed files with 79 additions and 3 deletions

View File

@@ -345,15 +345,50 @@ function activatePrivateTextChange(element: HTMLElement) {
element.querySelector(".option-hidden-section").classList.remove("hidden");
return;
}
textBox.value = Config.config[option];
let result = Config.config[option];
// See if anything extra must be done
switch (option) {
case "*":
result = JSON.stringify(Config.localConfig);
break;
}
textBox.value = result;
let setButton = element.querySelector(".text-change-set");
setButton.addEventListener("click", () => {
let confirmMessage = element.getAttribute("confirm-message");
if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) {
Config.config[option] = textBox.value;
// See if anything extra must be done
switch (option) {
case "*":
try {
let newConfig = JSON.parse(textBox.value);
for (const key in newConfig) {
Config.config[key] = newConfig[key];
}
init();
if (newConfig.supportInvidious) {
let checkbox = <HTMLInputElement> document.querySelector("#support-invidious > label > label > input");
checkbox.checked = true;
invidiousOnClick(checkbox, "supportInvidious");
}
} catch (e) {
alert(chrome.i18n.getMessage("incorrectlyFormattedOptions"));
}
break;
default:
Config.config[option] = textBox.value;
}
}
});