forked from OpenSquad/Focus-Time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
260 lines (176 loc) · 6.78 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
window.onload = function () {
s=document.getElementById("toclick");
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
// No tabs or host permissions needed!
alert("Site : "+tab.url);
chrome.tabs.executeScript({
code: 'alert("Tab : "+tab.url)'
});
});
};
document.addEventListener('DOMContentLoaded', function() {
var instances = M.AutoInit();
var sessionCrt=document.getElementById('sessionValue');
sessionCrt.onchange = function(){alert(sessionCrt.value);chrome.runtime.sendMessage({activatesession:sessionCrt.value});}
document.getElementById("tough4").onchange=function(){
var elem = document.getElementById("loadulation");
var width = 1;
var id = setInterval(frame, 10);
function frame() {
if (width >= 100) {
clearInterval(id);
} else {
width++;
elem.style.width = width + '%';
}
}
}
});
// ******* tout doux liste logic *********\\
var taskInput=document.getElementById("new-task");//Add a new task.
var addButton=document.getElementsByTagName("button")[0];//first button
var incompleteTaskHolder=document.getElementById("incomplete-tasks");//ul of #incomplete-tasks
var completedTasksHolder=document.getElementById("completed-tasks");//completed-tasks
//New task list item
var createNewTaskElement=function(taskString){
var listItem=document.createElement("li");
//input (checkbox)
var checkBox=document.createElement("input");//checkbx
//label
var label=document.createElement("label");//label
//input (text)
var editInput=document.createElement("input");//text
//button.edit
var editButton=document.createElement("button");//edit button
//button.delete
var deleteButton=document.createElement("button");//delete button
label.innerText=taskString;
//Each elements, needs appending
checkBox.type="checkbox";
checkBox.id="tough";
checkBox.className="berouit";
editInput.type="text";
label.setAttribute("for","tough");
editButton.innerText="Edit";//innerText encodes special characters, HTML does not.
editButton.className="edit btn-small zre9 byed padderul";
deleteButton.innerText="Delete";
deleteButton.className="delete btn-small zre9 biyed";
//and appending.
listItem.appendChild(checkBox);
listItem.appendChild(label);
listItem.appendChild(editInput);
listItem.appendChild(editButton);
listItem.appendChild(deleteButton);
return listItem;
}
var addTask=function(){
console.log("Add Task...");
//Create a new list item with the text from the #new-task:
var listItem=createNewTaskElement(taskInput.value);
//Append listItem to incompleteTaskHolder
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem, taskCompleted);
taskInput.value="";
}
//Edit an existing task.
var editTask=function(){
console.log("Edit Task...");
console.log("Change 'edit' to 'save'");
var listItem=this.parentNode;
var editInput=listItem.querySelector('input[type=text]');
var label=listItem.querySelector("label");
var containsClass=listItem.classList.contains("editMode");
//If class of the parent is .editmode
if(containsClass){
//switch to .editmode
//label becomes the inputs value.
label.innerText=editInput.value;
}else{
editInput.value=label.innerText;
}
//toggle .editmode on the parent.
listItem.classList.toggle("editMode");
}
//Delete task.
var deleteTask=function(){
console.log("Delete Task...");
var listItem=this.parentNode;
var ul=listItem.parentNode;
//Remove the parent list item from the ul.
ul.removeChild(listItem);
}
//Mark task completed
var taskCompleted=function(){
console.log("Complete Task...");
//Append the task list item to the #completed-tasks
var listItem=this.parentNode;
completedTasksHolder.appendChild(listItem);
bindTaskEvents(listItem, taskIncomplete);
}
var taskIncomplete=function(){
console.log("Incomplete Task...");
//Mark task as incomplete.
//When the checkbox is unchecked
//Append the task list item to the #incomplete-tasks.
var listItem=this.parentNode;
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem,taskCompleted);
}
var ajaxRequest=function(){
console.log("AJAX Request");
}
//The glue to hold it all together.
//Set the click handler to the addTask function.
var bindTaskEvents=function(taskListItem,checkBoxEventHandler){
console.log("bind list item events");
//select ListItems children
var checkBox=taskListItem.querySelector("input[type=checkbox]");
var editButton=taskListItem.querySelector("button.edit");
var deleteButton=taskListItem.querySelector("button.delete");
//Bind editTask to edit button.
editButton.onclick=editTask;
//Bind deleteTask to delete button.
deleteButton.onclick=deleteTask;
//Bind taskCompleted to checkBoxEventHandler.
checkBox.onchange=checkBoxEventHandler;
}
//cycle over incompleteTaskHolder ul list items
//for each list item
for (var i=0; i<incompleteTaskHolder.children.length;i++){
//bind events to list items chldren(tasksCompleted)
bindTaskEvents(incompleteTaskHolder.children[i],taskCompleted);
}
//cycle over completedTasksHolder ul list items
for (var i=0; i<completedTasksHolder.children.length;i++){
//bind events to list items chldren(tasksIncompleted)
bindTaskEvents(completedTasksHolder.children[i],taskIncomplete);
}
// Issues with usabiliy don't get seen until they are in front of a human tester.
//prevent creation of empty tasks.
//Shange edit to save when you are in edit mode.
// *****************************************\\
// ************ message**********************\\
var sent=false;
chrome.runtime.sendMessage({getsessions2:true});
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
for(var i in message.sessions2){if(message.sessions2[i]===undefined){return;}}
var sessionCrt=document.getElementById('sessionValue');
if(message.sessions2!==undefined && !sent)
{
sent=true;
console.log("MESSAGE SESSIONS2"+message.sessions2);
for(var i in message.sessions2)
{
var option=document.createElement("option");
option.text=message.sessions2[i].name;
option.value=message.sessions2[i].name;
sessionCrt.add(option);
}
}
}
);
document.addEventListener('DOMContentLoaded', function(){
var junk = document.getElementById('dashJump')
junk.onclick=function(){chrome.tabs.create({url: "dashboard/dashboard.html"});}
})