forked from Dev-Zhao/skribbl.io-autodraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
60 lines (50 loc) · 1.68 KB
/
popup.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
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
var drawModeDotsRadio = document.getElementById("drawModeDotsRadio");
var drawModeLinesRadio = document.getElementById("drawModeLinesRadio");
var brushNumRangeInput = document.getElementById("brushNumRangeInput");
var brushNumIndicator = document.getElementById('brushNumIndicator');
var saveButton = document.getElementById("saveButton");
function updateDrawModeRadioButtons(drawMode){
switch (drawMode){
case "Dots":
drawModeDotsRadio.checked = true;
break;
case "Lines":
drawModeLinesRadio.checked = true;
break;
}
}
function updatebrushNum(brushNum){
brushNumRangeInput.value = brushNum;
switch(brushNum){
case 0:
brushNumIndicator.innerHTML = "Small";
break;
case 1:
brushNumIndicator.innerHTML = "Medium";
break;
case 2:
brushNumIndicator.innerHTML = "Large";
break;
case 3:
brushNumIndicator.innerHTML = "Extra Large";
break;
}
}
Promise.all([storage.getData("drawMode"), storage.getData("brushNum")]).then((data) => {
let drawMode = data[0];
let brushNum = data[1];
updateDrawModeRadioButtons(drawMode);
updatebrushNum(brushNum);
}).catch((errors) => {
console.log(errors);
});
brushNumRangeInput.oninput = function(){
updatebrushNum(parseInt(brushNumRangeInput.value));
};
saveButton.onclick = function(){
var drawMode = document.querySelector('input[name="drawModeRadios"]:checked').value;
var brushNum = parseInt(brushNumRangeInput.value);
storage.setData({drawMode: drawMode, brushNum: brushNum}).catch((err) => {
console.log(err);
});
};