Update chrome.js

This commit is contained in:
Namhyeon Go 2021-07-30 06:10:20 +09:00 committed by GitHub
parent 59b1cb14ec
commit e38c2128a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,7 +115,7 @@ var ChromeObject = function() {
// disable default browser check
cmd.push("--no-default-browser-check");
// disable popop blocking
cmd.push("--disable-popup-blocking");
@ -400,16 +400,25 @@ var ChromeObject = function() {
}
};
this.arrange = function() {
// resolution: 1920x1080
// 화면 하단은 작업표시줄 또는 알림창이 떠있을 수 있음. 클릭 방지를 위해 높이(h) 값은 -200 으로 조정함.
var x = this.getRandomInt(0, 960);
var y = this.getRandomInt(0, 540);
var w = this.getRandomInt(960, 1920 - x);
var h = this.getRandomInt(540, 1080 - y - 200);
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 / 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(this.pageId, "", x, y, w, h);
// change webpage title to original
this.setTitle(_title);
};
this.blur = function() {
return this.evaluate("window.blur()");
@ -503,11 +512,24 @@ var ChromeObject = function() {
};
this.getCurrentDomain = function() {
return this.getEvaluatedValue('document.domain');
return this.getEvaluatedValue('document.domain') || '';
};
this.triggerEvent = function(eventName, selector) {
return this.evaluate('document.querySelector("' + selector + '").dispatchEvent(new Event("' + eventName + '"))');
if (selector.indexOf(':p(') < 0) {
if (eventName == 'click') {
return this.evaluate('document.querySelector("' + selector + '").click()');
} else {
return this.evaluate('document.querySelector("' + selector + '").dispatchEvent(new Event("' + eventName + '"))');
}
} else {
var probability = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
return this.evaluate('(function(obj, p) { var a = Array.from(obj).filter(function() { return (Math.random() < p); }); if(a.length > 0) a[0].click(); })(document.querySelectorAll("' + selector.substring(0, selector.indexOf(':')) + '"), ' + probability + ')');
}
};
this.scrollBySelector = function(selector, dx, dy) {
return this.evaluate('(function(rect, dx, dy) { window.scrollTo(rect.x + dx, rect.y + dy); })(document.querySelector("' + selector + '").getBoundingClientRect(), parseInt("' + (dx || 0) + '"), parseInt("' + (dy || 0) + '"))');
};
this.scrollBy = function(dx, dy) {