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

@@ -425,5 +425,20 @@
},
"mobileUpdateInfo": {
"message": "m.youtube.com is now supported"
},
"exportOptions": {
"message": "Import/Export All Options"
},
"whatExportOptions": {
"message": "This is your entire configuration in JSON. This includes your userID, so be sure to share this wisely."
},
"setOptions": {
"message": "Set Options"
},
"exportOptionsWarning": {
"message": "Warning: Changing the options is permanent and can break your install. Are you sure you would like to do this? Make sure to backup your old one just in case."
},
"incorrectlyFormattedOptions": {
"message": "This JSON is not formatted correctly. Your options have not been changed."
}
}

View File

@@ -308,6 +308,32 @@
<br/>
<br/>
<div option-type="private-text-change" sync-option="*" confirm-message="exportOptionsWarning">
<div class="option-button trigger-button">
__MSG_exportOptions__
</div>
<br/>
<div class="small-description">__MSG_whatExportOptions__</div>
<div class="option-hidden-section hidden">
<br/>
<input class="option-text-box" type="text">
<br/>
<br/>
<div class="option-button text-change-set">
__MSG_setOptions__
</div>
</div>
</div>
<br/>
<br/>
<div option-type="text-change" sync-option="serverAddress">
<label class="text-label-container">
<div>__MSG_customServerAddress__</div>

View File

@@ -346,14 +346,49 @@ function activatePrivateTextChange(element: HTMLElement) {
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;
}
}
});