-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopup.js
150 lines (127 loc) · 5.4 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
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
const startBtn = document.getElementById("start-btn");
const stopBtn = document.getElementById("stop-btn");
const runStatus = document.getElementById("runStatus");
const container = document.getElementById("container");
const randomBtn = document.getElementById("random");
const autoJoinBtn = document.getElementById("autoJoin");
const notifyBtn = document.getElementById("notify");
const email = document.getElementById("email");
// Update email on change
email.addEventListener("input", () => {
chrome.storage.local.set({ email: email.value });
});
document.addEventListener("DOMContentLoaded", () => {
chrome.storage.local.get(["status"], function (result) {
if (result.status == "started") {
startBtn.style.display = "none";
runStatus.style.display = "block";
stopBtn.style.display = "block";
runStatus.style.transform = "scale(0)";
runStatus.style.transform = "scale(0)";
setTimeout(() => {
runStatus.style.transition = "0.5s";
runStatus.style.transform = "scale(1)";
stopBtn.style.transition = "0.5s";
stopBtn.style.transform = "scale(1)";
}, 100);
} else if (result.status == "stopped" || result.status == undefined) {
runStatus.style.display = "none";
document.getElementById("form").style.marginTop = "30px";
startBtn.style.display = "block";
startBtn.style.transition = "0.5s";
startBtn.style.transform = "scale(1)";
stopBtn.style.display = "none";
}
});
chrome.storage.local.get(["random"], function (result) {
if (result.random == true) {
randomBtn.checked = true;
} else if (result.random == false || result.random == undefined) {
randomBtn.checked = false;
}
});
chrome.storage.local.get(["autoJoin"], function (result) {
if (result.autoJoin == true) {
autoJoinBtn.checked = true;
} else if (result.autoJoin == false || result.random == undefined) {
autoJoinBtn.checked = false;
}
});
chrome.storage.local.get(["email"], function (result) {
if (result.email == undefined) {
email.value = "";
} else {
email.value = result.email;
}
});
chrome.storage.local.get(["notify"], function (result) {
if (result.notify == true) {
notifyBtn.checked = true;
} else if (result.notify == false || result.notify == undefined) {
notifyBtn.checked = false;
}
});
});
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0];
if (tab.url === undefined || tab.url.indexOf("chrome") == 0) {
container.innerHTML = "<h1>ByeClicker can't access Chrome Pages</h1>";
} else if (tab.url.indexOf("file") == 0) {
container.innerHTML = "<h1>ByeClicker can't access local files</h1>";
} else if (!tab.url.includes("student.iclicker.com")) {
container.innerHTML = "<h1>ByeClicker works only on iCliker pages</h1>";
} else {
startBtn.addEventListener("click", () => {
startBtn.style.transition = "0.5s";
startBtn.style.transform = "scale(0)";
setTimeout(() => {
startBtn.style.display = "none";
runStatus.style.display = "block";
stopBtn.style.display = "block";
runStatus.style.transform = "scale(0)";
runStatus.style.transform = "scale(0)";
setTimeout(() => {
runStatus.style.transition = "0.5s";
runStatus.style.transform = "scale(1)";
stopBtn.style.transition = "0.5s";
stopBtn.style.transform = "scale(1)";
}, 100);
}, 500);
chrome.tabs.sendMessage(tab.id, { from: "popup", msg: "start" });
});
stopBtn.addEventListener("click", () => {
runStatus.style.transition = "0.5s";
runStatus.style.transform = "scale(0)";
stopBtn.style.transition = "0.5s";
stopBtn.style.transform = "scale(0)";
setTimeout(() => {
document.getElementById("form").style.marginTop = "30px";
runStatus.style.display = "none";
stopBtn.style.display = "none";
startBtn.style.display = "block";
startBtn.style.transform = "scale(0)";
setTimeout(() => {
startBtn.style.transition = "0.5s";
startBtn.style.transform = "scale(1)";
}, 100);
// startBtn.style.transition = '0.5s';
// startBtn.style.transform = 'scale(1)';
}, 500);
chrome.tabs.sendMessage(tab.id, { from: "popup", msg: "stop" });
});
randomBtn.addEventListener("click", () => {
chrome.tabs.sendMessage(tab.id, { from: "popup", msg: "random" });
});
autoJoinBtn.addEventListener("click", () => {
chrome.tabs.sendMessage(tab.id, { from: "popup", msg: "autoJoin" });
});
notifyBtn.addEventListener("click", () => {
return;
chrome.tabs.sendMessage(tab.id, {
from: "popup",
msg: "notify",
email: email.value,
});
});
}
});