-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.js
More file actions
68 lines (60 loc) · 2.09 KB
/
options.js
File metadata and controls
68 lines (60 loc) · 2.09 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
let page = document.getElementById("buttonDiv")
let selected = document.getElementById('selectedStacks')
let stacks = [];
getStacks();
selectedStacks();
function getStacks(){
chrome.storage.sync.get( (data)=>{
stacks = (data.stackList)
console.log(stacks);
stacks.forEach(element => {
if(element !== null){
let button = document.createElement("button");
button.classList.add("m-2", "btn-dark","p-2" );
button.innerText = element;
button.addEventListener("click", handleButtonClick);
setTimeout(() => {
page.appendChild(button);
}, 100);
}
});
})
}
function selectedStacks(){
chrome.storage.sync.get('StacksToKeep', (data)=>{
console.log(data.StacksToKeep);
data.StacksToKeep.forEach(element => {
let list = document.createElement('li')
list.innerText = element
list.classList.add("m-2", "bg-primary", "p-2", "text-light", "border", "rounded-pill")
list.addEventListener("click", handleButtonClick)
selected.appendChild(list)
})
})
}
function handleButtonClick(elem){
btnVal = elem.srcElement.innerText;
btnVal = btnVal+" ";
console.log(btnVal);
chrome.storage.sync.get(['StacksToKeep', 'stackList'], data =>{
stk = data.StacksToKeep;
stklst = data.stackList
console.log('this is the data', data);
if(stk.includes(btnVal)){
let stackIndex = stk.indexOf(btnVal)
stk.splice(stackIndex,1);
let StacksToKeep = stk
console.log('stackstokeep ---> ', StacksToKeep);
stackList = data.stackList
stackList.push(btnVal)
chrome.storage.sync.set({StacksToKeep})
} else {
stk.push(btnVal);
let StacksToKeep = stk;
console.log('else ---> ', StacksToKeep);
chrome.storage.sync.set({StacksToKeep})
}
// chrome.storage.sync.set({stackList})
})
window.location.reload()
}