-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
138 lines (111 loc) · 3.37 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
//-----------------------------------------------
// Rec.it chrome extension javascript
// ----------------------------------------------
function RecProxy() {
this.active = null;
}
});
// if start send message to background.js to save state start
RecProxy.prototype.start = function(url) {
chrome.tabs.getSelected(null, function(tab) {
chrome.runtime.sendMessage({action: "start", recorded_tab: tab.id, start_url: url});
});
}
RecProxy.prototype.pause = function() {
chrome.runtime.sendMessage({action: "pause"}, function(response){
if(response.pause){
// if there is item append in list
if(!response.empty){
return true;
}
}
});
}
RecProxy.prototype.stop = function() {
chrome.runtime.sendMessage({action: "stop"});
}
RecProxy.prototype.open = function(url, callback) {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendMessage(tab.id, {action: "open", 'url': url}, callback);
});
}
//-----------------------------------------------
// Rec.it
// prototype attribute allow us to append new attribute function into constructor
// rewrite in ES6
//----------------------------------------------
class RecIT{
constructor(){
// listen message
this.recorder = new RecProxy();
chrome.runtime.sendMessage({action: "get_status"}, function(response) {
if (response.active) {
// if active show pause only
var e = document.getElementById("pause");
e.style.display = '';
e = document.getElementById("start");
e.style.display = 'none';
e = document.getElementById("export");
e.style.display = 'none';
} else {
if (!response.empty) {
// if not active and not empty
// show stop and start
var e = document.getElementById("stop");
e.style.display = '';
e = document.getElementById("start");
e.style.display = '';
e = document.getElementById("export");
e.style.display = 'none';
}
chrome.tabs.getSelected(null, function(tab) {
});
}
});
}
start(){
// set css toggle start and pause
var e = document.getElementById("pause");
e.style.display = '';
e = document.getElementById("start");
e.style.display = 'none';
// pass message
this.recorder.start();
}
pause(){
// set css toggle pause and start
var e = document.getElementById("pause");
e.style.display = 'none';
// show start
e = document.getElementById("start");
e.style.display = '';
// pass message at the same time if already has recording show stop option
if(this.recorder.pause()){
e = document.getElementById("stop");
e.style.display = '';
};
}
stop(){
// set css on stop you can choose to export or start again
var e = document.getElementById("stop");
e.style.display = 'none';
e = document.getElementById("start");
e.style.display = '';
e = document.getElementById("export");
e.style.display = '';
// pass message
this.recorder.stop();
}
export(){
chrome.tabs.create({url: "./recit.html"});
}
}
var ui;
// bind events to ui elements
window.onload = function(){
ui = new RecIT();
document.querySelector('#start').onclick=function() {ui.start(); return false;};
document.querySelector('#pause').onclick=function() {ui.pause(); return false;};
document.querySelector('#stop').onclick=function() {ui.stop(); return false;};
document.querySelector('#export').onclick=function() {ui.export(); return false;};
}