-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
63 lines (55 loc) · 2.03 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
'use strict';
class PopupController {
constructor() {
this.idleArea = document.getElementById("idle-area");
this.allottedTimeInput = document.getElementById("allotted-time-input");
this.startButton = document.getElementById("start-presentation");
this.startButton.addEventListener("click", this.start.bind(this));
this.runningArea = document.getElementById("running-area");
this.allottedTimeText = document.getElementById("allotted-time-text");
this.pauseResumeButton = document.getElementById("pause-resume-presentation");
this.pauseResumeButton.addEventListener("click", this.pauseResume.bind(this));
this.resetButton = document.getElementById("reset-presentation");
this.resetButton.addEventListener("click", this.reset.bind(this));
this.getStatus();
}
start() {
this.allottedTime = this.allottedTimeInput.value;
if(this.allottedTime) {
this.sendMessage({"command": "start", "allottedTime": this.allottedTime});
window.close();
}
}
pauseResume() {
this.sendMessage({"command": this.paused ? "resume" : "pause"});
this.paused = !this.paused;
this.refresh();
}
reset() {
this.sendMessage({"command": "reset"});
window.close();
}
refresh() {
this.idleArea.style.display = this.allottedTime ? "none" : "";
this.runningArea.style.display = this.allottedTime ? "" : "none";
this.allottedTimeText.textContent = this.allottedTime;
this.pauseResumeButton.value = this.paused ? "resume" : "pause";
}
getStatus() {
this.sendMessage({"command": "status"}, function(response) {
if (!response.allottedTime)
return;
this.allottedTime = response.allottedTime;
this.paused = response.paused;
this.refresh();
}.bind(this));
}
sendMessage(message, responseHandler) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, message, responseHandler);
});
}
}
document.addEventListener('DOMContentLoaded', function() {
new PopupController();
});