Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
97 lines (89 loc) · 3.3 KB
/
Copy pathindex.html
File metadata and controls
97 lines (89 loc) · 3.3 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script>
function getXPath(node) {
var comp,
comps = []
var parent = null
var xpath = ''
var getPos = function (node) {
var position = 1,
curNode
if (node.nodeType == Node.ATTRIBUTE_NODE) {
return null
}
for (
curNode = node.previousSibling;
curNode;
curNode = curNode.previousSibling
) {
if (curNode.nodeName == node.nodeName) {
++position
}
}
return position
}
if (node instanceof Document) {
return '/'
}
for (
;
node && !(node instanceof Document);
node =
node.nodeType == Node.ATTRIBUTE_NODE
? node.ownerElement
: node.parentNode
) {
comp = comps[comps.length] = {}
switch (node.nodeType) {
case Node.TEXT_NODE:
comp.name = 'text()'
break
case Node.ATTRIBUTE_NODE:
comp.name = '@' + node.nodeName
break
case Node.PROCESSING_INSTRUCTION_NODE:
comp.name = 'processing-instruction()'
break
case Node.COMMENT_NODE:
comp.name = 'comment()'
break
case Node.ELEMENT_NODE:
comp.name = node.nodeName
break
}
comp.position = getPos(node)
}
for (var i = comps.length - 1; i >= 0; i--) {
comp = comps[i]
xpath += '/' + comp.name
if (comp.position != null) {
xpath += '[' + comp.position + ']'
}
}
return xpath
}
var arrayWithElements = new Array()
function clickListener(e) {
var clickedElement = e.target
arrayWithElements.push({
tag: clickedElement,
xPath: getXPath(clickedElement),
})
console.log('arrayWithElements ==>', arrayWithElements)
}
var copiedText = new Array()
const handleCopy = async e => {
console.log('copiedText ==>', e)
}
// document.onselectstart = handleCopy
document.onclick = clickListener
</script>
</head>
<body></body>
</html>