-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignal.js
More file actions
73 lines (71 loc) · 2.02 KB
/
signal.js
File metadata and controls
73 lines (71 loc) · 2.02 KB
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
/**
* Signal is the simplified version of my HTML element discovery tool.
*
*
**/
const SignalHelperClass = class{
/**
* Serialize all the elements.
* The full version uses a unique serial hash combo.
* But no reason to do that in the frontend.
* @public
* @return {int}
**/
addSignal(){
let list_num = 0 ;
for ( const b of document.getElementsByTagName('body'))
for ( const i of b.querySelectorAll('*')) {
list_num ++ ;
i.setAttribute('signal_listNum', list_num);
};
return parseInt(list_num+1);
}
/**
* yeaah we let hem recognize we were here.
* Obviously not.
* @public
**/
removeSignal(){
for ( const i of document.querySelectorAll('*')) {
i.removeAttribute('signal_listNum');
}
};
getElement(signal){
return document.
querySelectorAll(
'[signal_listNum="'+signal.toString()+'"]'
)[0];
};
getChildSignals(signal){
let out = [];
const e = this.getElement(signal);
for ( const i of e.querySelectorAll('*')) {
out.push(i.getAttribute('signal_listNum'));
}
return out;
};
getAttributes(signal){
let out = {}
const e = this.getElement(signal)
for ( const a of e.attributes){
out[a.nodeName] = a.nodeValue;
}
return out;
};
getElementDetails(signal){
const e = this.getElement(signal);
return {
'nodeName' : e.nodeName,
'text' : e.innerText,
'attributes' : this.getAttributes(signal),
'childs' : this.getChildSignals(signal)
};
};
getAllElementsDetails(end){
let out = [];
for (let i = 1; end > i ; i++){
out.push(this.getElementDetails(i));
}
return out;
};
};