mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Made the options save.
This commit is contained in:
parent
13727270d4
commit
2e2ff60c23
1 changed files with 24 additions and 4 deletions
|
@ -13,14 +13,22 @@ async function init() {
|
|||
for (let i = 0; i < optionsElements.length; i++) {
|
||||
switch (optionsElements[i].getAttribute("option-type")) {
|
||||
case "toggle":
|
||||
chrome.storage.sync.get([optionsElements[i].getAttribute("toggle-sync-option")], function(result) {
|
||||
let optionResult = result[optionsElements[i].getAttribute("toggle-sync-option")];
|
||||
let option = optionsElements[i].getAttribute("toggle-sync-option");
|
||||
chrome.storage.sync.get([option], function(result) {
|
||||
let optionResult = result[option];
|
||||
if (optionResult != undefined) {
|
||||
optionsElements[i].querySelector("input").checked = optionResult;
|
||||
let checkbox = optionsElements[i].querySelector("input");
|
||||
checkbox.checked = optionResult;
|
||||
|
||||
if (optionsElements[i].getAttribute("toggle-type") == "reverse") {
|
||||
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
||||
|
||||
if (reverse) {
|
||||
optionsElements[i].querySelector("input").checked = !optionResult;
|
||||
}
|
||||
|
||||
checkbox.addEventListener("click", () =>{
|
||||
optionToggled(option, reverse ? !checkbox.checked : checkbox.checked)
|
||||
});
|
||||
}
|
||||
|
||||
checksLeft--;
|
||||
|
@ -35,4 +43,16 @@ async function init() {
|
|||
|
||||
optionsContainer.style.display = "inherit";
|
||||
optionsContainer.classList.add("animated");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an option has been toggled.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
*/
|
||||
function optionToggled(option, value) {
|
||||
console.log(option)
|
||||
console.log(value)
|
||||
|
||||
chrome.storage.sync.set({[option]: value});
|
||||
}
|
Loading…
Reference in a new issue