mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 20:21:03 +00:00
Update chrome.js
This commit is contained in:
parent
dfa76185df
commit
9efe02e902
|
@ -579,9 +579,9 @@ var ChromeObject = function() {
|
|||
var pos = -1;
|
||||
|
||||
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 {
|
||||
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(',');
|
||||
|
@ -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) {
|
||||
var s = '';
|
||||
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);'
|
||||
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
|
||||
+ ' if (elements.length > 0) {'
|
||||
+ ' var rect = elements[0].querySelector("' + subSelector + '").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(",");'
|
||||
+ ' var element = elements[0];'
|
||||
+ ' 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 {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -641,7 +681,7 @@ var ChromeObject = function() {
|
|||
+ ' 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), 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 {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -657,7 +697,7 @@ var ChromeObject = function() {
|
|||
+ ' 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), 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 {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -675,8 +715,11 @@ var ChromeObject = function() {
|
|||
+ ' return (text.indexOf(searchText) > -1);'
|
||||
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
|
||||
+ ' if (elements.length > 0) {'
|
||||
+ ' var rect = elements[0].querySelector("' + subSelector + '").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(",");'
|
||||
+ ' var element = elements[0];'
|
||||
+ ' 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 {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -948,7 +991,7 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getWindowInnerHeight = function() {
|
||||
return this.getEvaluatedValue('window.innerHeight');
|
||||
return parseInt(this.getEvaluatedValue('window.innerHeight'));
|
||||
};
|
||||
|
||||
// formula: y > 0 and y + h < ih
|
||||
|
|
Loading…
Reference in New Issue
Block a user