Update chrome.js

This commit is contained in:
Namhyeon Go 2021-11-14 13:16:05 +09:00 committed by GitHub
parent cc36fffbd9
commit 1e95b79056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -266,7 +266,6 @@ var ChromeObject = function() {
try { try {
var responseText = HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json"); var responseText = HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json");
//console.info(responseText); //console.info(responseText);
console.log(responseText);
pageList = JSON.parse(responseText); pageList = JSON.parse(responseText);
this.pageList = pageList; this.pageList = pageList;
return pageList; return pageList;
@ -448,7 +447,7 @@ var ChromeObject = function() {
}; };
this.autoAdjustByScreen = function(sX, sY, divX, divY) { this.autoAdjustByScreen = function(sX, sY, divX, divY) {
// catch focus // focus
var title = this.focus(); var title = this.focus();
sleep(300); sleep(300);
@ -461,7 +460,7 @@ var ChromeObject = function() {
var h = this.getRandomInt(bY, sY - bY); var h = this.getRandomInt(bY, sY - bY);
this.oAutoIt.WinMove(title, "", x, y, w, h); this.oAutoIt.WinMove(title, "", x, y, w, h);
// release focus // blur
this.blur(); this.blur();
}; };
@ -477,14 +476,10 @@ var ChromeObject = function() {
var y = this.getRandomInt(0, (sY - h < 0 ? parseInt(sY * 0.2) : (sY - h))); var y = this.getRandomInt(0, (sY - h < 0 ? parseInt(sY * 0.2) : (sY - h)));
this.oAutoIt.WinMove(title, "", x, y, w, h); this.oAutoIt.WinMove(title, "", x, y, w, h);
// release focus // blur
this.blur(); this.blur();
}; };
this.blur = function() {
return this.evaluate("window.blur()");
};
this.downMouseWheel = function(times) { this.downMouseWheel = function(times) {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { try {
@ -536,7 +531,7 @@ var ChromeObject = function() {
}; };
this.getElementPosition = function(selector) { 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.right), parseInt(rect.bottom)].join(","); })();'); 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(','); var pos = result.split(',');
if (pos.length == 6) { if (pos.length == 6) {
return { return {
@ -544,8 +539,8 @@ var ChromeObject = function() {
"y": parseInt(pos[1]), "y": parseInt(pos[1]),
"a": parseInt(pos[2]), "a": parseInt(pos[2]),
"b": parseInt(pos[3]), "b": parseInt(pos[3]),
"g": parseInt(pos[4]), "w": parseInt(pos[4]),
"d": parseInt(pos[5]) "h": parseInt(pos[5])
}; };
} else { } else {
return { return {
@ -839,7 +834,8 @@ var ChromeObject = function() {
}; };
this.reload = function() { this.reload = function() {
return this.sendPageRPC("Page.reload", {}); //return this.sendPageRPC("Page.reload", {});
return this.evaluate("window.reload()");
}; };
this.hasClass = function(seletctor, className) { this.hasClass = function(seletctor, className) {
@ -863,21 +859,34 @@ var ChromeObject = function() {
this.oAutoIt.Send("{SPACE}"); this.oAutoIt.Send("{SPACE}");
}; };
this.setValue = function(selector, value, searchIndex) { this.setValue = function(selector, value, repeat, searchIndex) {
var searchIndex = (typeof searchIndex !== "undefined" ? searchIndex : 0); var s = encodeURIComponent(value),
var s = encodeURIComponent(value); i = 0,
searchIndex = (typeof searchIndex !== "undefined" ? searchIndex : 0)
;
while (i < repeat) {
if (searchIndex > 0) { if (searchIndex > 0) {
this.evaluate('Object.values(document.querySelectorAll("' + selector + '"))[' + searchIndex + '].value = decodeURIComponent("' + s + '");'); this.evaluate('Object.values(document.querySelectorAll("' + selector + '"))[' + searchIndex + '].value = decodeURIComponent("' + s + '");');
} else { } else {
this.evaluate('document.querySelector("' + selector + '").value = decodeURIComponent("' + s + '")'); this.evaluate('document.querySelector("' + selector + '").value = decodeURIComponent("' + s + '")');
} }
i++;
}
}; };
this.getText = function(selector) { this.getText = function(selector) {
return this.getEvaluatedValue('document.querySelector("' + selector + '").innerText'); return this.getEvaluatedValue('document.querySelector("' + selector + '").innerText');
}; };
this.traceMouseClick = function() {
return this.evaluate('window.addEventListener("click",function(e){var t=e.clientX,n=e.clientY,l=document.createElement("div");l.style.position="absolute",l.style.width="20px",l.style.height="20px",l.style.backgroundColor="#00ff00",l.style.zIndex=99999,l.style.top=window.pageYOffset+n-10+"px",l.style.left=window.pageXOffset+t-10+"px",document.body.appendChild(l)});');
};
this.getWindowInnerHeight = function() {
return this.getEvaluatedValue('window.innerHeight');
};
this.create(); this.create();
}; };