This repository has been archived by the owner on May 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
process_page.js
52 lines (45 loc) · 1.78 KB
/
process_page.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
// Extract query parameters from the page URL itself
var pageUrl = new URL(document.documentURI);
function getParamList(url) {
var paramList = "";
var tempUrl = null;
try {
if (url[0] === "/") {
url = pageUrl.schema + "://" + pageUrl.host + url
}
tempUrl = new URL(url);
tempUrl.searchParams.forEach(function (value, key) {
paramList += `<li>${key}: ${value}</li>`
});
return paramList;
} catch (err) {
console.log('Error parsing URL: ' + url + "Error: " + err)
}
return "";
}
var queryParamsMessage = "";
var paramList = getParamList(document.documentURI);
if (paramList !== "") {
queryParamsMessage += `<tr><td>${document.documentURI}</td><td><ul>${paramList}</ul></td></tr>`;
}
// Find all links
// let as = document.getElementsByTagName('a');
var links = document.getElementsByTagName('a');
var linksMessage = "";
for (i = 0; i < links.length; i++) {
linksMessage += `<tr><td>${links[i].innerHTML}</td><td><span style="color: blue;">${links[i].getAttribute('href')}</span></td></tr>`
// Check for query params on URL
var paramList = getParamList(links[i].getAttribute('href'));
if (paramList !== "") {
queryParamsMessage += `<tr><td>${links[i].getAttribute('href')}</td><td><ul>${paramList}</ul></td></tr>`;
}
}
browser.runtime.sendMessage({html: linksMessage, type: "links"});
browser.runtime.sendMessage({html: queryParamsMessage, type: 'queryParams'});
// Find all scripts
var scripts = document.getElementsByTagName('script');
var scriptsHTML = "";
for (i = 0; i < scripts.length; i++) {
scriptsHTML += `<tr><td>Source: ${scripts[i].getAttribute('src')}</td><td>HTML: ${scripts[i].innerHTML}</td></tr>`
}
browser.runtime.sendMessage({html: scriptsHTML, type: "scripts"});