-
Notifications
You must be signed in to change notification settings - Fork 10
/
get_dom_ids.js
54 lines (53 loc) · 1.49 KB
/
get_dom_ids.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_IDs.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('*[id]');
const dict = {};
for (i=0;i<dom.length;i++)
{
if (!(dom[i].tagName in dict))
{
dict[dom[i].tagName] = {};
}
try
{
dict[dom[i].tagName][dom[i].attributes['id'].value] = 0;
}
catch {}
}
const out = {};
for (i of Object.keys(dict).sort())
{
if (!(i in out))
{
out[i] = [];
}
for (v of Object.keys(dict[i]).sort())
{
out[i].push(v);
}
}
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 showing IDs)\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");
}
)();