mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 05:27:03 +03:00
Moved invidious code to functions and made it check permissions on init.
This commit is contained in:
@@ -27,12 +27,75 @@ async function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See if anything extra should be run first time
|
||||||
|
switch (option) {
|
||||||
|
case "supportInvidious":
|
||||||
|
invidiousInit(checkbox, option);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add click listener
|
||||||
checkbox.addEventListener("click", () =>{
|
checkbox.addEventListener("click", () =>{
|
||||||
setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked);
|
setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked);
|
||||||
|
|
||||||
// See if anything extra must be run
|
// See if anything extra must be run
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case "supportInvidious":
|
case "supportInvidious":
|
||||||
|
invidiousOnClick(checkbox, option);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
checksLeft--;
|
||||||
|
});
|
||||||
|
|
||||||
|
checksLeft++;
|
||||||
|
break;
|
||||||
|
case "text-change":
|
||||||
|
let button = optionsElements[i].querySelector(".trigger-button");
|
||||||
|
button.addEventListener("click", () => activateTextChange(optionsElements[i]));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "keybind-change":
|
||||||
|
let keybindButton = optionsElements[i].querySelector(".trigger-button");
|
||||||
|
keybindButton.addEventListener("click", () => activateKeybindChange(optionsElements[i]));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await wait(() => checksLeft == 0, 1000, 50);
|
||||||
|
|
||||||
|
optionsContainer.classList.remove("hidden");
|
||||||
|
optionsContainer.classList.add("animated");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run when the invidious button is being initialized
|
||||||
|
*
|
||||||
|
* @param {HTMLElement} checkbox
|
||||||
|
* @param {string} option
|
||||||
|
*/
|
||||||
|
function invidiousInit(checkbox, option) {
|
||||||
|
chrome.permissions.contains({
|
||||||
|
origins: ["https://*.invidio.us/*", "https://*.invidiou.sh/*"],
|
||||||
|
permissions: ["declarativeContent"]
|
||||||
|
}, function (result) {
|
||||||
|
if (result != checkbox.checked) {
|
||||||
|
setOptionValue(option, result);
|
||||||
|
|
||||||
|
checkbox.checked = result;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run whenever the invidious checkbox is clicked
|
||||||
|
*
|
||||||
|
* @param {HTMLElement} checkbox
|
||||||
|
* @param {string} option
|
||||||
|
*/
|
||||||
|
function invidiousOnClick(checkbox, option) {
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
// Request permission
|
// Request permission
|
||||||
chrome.permissions.request({
|
chrome.permissions.request({
|
||||||
@@ -85,33 +148,6 @@ async function init() {
|
|||||||
origins: ["https://*.invidio.us/*"]
|
origins: ["https://*.invidio.us/*"]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
checksLeft--;
|
|
||||||
});
|
|
||||||
|
|
||||||
checksLeft++;
|
|
||||||
break;
|
|
||||||
case "text-change":
|
|
||||||
let button = optionsElements[i].querySelector(".trigger-button");
|
|
||||||
button.addEventListener("click", () => activateTextChange(optionsElements[i]));
|
|
||||||
|
|
||||||
break;
|
|
||||||
case "keybind-change":
|
|
||||||
let keybindButton = optionsElements[i].querySelector(".trigger-button");
|
|
||||||
keybindButton.addEventListener("click", () => activateKeybindChange(optionsElements[i]));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await wait(() => checksLeft == 0, 1000, 50);
|
|
||||||
|
|
||||||
optionsContainer.classList.remove("hidden");
|
|
||||||
optionsContainer.classList.add("animated");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user