mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-13 15:07:02 +03:00
show version + clickable labels
This commit is contained in:
@@ -44,9 +44,7 @@ async function init() {
|
||||
if (dependentOn)
|
||||
isDependentOnReversed = dependentOn.getAttribute("data-toggle-type") === "reverse" || optionsElements[i].getAttribute("data-dependent-on-inverted") === "true";
|
||||
|
||||
if ((optionsElements[i].getAttribute("data-private-only") === "true" && !(await isIncognitoAllowed()))
|
||||
|| (optionsElements[i].getAttribute("data-no-safari") === "true" && navigator.vendor === "Apple Computer, Inc.")
|
||||
|| (dependentOn && (isDependentOnReversed ? Config.config[dependentOnName] : !Config.config[dependentOnName]))) {
|
||||
if (await shouldHideOption(optionsElements[i]) || (dependentOn && (isDependentOnReversed ? Config.config[dependentOnName] : !Config.config[dependentOnName]))) {
|
||||
optionsElements[i].classList.add("hidden");
|
||||
if (!dependentOn)
|
||||
continue;
|
||||
@@ -74,7 +72,7 @@ async function init() {
|
||||
}
|
||||
|
||||
// Add click listener
|
||||
checkbox.addEventListener("click", () => {
|
||||
checkbox.addEventListener("click", async () => {
|
||||
// Confirm if required
|
||||
if (checkbox.checked && confirmMessage && !confirm(chrome.i18n.getMessage(confirmMessage))){
|
||||
checkbox.checked = false;
|
||||
@@ -105,20 +103,15 @@ async function init() {
|
||||
break;
|
||||
}
|
||||
|
||||
// If other options depend on this, hide and disable them
|
||||
// If other options depend on this, hide/show them
|
||||
const dependents = optionsContainer.querySelectorAll(`[data-dependent-on='${option}']`);
|
||||
for (let j = 0; j < dependents.length; j++) {
|
||||
const isDependentReversed = dependents[j].getAttribute("data-toggle-type") === "reverse";
|
||||
const disableWhenChecked = dependents[j].getAttribute("data-dependent-on-inverted") === "true";
|
||||
if (!disableWhenChecked && checkbox.checked || disableWhenChecked && !checkbox.checked) {
|
||||
if (!await shouldHideOption(dependents[j]) && (!disableWhenChecked && checkbox.checked || disableWhenChecked && !checkbox.checked)) {
|
||||
dependents[j].classList.remove("hidden");
|
||||
} else {
|
||||
if (dependents[j].getAttribute("data-type") === "toggle") {
|
||||
(dependents[j].querySelector("div > label > input") as HTMLInputElement).checked = false;
|
||||
Config.config[dependents[j].getAttribute("data-sync")] = isDependentReversed;
|
||||
}
|
||||
dependents[j].classList.add("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
@@ -254,10 +247,22 @@ async function init() {
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById("version").innerText = "v. " + chrome.runtime.getManifest().version;
|
||||
|
||||
optionsContainer.classList.remove("hidden");
|
||||
optionsContainer.classList.add("animated");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle special cases where an option shouldn't show
|
||||
*
|
||||
* @param {String} element
|
||||
*/
|
||||
async function shouldHideOption(element: Element): Promise<boolean> {
|
||||
return (element.getAttribute("data-private-only") === "true" && !(await isIncognitoAllowed()))
|
||||
|| (element.getAttribute("data-no-safari") === "true" && navigator.vendor === "Apple Computer, Inc.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the config is updated
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user