Made it reenable the permission when an invidious instance is added.

Right now it throws an error
This commit is contained in:
Ajay Ramachandran
2020-01-01 12:55:35 -05:00
parent 0b41118232
commit 509b627e88
2 changed files with 27 additions and 16 deletions

View File

@@ -270,24 +270,35 @@ function activateTextChange(element) {
case "invidiousInstances":
let setButton = element.querySelector(".text-change-set");
setButton.addEventListener("click", function(e) {
setButton.addEventListener("click", async function(e) {
if (textBox.value.includes("/") || textBox.value.includes("http") || textBox.value.includes(":")) {
alert(chrome.i18n.getMessage("addInvidiousInstanceError"));
} else {
// Add this
chrome.storage.sync.get([option], function(result) {
if (!result[option]) result[option] = [];
result[option].push(textBox.value);
setOptionValue(option, result[option]);
textBox.value = "";
// Hide this section again
element.querySelector(".option-hidden-section").classList.add("hidden");
button.classList.remove("disabled");
//TODO Make the call to invidiousOnClick support passing the straight extra values, plus make the get not needed
//OR merge the config PR and use that
let result = await new Promise((resolve, reject) => {
chrome.storage.sync.get([option], resolve);
});
if (!result[option]) result[option] = [];
result[option].push(textBox.value);
await new Promise((resolve, reject) => {
setOptionValue(option, result[option], resolve);
});
let checkbox = document.querySelector("#support-invidious input");
checkbox.checked = true;
invidiousOnClick(checkbox, "supportInvidious");
textBox.value = "";
// Hide this section again
element.querySelector(".option-hidden-section").classList.add("hidden");
button.classList.remove("disabled");
}
});
@@ -319,6 +330,6 @@ function activateTextChange(element) {
* @param {string} option
* @param {*} value
*/
function setOptionValue(option, value) {
chrome.storage.sync.set({[option]: value});
function setOptionValue(option, value, callback) {
chrome.storage.sync.set({[option]: value}, callback);
}