Skip to content

Commit 27c9dab

Browse files
authored
Den 451 Fix add d-id to dom (#90)
1 parent 224d522 commit 27c9dab

File tree

4 files changed

+136
-128
lines changed

4 files changed

+136
-128
lines changed

dendrite/async_api/_core/_js/generateDendriteIDs.js

+33-32
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
var hashCode = (string) => {
1+
var hashCode = (str) => {
22
var hash = 0, i, chr;
3-
if (string.length === 0) return hash;
4-
for (i = 0; i < string.length; i++) {
5-
chr = string.charCodeAt(i);
3+
if (str.length === 0) return hash;
4+
for (i = 0; i < str.length; i++) {
5+
chr = str.charCodeAt(i);
66
hash = ((hash << 5) - hash) + chr;
77
hash |= 0; // Convert to 32bit integer
88
}
99
return hash;
1010
}
1111

12-
var getXPathForElement = (element) => {
13-
const getElementIndex = (element) => {
14-
let index = 1;
15-
let sibling = element.previousElementSibling;
16-
17-
while (sibling) {
18-
if (sibling.localName === element.localName) {
19-
index++;
20-
}
21-
sibling = sibling.previousElementSibling;
12+
const getElementIndex = (element) => {
13+
let index = 1;
14+
let sibling = element.previousElementSibling;
15+
16+
while (sibling) {
17+
if (sibling.localName === element.localName) {
18+
index++;
2219
}
23-
24-
return index;
25-
};
20+
sibling = sibling.previousElementSibling;
21+
}
22+
23+
return index;
24+
};
2625

27-
const segs = elm => {
28-
if (!elm || elm.nodeType !== 1) return [''];
29-
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
30-
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
31-
let index = getElementIndex(elm);
32-
33-
return [...segs(elm.parentNode), `${localName}[${index}]`];
34-
};
26+
27+
const segs = function elmSegs(elm) {
28+
if (!elm || elm.nodeType !== 1) return [''];
29+
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
30+
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
31+
let index = getElementIndex(elm);
32+
33+
return [...elmSegs(elm.parentNode), `${localName}[${index}]`];
34+
};
35+
36+
var getXPathForElement = (element) => {
3537
return segs(element).join('/');
36-
}
38+
}
3739

3840
// Create a Map to store used hashes and their counters
3941
const usedHashes = new Map();
4042

43+
var markHidden = (hidden_element) => {
44+
// Mark the hidden element itself
45+
hidden
46+
}
47+
4148
document.querySelectorAll('*').forEach((element, index) => {
4249
try {
4350

4451
const xpath = getXPathForElement(element);
4552
const hash = hashCode(xpath);
4653
const baseId = hash.toString(36);
47-
48-
const markHidden = (hidden_element) => {
49-
// Mark the hidden element itself
50-
hidden_element.setAttribute('data-hidden', 'true');
51-
52-
}
5354

5455
// const is_marked_hidden = element.getAttribute("data-hidden") === "true";
5556
const isHidden = !element.checkVisibility();

dendrite/async_api/_core/_js/generateDendriteIDsIframe.js

+35-32
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
({frame_path}) => {
2-
var hashCode = (string) => {
2+
var hashCode = (str) => {
33
var hash = 0, i, chr;
4-
if (string.length === 0) return hash;
5-
for (i = 0; i < string.length; i++) {
6-
chr = string.charCodeAt(i);
4+
if (str.length === 0) return hash;
5+
for (i = 0; i < str.length; i++) {
6+
chr = str.charCodeAt(i);
77
hash = ((hash << 5) - hash) + chr;
88
hash |= 0; // Convert to 32bit integer
99
}
1010
return hash;
1111
}
1212

13-
var getXPathForElement = (element) => {
14-
const getElementIndex = (element) => {
15-
let index = 1;
16-
let sibling = element.previousElementSibling;
17-
18-
while (sibling) {
19-
if (sibling.localName === element.localName) {
20-
index++;
21-
}
22-
sibling = sibling.previousElementSibling;
13+
const getElementIndex = (element) => {
14+
let index = 1;
15+
let sibling = element.previousElementSibling;
16+
17+
while (sibling) {
18+
if (sibling.localName === element.localName) {
19+
index++;
2320
}
24-
25-
return index;
26-
};
21+
sibling = sibling.previousElementSibling;
22+
}
23+
24+
return index;
25+
};
2726

28-
const segs = elm => {
29-
if (!elm || elm.nodeType !== 1) return [''];
30-
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
31-
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
32-
let index = getElementIndex(elm);
33-
34-
return [...segs(elm.parentNode), `${localName}[${index}]`];
35-
};
36-
return segs(element).join('/');
37-
}
3827

28+
const segs = function elmSegs(elm) {
29+
if (!elm || elm.nodeType !== 1) return [''];
30+
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
31+
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
32+
let index = getElementIndex(elm);
33+
34+
return [...elmSegs(elm.parentNode), `${localName}[${index}]`];
35+
};
36+
37+
var getXPathForElement = (element) => {
38+
return segs(element).join('/');
39+
}
3940

4041
// Create a Map to store used hashes and their counters
4142
const usedHashes = new Map();
43+
44+
var markHidden = (hidden_element) => {
45+
// Mark the hidden element itself
46+
hidden_element.setAttribute('data-hidden', 'true');
47+
}
4248

4349
document.querySelectorAll('*').forEach((element, index) => {
4450
try {
45-
const markHidden = (hidden_element) => {
46-
// Mark the hidden element itself
47-
hidden_element.setAttribute('data-hidden', 'true');
48-
}
51+
4952

5053
// const is_marked_hidden = element.getAttribute("data-hidden") === "true";
5154
const isHidden = !element.checkVisibility();
@@ -57,7 +60,7 @@
5760
}else{
5861
element.removeAttribute("data-hidden") // in case we hid it in a previous call
5962
}
60-
const xpath = getXPathForElement(element);
63+
let xpath = getXPathForElement(element);
6164
if(frame_path){
6265
element.setAttribute("iframe-path",frame_path)
6366
xpath = frame_path + xpath;

dendrite/sync_api/_core/_js/generateDendriteIDs.js

+33-32
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
var hashCode = (string) => {
1+
var hashCode = (str) => {
22
var hash = 0, i, chr;
3-
if (string.length === 0) return hash;
4-
for (i = 0; i < string.length; i++) {
5-
chr = string.charCodeAt(i);
3+
if (str.length === 0) return hash;
4+
for (i = 0; i < str.length; i++) {
5+
chr = str.charCodeAt(i);
66
hash = ((hash << 5) - hash) + chr;
77
hash |= 0; // Convert to 32bit integer
88
}
99
return hash;
1010
}
1111

12-
var getXPathForElement = (element) => {
13-
const getElementIndex = (element) => {
14-
let index = 1;
15-
let sibling = element.previousElementSibling;
16-
17-
while (sibling) {
18-
if (sibling.localName === element.localName) {
19-
index++;
20-
}
21-
sibling = sibling.previousElementSibling;
12+
const getElementIndex = (element) => {
13+
let index = 1;
14+
let sibling = element.previousElementSibling;
15+
16+
while (sibling) {
17+
if (sibling.localName === element.localName) {
18+
index++;
2219
}
23-
24-
return index;
25-
};
20+
sibling = sibling.previousElementSibling;
21+
}
22+
23+
return index;
24+
};
2625

27-
const segs = elm => {
28-
if (!elm || elm.nodeType !== 1) return [''];
29-
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
30-
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
31-
let index = getElementIndex(elm);
32-
33-
return [...segs(elm.parentNode), `${localName}[${index}]`];
34-
};
26+
27+
const segs = function elmSegs(elm) {
28+
if (!elm || elm.nodeType !== 1) return [''];
29+
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
30+
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
31+
let index = getElementIndex(elm);
32+
33+
return [...elmSegs(elm.parentNode), `${localName}[${index}]`];
34+
};
35+
36+
var getXPathForElement = (element) => {
3537
return segs(element).join('/');
36-
}
38+
}
3739

3840
// Create a Map to store used hashes and their counters
3941
const usedHashes = new Map();
4042

43+
var markHidden = (hidden_element) => {
44+
// Mark the hidden element itself
45+
hidden
46+
}
47+
4148
document.querySelectorAll('*').forEach((element, index) => {
4249
try {
4350

4451
const xpath = getXPathForElement(element);
4552
const hash = hashCode(xpath);
4653
const baseId = hash.toString(36);
47-
48-
const markHidden = (hidden_element) => {
49-
// Mark the hidden element itself
50-
hidden_element.setAttribute('data-hidden', 'true');
51-
52-
}
5354

5455
// const is_marked_hidden = element.getAttribute("data-hidden") === "true";
5556
const isHidden = !element.checkVisibility();

dendrite/sync_api/_core/_js/generateDendriteIDsIframe.js

+35-32
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
({frame_path}) => {
2-
var hashCode = (string) => {
2+
var hashCode = (str) => {
33
var hash = 0, i, chr;
4-
if (string.length === 0) return hash;
5-
for (i = 0; i < string.length; i++) {
6-
chr = string.charCodeAt(i);
4+
if (str.length === 0) return hash;
5+
for (i = 0; i < str.length; i++) {
6+
chr = str.charCodeAt(i);
77
hash = ((hash << 5) - hash) + chr;
88
hash |= 0; // Convert to 32bit integer
99
}
1010
return hash;
1111
}
1212

13-
var getXPathForElement = (element) => {
14-
const getElementIndex = (element) => {
15-
let index = 1;
16-
let sibling = element.previousElementSibling;
17-
18-
while (sibling) {
19-
if (sibling.localName === element.localName) {
20-
index++;
21-
}
22-
sibling = sibling.previousElementSibling;
13+
const getElementIndex = (element) => {
14+
let index = 1;
15+
let sibling = element.previousElementSibling;
16+
17+
while (sibling) {
18+
if (sibling.localName === element.localName) {
19+
index++;
2320
}
24-
25-
return index;
26-
};
21+
sibling = sibling.previousElementSibling;
22+
}
23+
24+
return index;
25+
};
2726

28-
const segs = elm => {
29-
if (!elm || elm.nodeType !== 1) return [''];
30-
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
31-
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
32-
let index = getElementIndex(elm);
33-
34-
return [...segs(elm.parentNode), `${localName}[${index}]`];
35-
};
36-
return segs(element).join('/');
37-
}
3827

28+
const segs = function elmSegs(elm) {
29+
if (!elm || elm.nodeType !== 1) return [''];
30+
if (elm.id && document.getElementById(elm.id) === elm) return [`id("${elm.id}")`];
31+
const localName = typeof elm.localName === 'string' ? elm.localName.toLowerCase() : 'unknown';
32+
let index = getElementIndex(elm);
33+
34+
return [...elmSegs(elm.parentNode), `${localName}[${index}]`];
35+
};
36+
37+
var getXPathForElement = (element) => {
38+
return segs(element).join('/');
39+
}
3940

4041
// Create a Map to store used hashes and their counters
4142
const usedHashes = new Map();
43+
44+
var markHidden = (hidden_element) => {
45+
// Mark the hidden element itself
46+
hidden_element.setAttribute('data-hidden', 'true');
47+
}
4248

4349
document.querySelectorAll('*').forEach((element, index) => {
4450
try {
45-
const markHidden = (hidden_element) => {
46-
// Mark the hidden element itself
47-
hidden_element.setAttribute('data-hidden', 'true');
48-
}
51+
4952

5053
// const is_marked_hidden = element.getAttribute("data-hidden") === "true";
5154
const isHidden = !element.checkVisibility();
@@ -57,7 +60,7 @@
5760
}else{
5861
element.removeAttribute("data-hidden") // in case we hid it in a previous call
5962
}
60-
const xpath = getXPathForElement(element);
63+
let xpath = getXPathForElement(element);
6164
if(frame_path){
6265
element.setAttribute("iframe-path",frame_path)
6366
xpath = frame_path + xpath;

0 commit comments

Comments
 (0)