-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
34 lines (28 loc) · 1.05 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
let page=document.getElementById('buttonDiv');
let selectedClassName='current';
const presetButtonColors=['red','pink','blue'];
const handleButtonClick=(event)=>{
let current=event.target.parentElement.querySelector(`.${selectedClassName}`);
if(current && current!==event.target){
current.classList.remove(selectedClassName);
}
let color=event.target.dataset.color;
event.target.classList.add('current');
chrome.storage.sync.set({color});
}
const displayColors=(buttonColors)=>{
chrome.storage.sync.get('color',(data)=>{
let currentColor=data.color;
buttonColors.forEach(buttonColor=>{
let button=document.createElement("button");
button.dataset.color=buttonColor;
button.style.backgroundColor=buttonColor;
if(buttonColor==currentColor){
button.classList.add(selectedClassName);
}
button.addEventListener('click',handleButtonClick);
page.appendChild(button);
})
})
}
displayColors(presetButtonColors);