Skip to content

Commit

Permalink
feat: slider memory
Browse files Browse the repository at this point in the history
Implement functionality for remembering slider settings
Disable slider on incompatible filters
  • Loading branch information
cadomac committed Aug 8, 2023
1 parent 62ff675 commit 949b823
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ $.all = function (selector, context) {

let current;
let currentMatrix;
let filterValues = {
"TrueColor": 100,
"TrueColorG": 100,
"TrueColorD": 100,
"TrueColorN": 100,
}

localStorage.setItem("filterValues", JSON.stringify(filterValues));

if (!localStorage.getItem("currentFilter")) {
localStorage.setItem("currentFilter", "NoFilter");
Expand Down Expand Up @@ -42,6 +50,10 @@ slider.type = "range";
slider.addEventListener('input', async (e) => {
const [tab] = await chrome.tabs.query({active: true, lastFocusedWindow: true});
const response = await chrome.tabs.sendMessage(tab.id, {filter: current, value: e.target.value});
if (response.msg === "success") {
filterValues = {...filterValues, [current]: e.target.value}
localStorage.setItem("filterValues", JSON.stringify(filterValues))
}
});

document.body.appendChild(slider);
Expand Down Expand Up @@ -76,6 +88,13 @@ function handler(e) {
localStorage.setItem("css", `html { -webkit-filter: url(#${current}); }`)

}
console.log(current)
if (current.includes("TrueColor")) {
slider.disabled = false;
slider.value = JSON.parse(localStorage.getItem("filterValues"))[current];
} else {
slider.disabled = true;
}
}
})
}

0 comments on commit 949b823

Please sign in to comment.