-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
76 lines (65 loc) · 2.21 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function getCurrentTabUrl(callback) {
let queryInfo = {
active: true,
currentWindow: true
};
chrome.tabs.query(queryInfo, (tabs) => {
let tab = tabs[0];
let url = tab.url;
console.assert(typeof url == 'string', 'tab.url should be a string');
callback(url);
});
}
function startDraw(color, weight) {
let drawConfig = {
color: color,
weight: weight,
// transparency: transparency
};
console.log(drawConfig)
chrome.tabs.executeScript({
code: 'var drawConfig = ' + JSON.stringify(drawConfig)
}, () => {
chrome.tabs.executeScript({
file: "sketch.js"
});
});
}
let selectedWeight = () => {
let weight = document.getElementById('weight');
return weight.value
}
let selectedColour = (colours) => {
let colour = colours.find(colour => colour.classList.contains('active'));
return colour.dataset.colour
}
document.addEventListener('DOMContentLoaded', () => {
getCurrentTabUrl((url) => {
const colours = Array.from(document.querySelectorAll('.colour-choice'));
const drawIcon = document.querySelector('#draw-button');
const slider = document.querySelector('#weight');
const weightValue = document.querySelector('#weight-value');
drawIcon.addEventListener('click', () => {
let selColour = selectedColour(colours);
let selWeight = selectedWeight();
startDraw(selColour, selWeight);
})
colours.forEach((colour) => {
colour.addEventListener('click', () => {
colours.forEach((colour) => {
colour.classList.remove('active')
});
colour.classList.add('active')
let selColour = selectedColour(colours);
let selWeight = selectedWeight();
startDraw(selColour, selWeight);
});
})
slider.addEventListener("input", function() {
let selColour = selectedColour(colours);
let selWeight = selectedWeight();
weightValue.innerHTML = selWeight
startDraw(selColour, selWeight);
});
});
});