mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 23:41:42 +00:00
Update chrome.js
This commit is contained in:
parent
410d77ccdd
commit
dfa76185df
|
@ -324,9 +324,9 @@ var ChromeObject = function() {
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getParameterValue = function(paramName) {
|
this.getParameterValue = function(paramName, defaultValue) {
|
||||||
var paramValue;
|
var paramValue = defaultValue;
|
||||||
var page = this.getPageById(this.pageId);
|
var page = this.getPageById(this.pageId);
|
||||||
var params = page.url.split('&');
|
var params = page.url.split('&');
|
||||||
|
|
||||||
|
@ -573,9 +573,18 @@ var ChromeObject = function() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getElementPosition = function(selector) {
|
this.getElementPosition = function(selector, startIndex) {
|
||||||
var result = this.getEvaluatedValue('(function() { var rect = document.querySelector("' + selector + '").getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(rect.x), parseInt(rect.y), parseInt(rect.width), parseInt(rect.height)].join(","); })();');
|
var startIndex = (typeof startIndex !== 'undefined' ? startIndex : 0);
|
||||||
var pos = result.split(',');
|
var result;
|
||||||
|
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 + ');');
|
||||||
|
} 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(","); })();');
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = result.split(',');
|
||||||
if (pos.length == 6) {
|
if (pos.length == 6) {
|
||||||
return {
|
return {
|
||||||
"x": parseInt(pos[0]),
|
"x": parseInt(pos[0]),
|
||||||
|
@ -600,26 +609,27 @@ var ChromeObject = function() {
|
||||||
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);
|
||||||
var isSelfSelector = (subSelector == ":self");
|
|
||||||
|
|
||||||
if (searchText.indexOf(':tokenize(') == 0) {
|
if (searchText.indexOf(':tokenize(') == 0) {
|
||||||
searchText = searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')'));
|
searchText = searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')'));
|
||||||
s += '(function() {'
|
s += '(function() {'
|
||||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||||
+ ' var el = x' + (!isSelfSelector ? '' : '.querySelector("' + subSelector + '")') + ';'
|
+ ' var el = x.querySelector("' + subSelector + '");'
|
||||||
+ ' var keywords = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim().split(" ");'
|
+ ' var keywords = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim().split(" ");'
|
||||||
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
||||||
+ ' 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]' + (!isSelfSelector ? '' : '.querySelector("' + subSelector + '")') + '.getBoundingClientRect();'
|
+ ' 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(",");'
|
+ ' return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), ""].join(",");'
|
||||||
+ ' } else {'
|
+ ' } else {'
|
||||||
+ ' return "";'
|
+ ' return "";'
|
||||||
+ ' }'
|
+ ' }'
|
||||||
+ '})()'
|
+ '})()'
|
||||||
;
|
;
|
||||||
} else if (searchText.indexOf(':p(') == 0) {
|
}
|
||||||
|
|
||||||
|
else if (searchText.indexOf(':p(') == 0) {
|
||||||
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')')));
|
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')')));
|
||||||
if (p > 0) {
|
if (p > 0) {
|
||||||
s += '(function() {'
|
s += '(function() {'
|
||||||
|
@ -627,8 +637,11 @@ var ChromeObject = function() {
|
||||||
+ ' return (Math.random() < ' + p + ');'
|
+ ' return (Math.random() < ' + p + ');'
|
||||||
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
|
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
|
||||||
+ ' if (elements.length > 0) {'
|
+ ' if (elements.length > 0) {'
|
||||||
+ ' var rect = elements[0].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), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||||
+ ' } else {'
|
+ ' } else {'
|
||||||
+ ' return "";'
|
+ ' return "";'
|
||||||
+ ' }'
|
+ ' }'
|
||||||
|
@ -640,25 +653,30 @@ var ChromeObject = function() {
|
||||||
+ ' ' + (startIndex > 0 ? 'elements = elements.slice(' + startIndex + ');' : '')
|
+ ' ' + (startIndex > 0 ? 'elements = elements.slice(' + startIndex + ');' : '')
|
||||||
+ ' if (elements.length > 0) {'
|
+ ' if (elements.length > 0) {'
|
||||||
+ ' var k = Math.floor(Math.random() * elements.length);'
|
+ ' var k = Math.floor(Math.random() * elements.length);'
|
||||||
+ ' var rect = elements[k].getBoundingClientRect();'
|
+ ' var element = elements[k];'
|
||||||
+ ' 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), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||||
+ ' } else {'
|
+ ' } else {'
|
||||||
+ ' return "";'
|
+ ' return "";'
|
||||||
+ ' }'
|
+ ' }'
|
||||||
+ '})()'
|
+ '})()'
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
s += '(function() {'
|
s += '(function() {'
|
||||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||||
+ ' var el = x' + (!isSelfSelector ? '' : '.querySelector("' + subSelector + '")') + ';'
|
+ ' var el = x.querySelector("' + subSelector + '");'
|
||||||
+ ' var searchText = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim();'
|
+ ' var searchText = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim();'
|
||||||
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
||||||
+ ' 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]' + (!isSelfSelector ? '' : '.querySelector("' + subSelector + '")') + '.getBoundingClientRect();'
|
+ ' 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(",");'
|
+ ' return [parseInt(rect.left), parseInt(rect.top), window.pageXOffset + parseInt(rect.left), window.pageYOffset + parseInt(rect.top), parseInt(rect.width), parseInt(rect.height), ""].join(",");'
|
||||||
+ ' } else {'
|
+ ' } else {'
|
||||||
+ ' return "";'
|
+ ' return "";'
|
||||||
+ ' }'
|
+ ' }'
|
||||||
|
@ -668,14 +686,15 @@ var ChromeObject = function() {
|
||||||
|
|
||||||
var result = this.getEvaluatedValue(s);
|
var result = this.getEvaluatedValue(s);
|
||||||
var pos = result.split(',');
|
var pos = result.split(',');
|
||||||
if (pos.length == 6) {
|
if (pos.length == 7) {
|
||||||
return {
|
return {
|
||||||
"x": parseInt(pos[0]),
|
"x": parseInt(pos[0]),
|
||||||
"y": parseInt(pos[1]),
|
"y": parseInt(pos[1]),
|
||||||
"a": parseInt(pos[2]),
|
"a": parseInt(pos[2]),
|
||||||
"b": parseInt(pos[3]),
|
"b": parseInt(pos[3]),
|
||||||
"w": parseInt(pos[4]),
|
"w": parseInt(pos[4]),
|
||||||
"h": parseInt(pos[5])
|
"h": parseInt(pos[5]),
|
||||||
|
"s": pos[6]
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
@ -684,11 +703,12 @@ var ChromeObject = function() {
|
||||||
"a": -1,
|
"a": -1,
|
||||||
"b": -1,
|
"b": -1,
|
||||||
"w": -1,
|
"w": -1,
|
||||||
"h": -1
|
"h": -1,
|
||||||
|
"s": ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.triggerEventOnNestedElement = function(eventName, selector, subSelector, searchText, startIndex) {
|
this.triggerEventOnNestedElement = function(eventName, selector, subSelector, searchText, startIndex) {
|
||||||
var s = '';
|
var s = '';
|
||||||
var startIndex = (typeof startIndex !== 'undefined' ? startIndex : 0);
|
var startIndex = (typeof startIndex !== 'undefined' ? startIndex : 0);
|
||||||
|
@ -933,7 +953,7 @@ var ChromeObject = function() {
|
||||||
|
|
||||||
// formula: y > 0 and y + h < ih
|
// formula: y > 0 and y + h < ih
|
||||||
this.isVisibleElementInViewport = function(elementPosition) {
|
this.isVisibleElementInViewport = function(elementPosition) {
|
||||||
return (elementPosition.y > 0 && (elementPosition.y + elementPosition.h < this.getWindowInnerHeight());
|
return (elementPosition.y > 0 && (elementPosition.y + elementPosition.h < this.getWindowInnerHeight()));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.create();
|
this.create();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user