Update chrome.js

This commit is contained in:
Namhyeon Go 2021-08-17 00:04:26 +09:00 committed by GitHub
parent 93d3a4a8a0
commit 0f5feece79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -362,15 +362,13 @@ var ChromeObject = function() {
this.terminate = function() {
try {
this.oAutoIt.WinKill(this.getTitle());
this.oAutoIt.WinKill(this.title);
} catch (e) {
console.error("ChromeObject.terminate() ->", e.message);
}
};
this.focus = function() {
var title = "";
if (this.debuggingPort > 0) {
try {
// set page id
@ -381,27 +379,25 @@ var ChromeObject = function() {
// get current title
this.title = this.getTitle();
// will be change title
title = this.title + " " + this.pageId.substring(0, 6);
// new title
var _title = this.title + " " + this.pageId.substring(0, 6);
// change webpage title for focusing window
this.setTitle(title);
this.setTitle(_title);
// find window by title
var pageList = this.getPageList();
if (pageList.length > 0) {
this.oAutoIt.WinActivate(title);
this.oAutoIt.WinActivate(_title);
}
} catch (e) {
console.error("ChromeObject._focus() ->", e.message);
}
}
return title;
};
this.blur = function() {
return this.setTitle(this.title);
this.setTitle(this.title);
};
this.getScrollHeight = function(selector) {
@ -427,38 +423,28 @@ var ChromeObject = function() {
}
};
this.autoAdjustByScreen = function(sX, sY, divX, divY) {
// catch focus
var title = this.focus();
sleep(300);
this.autoAdjust = function(sX, sY) {
// get current title
var _title = this.getTitle();
// change webpage title
this.setTitle(this.pageId);
// adjust window position and size
var bX = Math.floor(sX / divX);
var bY = Math.floor(sY / divY);
var bX = Math.floor(sX / 6);
var bY = Math.floor(sY / 3);
var x = this.getRandomInt(0, bX);
var y = this.getRandomInt(0, bY);
var w = this.getRandomInt(bX * 3, sX - bX);
var h = this.getRandomInt(bY, sY - bY);
this.oAutoIt.WinMove(title, "", x, y, w, h);
this.oAutoIt.WinMove(this.pageId, "", x, y, w, h);
// release focus
this.blur();
// change webpage title to original
this.setTitle(_title);
};
this.autoAdjustByWindow = function(sX, sY, w1, w2, h1, h2) {
// catch focus
var title = this.focus();
sleep(300);
// adjust window position and size
var w = this.getRandomInt(w1, w2);
var h = this.getRandomInt(h1, h2);
var x = this.getRandomInt(0, (sX - w < 0 ? parseInt(sX * 0.2) : (sX - w)));
var y = this.getRandomInt(0, (sY - h < 0 ? parseInt(sY * 0.2) : (sY - h)));
this.oAutoIt.WinMove(title, "", x, y, w, h);
// release focus
this.blur();
this.blur = function() {
return this.evaluate("window.blur()");
};
this.downMouseWheel = function(times) {
@ -654,7 +640,11 @@ var ChromeObject = function() {
} else {
var p = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
var _selector = selector.substring(0, selector.indexOf(':'));
return this.evaluate('(function(obj, p) { var element = Object.values(obj).find(function() { return (Math.random() < p); }); if(element) element.click(); })(document.querySelectorAll("' + _selector + '"), ' + p + ')');
if (p > 0) {
return this.evaluate('(function(obj, p) { var element = Object.values(obj).find(function() { return (Math.random() < p); }); if(element) element.click(); })(document.querySelectorAll("' + _selector + '"), ' + p + ')');
} else {
return this.evaluate('(function(obj) { var elements = Object.values(obj); var element = elements[Math.floor(Math.random() * elements.length)]; if(element) element.click(); })(document.querySelectorAll("' + _selector + '"))');
}
}
};