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