-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
306 lines (281 loc) · 11.8 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
var url = window.location.href.toString();
var notes, hlights;
// EXPAND NOTES VIEW
var exp = document.getElementById("expand");
function expand() {
var faExp = document.getElementsByClassName("fa-expand")[0];
var faCom = document.getElementsByClassName("fa-compress")[0];
// var sb = document.getElementsByClassName("searchBar")[0];
// sb.classList.add("wide-search");
faExp.style.display = "none";
faCom.style.display = "block";
document.body.classList.add("wide-body");
}
exp.addEventListener("click", expand);
var com = document.getElementById("compress");
function compress() {
var faExp = document.getElementsByClassName("fa-expand")[0];
var faCom = document.getElementsByClassName("fa-compress")[0];
faExp.style.display = "block";
faCom.style.display = "none";
document.body.classList.remove("wide-body");
}
com.addEventListener("click", compress);
// function toggle() {
// var checkbox = document.getElementsByClassName("checkbox")[0];
// chrome.storage.local.get("active", results => {
// // alert(`${JSON.stringify(results.active)}`);
// if (results.active.active || results.active) {
// var on = document.getElementsByClassName("on")[0];
// on.style.display = "none";
// var off = document.getElementsByClassName("off")[0];
// off.style.display = "block";
// var msg = document.getElementsByClassName("toggle-msg")[0];
// msg.style.display = "block";
// var headerMsgOn = document.getElementsByClassName("on-header")[0];
// headerMsgOn.style.display = "none";
// var headerMsgOff = document.getElementsByClassName("off-header")[0];
// headerMsgOff.style.display = "block";
// chrome.storage.local.set({ active: false }, () => {});
// checkbox.removeAttribute("checked");
// } else {
// var on = document.getElementsByClassName("on")[0];
// on.style.display = "block";
// var off = document.getElementsByClassName("off")[0];
// off.style.display = "none";
// var msg = document.getElementsByClassName("toggle-msg")[0];
// msg.style.display = "block";
// var headerMsgOn = document.getElementsByClassName("on-header")[0];
// headerMsgOn.style.display = "block";
// var headerMsgOff = document.getElementsByClassName("off-header")[0];
// headerMsgOff.style.display = "none";
// chrome.storage.local.set({ active: true }, () => {});
// checkbox.setAttribute("checked", true);
// }
// });
// }
// function toggle2() {
// var checkbox = document.getElementsByClassName("checkbox")[0];
// chrome.storage.local.get("active", results => {
// if (results.active.active || results.active) {
// var on = document.getElementsByClassName("on")[0];
// on.style.display = "block";
// var off = document.getElementsByClassName("off")[0];
// off.style.display = "none";
// var headerMsgOn = document.getElementsByClassName("on-header")[0];
// headerMsgOn.style.display = "block";
// var headerMsgOff = document.getElementsByClassName("off-header")[0];
// headerMsgOff.style.display = "none";
// checkbox.setAttribute("checked", true);
// } else {
// var on = document.getElementsByClassName("on")[0];
// on.style.display = "none";
// var off = document.getElementsByClassName("off")[0];
// off.style.display = "block";
// var headerMsgOn = document.getElementsByClassName("on-header")[0];
// headerMsgOn.style.display = "none";
// var headerMsgOff = document.getElementsByClassName("off-header")[0];
// headerMsgOff.style.display = "block";
// checkbox.removeAttribute("checked");
// }
// });
// }
document.addEventListener("DOMContentLoaded", function() {
var footer = document.getElementsByClassName("footer")[0];
var instructions = document.getElementsByClassName("instructions")[0];
footer.addEventListener("click", () => {
if (
instructions.style.display == "none" ||
instructions.style.display == ""
) {
instructions.style.display = "block";
footer.style.height = "510px";
footer.style.transition = "1s";
document.getElementsByClassName("instructions-up")[0].style.display =
"none";
document.getElementsByClassName("instructions-down")[0].style.display =
"inline-block";
} else {
instructions.style.display = "none";
footer.style.height = "40px";
footer.style.transition = "1s";
document.getElementsByClassName("instructions-up")[0].style.display =
"inline-block";
document.getElementsByClassName("instructions-down")[0].style.display =
"none";
}
});
// toggle2();
// var checkbox = document.getElementsByClassName("checkbox")[0];
// checkbox.addEventListener("click", () => {
// toggle();
// });
// var tab1 = document.getElementsByClassName("tablinks")[0];
// tab1.addEventListener("click", () => {
// openTab(event, "toggle");
// });
var tab2 = document.getElementsByClassName("tablinks")[0];
tab2.addEventListener("click", () => {
openTab(event, "notes");
chrome.storage.local.get("highlights", results => {
var notesDiv = document.getElementsByClassName("notesDiv")[0];
notesDiv.style.display = "block";
var searchDiv = document.getElementsByClassName("searchDiv")[0];
searchDiv.style.display = "block";
// var urlHeader = document.getElementsByClassName("url-header")[0];
// urlHeader.style.display = "block";
// urlHeader.innerHTML = `${currentTab.url}`;
// all URLs listed as details
// current URL styled as a color with a tooltip saying current URL
var loader = document.getElementsByClassName("loader")[0];
loader.style.display = "none";
// var notesPs = Object.keys(results.highlights[currentTab.url])
var sites = Object.keys(results.highlights).map(el => {
hlights = Object.keys(results.highlights[el]).map(elem => {
if (!(elem.trim() == "color")) {
if (results.highlights[el][elem][3]) {
return `<p class="wrap highlights" style="text-align: left">- ${elem} <em>(note: ${
results.highlights[el][elem][3]
})</em></p>`;
}
return `<p class="wrap highlights" style="text-align: left">- ${elem}</p>`;
}
});
// ${el.substr( 0, 25)}
if (
!(
results.highlights[el]["color"] &&
Object.keys(results.highlights[el]).length == 1
) &&
Object.keys(results.highlights[el]).length > 0
) {
if (results.highlights[el]["color"]) {
return `<details class="detail">
<summary class="notes-url wrap">${el}<i class='fa fa-chevron-down' style='display: inline-block; margin-right: 6px'></i><a class="url" target="_blank" href="${el}">Link</a><span class="num">${hlights.length -
1}</span></summary>
${hlights.join("")}
</details>
<hr />`;
} else {
return `<details class="detail">
<summary class="notes-url wrap">${el}<i class='fa fa-chevron-down' style='display: inline-block; margin-right: 6px'></i><a class="url" target="_blank" href="${el}">Link</a><span class="num">${
hlights.length
}</span></summary>
${hlights.join("")}
</details>
<hr />`;
}
}
});
if (Object.keys(results.highlights).length > 0 && hlights.length > 0) {
notesDiv.innerHTML = sites.join("");
} else {
notesDiv.innerHTML = `No highlights stored yet. Click Instructions to learn how to use it.`;
}
});
// SEARCH FUNCTIONS
// var search = document.getElementsByClassName("searchBar")[0];
// search.addEventListener("keyup", () => {
// var val = search.value;
// alert(val);
// });
});
var tab3 = document.getElementsByClassName("tablinks")[1];
tab3.addEventListener("click", () => {
openTab(event, "color");
// change highlight color in example text
var colorPicker = document.getElementsByClassName("colorPicker")[0];
colorPicker.value = "#CFFFDF";
colorPicker.addEventListener("change", e => {
var example = document.getElementsByClassName("example-text")[0];
example.style.backgroundColor = colorPicker.value;
});
// make color picker input default value set to the highlight color for current url
var query = { active: true, currentWindow: true };
function callback(tabs) {
var currentTab = tabs[0];
chrome.storage.local.get("highlights", results => {
highlights = results.highlights;
if (highlights[currentTab.url] && highlights[currentTab.url]["color"]) {
colorPicker.value = highlights[currentTab.url]["color"];
}
var example = document.getElementsByClassName("example-text")[0];
example.style.backgroundColor = colorPicker.value;
});
}
chrome.tabs.query(query, callback);
// reset color picker value AND update stored current url highlight color
var resetColor = document.getElementsByClassName("reset")[0];
resetColor.addEventListener("click", e => {
e.preventDefault();
colorPicker.value = "#CFFFDF";
var example = document.getElementsByClassName("example-text")[0];
example.style.backgroundColor = colorPicker.value;
var query = { active: true, currentWindow: true };
function callback(tabs) {
var currentTab = tabs[0];
chrome.storage.local.get("highlights", results => {
highlights = results.highlights;
highlights[currentTab.url]["color"] = colorPicker.value;
chrome.storage.local.set({ highlights }, () => {});
document.getElementsByClassName(
"success-msg-reset"
)[0].style.display = "block";
document.getElementsByClassName("success-msg")[0].style.display =
"none";
});
}
chrome.tabs.query(query, callback);
});
// change color picker value AND update stored current url highlight color
var submitNewColor = document.getElementsByClassName("thisWebsite")[0];
submitNewColor.addEventListener("click", e => {
e.preventDefault();
var newColor = document.getElementsByClassName("colorPicker")[0].value;
var query = { active: true, currentWindow: true };
function callback(tabs) {
var currentTab = tabs[0];
chrome.storage.local.get("highlights", results => {
highlights = results.highlights;
if (!highlights[currentTab.url]) {
highlights[currentTab.url] = {};
highlights[currentTab.url]["color"] = newColor;
} else {
highlights[currentTab.url]["color"] = newColor;
}
chrome.storage.local.set({ highlights }, () => {});
document.getElementsByClassName(
"success-msg-reset"
)[0].style.display = "none";
document.getElementsByClassName("success-msg")[0].style.display =
"block";
});
}
chrome.tabs.query(query, callback);
});
});
});
// CHANGE TABS
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
// CHANGE COLOR
var highlights;
var newColor = document.getElementById("colorPicker");
function setColor(e) {
chrome.storage.local.get("highlights", results => {
highlights = results.highlights;
highlights[color] = newColor.value;
chrome.storage.local.set({ highlights }, () => {});
});
}