-
Notifications
You must be signed in to change notification settings - Fork 10
/
get_dom_URIs.js
94 lines (91 loc) · 2.39 KB
/
get_dom_URIs.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
javascript:
(
()=>
{
function downloadName()
{
var hostname = window.location.hostname.substring(0, window.location.hostname.lastIndexOf('.')).replaceAll(".", "_");
var pathname = window.location.pathname ? window.location.pathname.replaceAll('/', '_'): "_";
var filename = hostname + pathname + "_DOM_URIs.json";
return filename;
}
function download(text, name, type)
{
var a = document.createElement("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.click()
}
c = document.querySelectorAll('*');
a = {};
for (i=0;i<c.length;i++)
{
try {c[i].attributes["href"]} catch {continue}
if (c[i].attributes["href"] != null)
{
thelink = c[i].attributes["href"].baseURI;
if (c[i].attributes["href"].value.includes("//"))
{
thelink = c[i].attributes["href"].value;
}
else
{
if (c[i].attributes["href"].value.substring(0,1) == "/")
{
thelink += c[i].attributes["href"].value.substring(1);
}
else
{
thelink += c[i].attributes["href"].value;
}
}
if (c[i].tagName in a)
{
a[c[i].tagName].push([thelink,c[i].innerText]);
}
else
{
a[c[i].tagName] = [[thelink,c[i].innerText]];
}
}
if (c[i].attributes["src"] != null)
{
thelink = document.baseURI;
if (c[i].attributes["src"].value.includes("//"))
{
thelink = c[i].attributes["src"].value;
}
else
{
if (c[i].attributes["src"].value.substring(0,1) == "/")
{
thelink += c[i].attributes["src"].value.substring(1);
}
else
{
thelink += c[i].attributes["src"].value;
}
}
if (c[i].tagName in a)
{
a[c[i].tagName].push([thelink]);
}
else
{
a[c[i].tagName] = [[thelink]];
}
}
}
for (i in a)
{
a[i] = a[i].sort();
}
the_title = document.title;
the_place = window.location.href;
the_text = window.getSelection().toString();
the_time = Date().valueOf();
console.log("*** Test Stamp ***\n(Downloaded all URIs)\n" + "TIME: " + the_time + "\n" + "TITLE: " + the_title + "\n" + "URL: " + the_place + "\n" + "SELECTED TEXT: " + the_text + "\n" );
download(JSON.stringify(a, Object.keys(a).sort(),2),downloadName(),"application/json");
}
)();