Update chrome.js

This commit is contained in:
Namhyeon Go 2021-12-04 02:17:01 +09:00 committed by GitHub
parent dfa76185df
commit 9efe02e902
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -579,9 +579,9 @@ var ChromeObject = function() {
var pos = -1; var pos = -1;
if (startIndex > 0) { if (startIndex > 0) {
result = this.getEvaluatedValue('(function(k) { var rect = document.querySelectorAll("' + selector + '")[k].getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })(' + startIndex + ');'); result = this.getEvaluatedValue('(function(k) { var rect = document.querySelectorAll("' + selector + '")[k].getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })(' + startIndex + ');');
} else { } else {
result = this.getEvaluatedValue('(function() { var rect = document.querySelector("' + selector + '").getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();'); result = this.getEvaluatedValue('(function() { var rect = document.querySelector("' + selector + '").getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();');
} }
pos = result.split(','); pos = result.split(',');
@ -606,6 +606,43 @@ var ChromeObject = function() {
} }
}; };
this.getElementPositionByText = function(selector, searchText) {
var result;
var pos = -1;
var s = '(function() {'
+ ' var element = Object.values(document.querySelectorAll("' + selector + '")).find(function(x) {'
+ ' return (x.innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
+ ' });'
+ ' if (element) {'
+ ' var rect = element.getBoundingClientRect();'
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(",");'
+ ' }'
+ '})()'
;
result = this.getEvaluatedValue(s);
pos = result.split(',');
if (pos.length == 6) {
return {
"x": parseInt(pos[0]),
"y": parseInt(pos[1]),
"a": parseInt(pos[2]),
"b": parseInt(pos[3]),
"w": parseInt(pos[4]),
"h": parseInt(pos[5])
};
} else {
return {
"x": -1,
"y": -1,
"a": -1,
"b": -1,
"g": -1,
"d": -1
};
}
};
this.getNestedElementPosition = function(selector, subSelector, searchText, startIndex) { this.getNestedElementPosition = function(selector, subSelector, searchText, startIndex) {
var s = ''; var s = '';
var startIndex = (typeof startIndex !== 'undefined' ? startIndex : 0); var startIndex = (typeof startIndex !== 'undefined' ? startIndex : 0);
@ -620,8 +657,11 @@ var ChromeObject = function() {
+ ' return (text.split(" ").filter(function(w) { return keywords.indexOf(w) > -1; }).length >= keywords.length);' + ' return (text.split(" ").filter(function(w) { return keywords.indexOf(w) > -1; }).length >= keywords.length);'
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});') + ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
+ ' if (elements.length > 0) {' + ' if (elements.length > 0) {'
+ ' var rect = elements[0].querySelector("' + subSelector + '").getBoundingClientRect();' + ' var element = elements[0];'
+ ' return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), ""].join(",");' + ' var rect = element.getBoundingClientRect();'
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
+ ' } else {' + ' } else {'
+ ' return "";' + ' return "";'
+ ' }' + ' }'
@ -641,7 +681,7 @@ var ChromeObject = function() {
+ ' var rect = element.getBoundingClientRect();' + ' var rect = element.getBoundingClientRect();'
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);' + ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);' + ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
+ ' return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");' + ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
+ ' } else {' + ' } else {'
+ ' return "";' + ' return "";'
+ ' }' + ' }'
@ -657,7 +697,7 @@ var ChromeObject = function() {
+ ' var rect = element.getBoundingClientRect();' + ' var rect = element.getBoundingClientRect();'
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);' + ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);' + ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
+ ' return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");' + ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
+ ' } else {' + ' } else {'
+ ' return "";' + ' return "";'
+ ' }' + ' }'
@ -675,8 +715,11 @@ var ChromeObject = function() {
+ ' return (text.indexOf(searchText) > -1);' + ' return (text.indexOf(searchText) > -1);'
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});') + ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
+ ' if (elements.length > 0) {' + ' if (elements.length > 0) {'
+ ' var rect = elements[0].querySelector("' + subSelector + '").getBoundingClientRect();' + ' var element = elements[0];'
+ ' return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), ""].join(",");' + ' var rect = element.getBoundingClientRect();'
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
+ ' } else {' + ' } else {'
+ ' return "";' + ' return "";'
+ ' }' + ' }'
@ -948,7 +991,7 @@ var ChromeObject = function() {
}; };
this.getWindowInnerHeight = function() { this.getWindowInnerHeight = function() {
return this.getEvaluatedValue('window.innerHeight'); return parseInt(this.getEvaluatedValue('window.innerHeight'));
}; };
// formula: y > 0 and y + h < ih // formula: y > 0 and y + h < ih