mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
Converted options page to new config system.
This commit is contained in:
@@ -3,38 +3,33 @@ window.addEventListener('DOMContentLoaded', init);
|
|||||||
async function init() {
|
async function init() {
|
||||||
localizeHtmlPage();
|
localizeHtmlPage();
|
||||||
|
|
||||||
|
await wait(() => SB.config !== undefined);
|
||||||
|
|
||||||
// Set all of the toggle options to the correct option
|
// Set all of the toggle options to the correct option
|
||||||
let optionsContainer = document.getElementById("options");
|
let optionsContainer = document.getElementById("options");
|
||||||
let optionsElements = optionsContainer.children;
|
let optionsElements = optionsContainer.children;
|
||||||
|
|
||||||
// How many checks are left to be done
|
|
||||||
let checksLeft = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < optionsElements.length; i++) {
|
for (let i = 0; i < optionsElements.length; i++) {
|
||||||
switch (optionsElements[i].getAttribute("option-type")) {
|
switch (optionsElements[i].getAttribute("option-type")) {
|
||||||
case "toggle":
|
case "toggle":
|
||||||
let option = optionsElements[i].getAttribute("sync-option");
|
let option = optionsElements[i].getAttribute("sync-option");
|
||||||
chrome.storage.sync.get([option], function(result) {
|
|
||||||
let optionResult = result[option];
|
|
||||||
if (optionResult != undefined) {
|
|
||||||
let checkbox = optionsElements[i].querySelector("input");
|
|
||||||
checkbox.checked = optionResult;
|
|
||||||
|
|
||||||
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
let optionResult = SB.config[option];
|
||||||
|
|
||||||
if (reverse) {
|
let checkbox = optionsElements[i].querySelector("input");
|
||||||
optionsElements[i].querySelector("input").checked = !optionResult;
|
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
||||||
}
|
|
||||||
|
|
||||||
checkbox.addEventListener("click", () =>{
|
if (optionResult != undefined) {
|
||||||
SB.config[option] = reverse ? !checkbox.checked : checkbox.checked;
|
checkbox.checked = optionResult;
|
||||||
});
|
|
||||||
|
if (reverse) {
|
||||||
|
optionsElements[i].querySelector("input").checked = !optionResult;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
checksLeft--;
|
checkbox.addEventListener("click", () =>{
|
||||||
|
SB.config[option] = reverse ? !checkbox.checked : checkbox.checked;
|
||||||
});
|
});
|
||||||
|
|
||||||
checksLeft++;
|
|
||||||
break;
|
break;
|
||||||
case "text-change":
|
case "text-change":
|
||||||
let button = optionsElements[i].querySelector(".trigger-button");
|
let button = optionsElements[i].querySelector(".trigger-button");
|
||||||
@@ -49,8 +44,6 @@ async function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await wait(() => checksLeft == 0, 1000, 50);
|
|
||||||
|
|
||||||
optionsContainer.classList.remove("hidden");
|
optionsContainer.classList.remove("hidden");
|
||||||
optionsContainer.classList.add("animated");
|
optionsContainer.classList.add("animated");
|
||||||
}
|
}
|
||||||
@@ -68,21 +61,19 @@ function activateKeybindChange(element) {
|
|||||||
|
|
||||||
let option = element.getAttribute("sync-option");
|
let option = element.getAttribute("sync-option");
|
||||||
|
|
||||||
chrome.storage.sync.get([option], function(result) {
|
let currentlySet = SB.config[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : "";
|
||||||
let currentlySet = result[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : "";
|
|
||||||
|
|
||||||
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
|
||||||
status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet;
|
|
||||||
|
|
||||||
if (result[option] !== null) {
|
|
||||||
let statusKey = element.querySelector(".option-hidden-section > .keybind-status-key");
|
|
||||||
statusKey.innerText = result[option];
|
|
||||||
}
|
|
||||||
|
|
||||||
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
||||||
|
status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet;
|
||||||
document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true});
|
|
||||||
});
|
if (SB.config[option] !== null) {
|
||||||
|
let statusKey = element.querySelector(".option-hidden-section > .keybind-status-key");
|
||||||
|
statusKey.innerText = SB.config[option];
|
||||||
|
}
|
||||||
|
|
||||||
|
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +88,7 @@ function keybindKeyPressed(element, e) {
|
|||||||
|
|
||||||
let option = element.getAttribute("sync-option");
|
let option = element.getAttribute("sync-option");
|
||||||
|
|
||||||
chrome.storage.sync.set({[option]: key});
|
SB.config[option] = key;
|
||||||
|
|
||||||
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
||||||
status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete");
|
status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete");
|
||||||
|
|||||||
Reference in New Issue
Block a user