forked from satisfice/web-testing-bookmarklets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_dom_by_classes.js
54 lines (53 loc) · 1.5 KB
/
get_dom_by_classes.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
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_ByClasses.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()
}
dom = document.querySelectorAll('*[class]');
const dict = {};
for (i=0;i<dom.length;i++)
{
if (!(dom[i].className in dict))
{
dict[dom[i].className] = [];
}
dict[dom[i].className].push(dom[i].outerHTML);
}
const out = {};
for (i of Object.keys(dict).sort())
{
if (!(i in out))
{
out[i] = [];
}
for (v of dict[i].sort())
{
out[i].push(v);
}
}
for (i in out)
{
out[i] = out[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 DOM by classes)\n" + "TIME: " + the_time + "\n" + "TITLE: " + the_title + "\n" + "URL: " + the_place + "\n" + "SELECTED TEXT: " + the_text + "\n" );
download(JSON.stringify(out, Object.keys(out).sort(),2),downloadName(),"application/json");
}
)();