diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index b49c0bce..2dc611f5 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -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." } } diff --git a/public/options/options.html b/public/options/options.html index 72916c3a..37139c31 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -305,6 +305,32 @@ +
+
+ +
+
+ __MSG_exportOptions__ +
+ +
+ +
__MSG_whatExportOptions__
+ + +
+

diff --git a/src/options.ts b/src/options.ts index 1836c6c3..466a57e6 100644 --- a/src/options.ts +++ b/src/options.ts @@ -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 = 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; + } } });