-
Notifications
You must be signed in to change notification settings - Fork 2
/
sketch.js
160 lines (137 loc) · 5.06 KB
/
sketch.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// --------------------------- To Write on screen -------------------------------
console.log("outside");
function setup() {
chrome.storage.sync.get(['color'],(result)=>{
console.log("inside here :", result.color);
document.getElementById("start").style.backgroundColor=result.color;
});
noCanvas();
// start
document.getElementById("start").addEventListener("click",()=>{startFunc()});
//COLORS
document.getElementById("redColor").addEventListener("click", () => { changeColor('#FF0000') });
document.getElementById("orangeColor").addEventListener("click", () => { changeColor('#F26202') });
document.getElementById("yellowColor").addEventListener("click", () => { changeColor('#EAAE00') });
document.getElementById("greenColor").addEventListener("click", () => { changeColor('#00FF00') });
document.getElementById("blueColor").addEventListener("click", () => { changeColor('#0000FF') });
document.getElementById("whiteColor").addEventListener("click", () => { changeColor('#FFFFFF') });
document.getElementById("blackColor").addEventListener("click", () => { changeColor('#000000') });
document.getElementById("violetColor").addEventListener("click", () => { changeColor('#5829BB') });
document.getElementById("pinkColor").addEventListener("click", () => { changeColor('#E61A8D') });
//STROKES
document.getElementById("1x").addEventListener("click", () => { changeStroke(1) });
document.getElementById("2x").addEventListener("click", () => { changeStroke(2) });
document.getElementById("3x").addEventListener("click", () => { changeStroke(3) });
document.getElementById("4x").addEventListener("click", () => { changeStroke(4) });
document.getElementById("5x").addEventListener("click", () => { changeStroke(5) });
//SHAPES
document.getElementById("lineShape").addEventListener("click", () => { changeShape("lineShape") });
document.getElementById("circleShape").addEventListener("click", () => { changeShape("circleShape") });
document.getElementById("ellipseShape").addEventListener("click", () => { changeShape("ellipseShape") });
document.getElementById("squareShape").addEventListener("click", () => { changeShape("squareShape") });
document.getElementById("triangleShape").addEventListener("click", () => { changeShape("triangleShape") });
//TOOLS
document.getElementById("eraserTool").addEventListener("click", () => { changeTool("eraserTool") });
document.getElementById("bucketTool").addEventListener("click", () => { changeTool("bucketTool") });
document.getElementById("brushTool").addEventListener("click", () => { changeTool("brushTool") });
document.getElementById("sprayTool").addEventListener("click", () => { changeTool("sprayTool") });
// start
function startFunc(){
let start;
chrome.storage.sync.get(['on'],(result)=>{
start=result.on;
start=(start===true) ? false : true;
chrome.storage.sync.set({on:start},()=>{
if(start===true){
chrome.storage.sync.set({color:"#12c7ea"},()=>{
document.getElementById("start").style.backgroundColor="#12c7ea";
})
}
else
chrome.storage.sync.set({color:"#A4A4AB"},()=>{
document.getElementById("start").style.backgroundColor="#A4A4AB";
})
})
});
};
//to change the color
function changeColor(currcolor) {
let params = {
active: true,
currentWindow: true,
};
chrome.tabs.query(params, gotTabs);
function gotTabs(tabs) {
let msg = {
color: currcolor,
flag: 0
};
console.log("color", msg.color);
chrome.tabs.sendMessage(tabs[0].id, msg);
}
};
//to change the stroke
function changeStroke(currWeight) {
let params = {
active: true,
currentWindow: true,
};
chrome.tabs.query(params, gotTabs);
function gotTabs(tabs) {
let msg = {
weight: currWeight,
flag: 1
};
console.log("weight", msg.weight);
chrome.tabs.sendMessage(tabs[0].id, msg);
}
}
}
//to change the shape
function changeShape(currShape) {
let params = {
active: true,
currentWindow: true,
};
chrome.tabs.query(params, gotTabs);
function gotTabs(tabs) {
let msg = {
shape: currShape,
flag: 2
};
console.log("clicked shape", msg.shape);
chrome.tabs.sendMessage(tabs[0].id, msg);
}
};
//to change the tools
function changeTool(currTool) {
let params = {
active: true,
currentWindow: true,
};
chrome.tabs.query(params, gotTabs);
function gotTabs(tabs) {
let msg = {
tool: currTool,
flag: 3
};
console.log("Tool selected", msg.tool);
chrome.tabs.sendMessage(tabs[0].id, msg);
}
};
// let userinput = select("#userinput");
// userinput.input(changeText);
// function changeText() {
// let params = {
// active: true,
// currentWindow: true,
// };
// chrome.tabs.query(params, gotTabs);
// function gotTabs(tabs) {
// console.log("tabs: ", tabs);
// let message = userinput.value();
// console.log("message : ", message);
// let msg = {
// txt: message,
// };
// }