-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
304 lines (260 loc) · 8.72 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
/// Navigate to given session's Visual Trace page
let instances;
let titles;
let analysis;
document.querySelector('#optionsPage').addEventListener('click', function() {
if (chrome.runtime.openOptionsPage) {
chrome.runtime.openOptionsPage();
} else {
window.open(chrome.runtime.getURL('options.html'));
}
});
document.getElementById('pdfViewerBtn').addEventListener('click', function() {
let base64 = document.getElementById('base64').value
try {
console.log(base64);
decode(base64);
} catch {
alert("Unable to convert base64 text to PDF. Make sure you're highlighting the whole text.");
}
});
let pageTitlesSearch = document.getElementById("pageTitlesSearch");
pageTitlesSearch.addEventListener('keyup', function(e) {
searchPageTitles(e);
});
const keys = ["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft", "Control", "Shift"]
function searchPageTitles(e) {
console.log(e);
let key = e.key;
let eValue = e.target.value;
if (keys.includes(key)) {
//console.log(e.key, "skipped")
return
}
let textSearch = eValue.toLowerCase();
textSearch = textSearch.replace(/\s/gm, " ");
for (var i = titles.length - 1, page; page = titles[i]; i--) {
console.log("Check page: ", page);
//console.log((row.childNodes[4].innerText.toUpperCase() == (textSearchArray[1].toUpperCase())));
let compareText = page.title.replace(/\s/gm, " ");
compareText = compareText.toLowerCase();
if (compareText.includes(textSearch)) {
document.getElementById(page.id).style.display = "";
} else {
document.getElementById(page.id).style.display = "none";
}
}
}
function searchAnalysis(e) {
console.log(e);
let key = e.key;
let eValue = e.target.value;
if (keys.includes(key)) {
//console.log(e.key, "skipped")
return
}
let textSearch = eValue.toLowerCase();
textSearch = textSearch.replace(/\s/gm, " ");
for (var i = titles.length - 1, page; page = titles[i]; i--) {
console.log("Check page: ", page);
//console.log((row.childNodes[4].innerText.toUpperCase() == (textSearchArray[1].toUpperCase())));
let compareText = page.title.replace(/\s/gm, " ");
compareText = compareText.toLowerCase();
if (compareText.includes(textSearch)) {
document.getElementById(page.id).style.display = "";
} else {
document.getElementById(page.id).style.display = "none";
}
}
}
let pageTitlesBtnClicked = false;
document.getElementById('pageTitlesBtn').addEventListener('click', function() {
if (pageTitlesBtnClicked) {
return
}
pageTitlesBtnClicked = true;
try {
let pageContainerDiv = document.getElementById("pageContainerDiv");
let length = titles.length
for (i = 0; i < length; i++) {
let pageDiv = createPageDiv(titles[i])
if (i >= 5) {
pageDiv.style.display = "none";
pageContainerDiv.appendChild(pageDiv);
} else {
pageContainerDiv.appendChild(pageDiv);
}
}
} catch {
alert("Unable to load pages.");
}
});
/* // Option to save analysis.
let analysisBtnClicked = false;
document.getElementById('savedAnalysisBtn').addEventListener('click', function() {
if (analysisBtnClicked) {
return
}
analysisBtnClicked = true;
try {
let analysisContainerDiv = document.getElementById("analysisContainerDiv");
let length = analysis.length
for (i = 0; i < length; i++) {
let pageDiv = createAnalysisDiv(analysis[i])
if (i >= 5) {
pageDiv.style.display = "none";
analysisContainerDiv.appendChild(pageDiv);
} else {
analysisContainerDiv.appendChild(pageDiv);
}
}
} catch {
alert("Unable to load pages.");
}
});*/
function createAnalysisDiv(page) {
let analysisContainerDiv = document.createElement("div");
analysisContainerDiv.classList.add("pageContainerDiv");
if (page.name == "") {
analysisContainerDiv.innerHTML = "<a href='"+page.url+"' target='_blank' rel='noopener noreferrer'>"+page.id+"</a>"
} else {
analysisContainerDiv.innerHTML = "<a href='"+page.url+"' target='_blank' rel='noopener noreferrer'>"+page.name+"</a>"
}
analysisContainerDiv.title = page.url;
analysisContainerDiv.id = page.id;
let datetimeP = document.createElement("p");
datetimeP.innerText = page.date.formatted;
analysisContainerDiv.appendChild(datetimeP);
// Close button
let closeButton = document.createElement("div");
closeButton.innerText = "X";
closeButton.classList.add("closeBtnDelete");
closeButton.addEventListener("click", () => {
analysisContainerDiv.parentElement.removeChild(analysisContainerDiv);
// Delete page from titles object
for (let i = 0; i < analysis.length; i++) {
if (analysis[i].id == page.id) {
console.log(analysis);
analysis.splice(i, 1);
console.log(analysis);
chrome.storage.local.set({ analysis: analysis }).then(() => {
console.log("analysis is set");
});
return
}
}
})
analysisContainerDiv.appendChild(closeButton);
return analysisContainerDiv;
}
function createPageDiv(page) {
let pageContainerDiv = document.createElement("div");
pageContainerDiv.classList.add("pageContainerDiv");
pageContainerDiv.innerHTML = "<a href='"+page.url+"' target='_blank' rel='noopener noreferrer'>"+page.title+"</a>"
pageContainerDiv.title = page.url;
pageContainerDiv.id = page.id;
let datetimeP = document.createElement("p");
const d = new Date(page.id)
//datetimeP.innerText = d;
datetimeP.innerText = d.toLocaleString('en-GB', { timeZone: 'UTC' });
pageContainerDiv.appendChild(datetimeP);
// Close button
let closeButton = document.createElement("div");
closeButton.innerText = "X";
closeButton.classList.add("closeBtnDelete");
closeButton.addEventListener("click", () => {
pageContainerDiv.parentElement.removeChild(pageContainerDiv);
// Delete page from titles object
for (let i = 0; i < titles.length; i++) {
if (titles[i].id == page.id) {
console.log(titles);
titles.splice(i, 1);
console.log(titles);
chrome.storage.local.set({ titles: titles }).then(() => {
console.log("titles is set");
});
return
}
}
})
pageContainerDiv.appendChild(closeButton);
return pageContainerDiv;
}
chrome.storage.local.get(['instances'], function(loadedInstances) {
instances = loadedInstances;
console.log("instances", instances);
})
// Load saved page titles
chrome.storage.local.get({
titles: []
}, function(stored) {
titles = stored.titles;
});
// Load saved analysis
chrome.storage.local.get({
analysis: []
}, function(stored) {
analysis = stored.analysis;
});
async function goToTrace() {
console.log("go to trace...", instances);
if (instances == undefined) {
return
}
/// Takes user to the given trace ID
let tab = await getTabID();
var sessionId = document.querySelector("#sessionId").value;
console.log("current tab:", tab, "\nsession id: ", sessionId);
let instancesLength = instances["instances"].length;
for (var i = 0; i < instancesLength; i ++) {
if (tab.includes(instances["instances"][i].url)) {
let namespacesLength = instances["instances"][i].namespaces.length;
for (var x = 0; x < namespacesLength; x ++) {
if ((tab.includes(instances["instances"][i].namespaces[x].namespace.toLowerCase())) || (tab.includes("NAMESPACE=" + instances["instances"][i].namespaces[x].namespace.toUpperCase()))){
let domain = tab.split("/")[2]
let protocol = tab.split("/")[0]
// Edit this URL as needed
let trace_url = protocol + "//" + domain + "/csp/healthshare/" + instances["instances"][i].namespaces[x].namespace + "/EnsPortal.VisualTrace.zen?SESSIONID=" + sessionId
chrome.tabs.update({
url: trace_url
});
break
}
}
}
}
}
function getTabID() {
return new Promise((resolve, reject) => {
try {
chrome.tabs.query({
active: true,
}, function (tabs) {
resolve(tabs[0].url);
})
} catch (e) {
reject(e);
}
})
}
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
/* Toggle between adding and removing the "active" class,
to highlight the button that controls the panel */
this.classList.toggle("active");
/* Toggle between hiding and showing the active panel */
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
this.nextElementSibling.children[1].focus();
}
});
}
document.getElementById("traceButton").addEventListener("click", function() {
console.log("Clicked traceButton");
goToTrace()
});