mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-09 21:26:04 +00:00
Update chrome.js
This commit is contained in:
parent
93d3a4a8a0
commit
0f5feece79
|
@ -362,15 +362,13 @@ var ChromeObject = function() {
|
||||||
|
|
||||||
this.terminate = function() {
|
this.terminate = function() {
|
||||||
try {
|
try {
|
||||||
this.oAutoIt.WinKill(this.getTitle());
|
this.oAutoIt.WinKill(this.title);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("ChromeObject.terminate() ->", e.message);
|
console.error("ChromeObject.terminate() ->", e.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.focus = function() {
|
this.focus = function() {
|
||||||
var title = "";
|
|
||||||
|
|
||||||
if (this.debuggingPort > 0) {
|
if (this.debuggingPort > 0) {
|
||||||
try {
|
try {
|
||||||
// set page id
|
// set page id
|
||||||
|
@ -381,27 +379,25 @@ var ChromeObject = function() {
|
||||||
// get current title
|
// get current title
|
||||||
this.title = this.getTitle();
|
this.title = this.getTitle();
|
||||||
|
|
||||||
// will be change title
|
// new title
|
||||||
title = this.title + " " + this.pageId.substring(0, 6);
|
var _title = this.title + " " + this.pageId.substring(0, 6);
|
||||||
|
|
||||||
// change webpage title for focusing window
|
// change webpage title for focusing window
|
||||||
this.setTitle(title);
|
this.setTitle(_title);
|
||||||
|
|
||||||
// find window by title
|
// find window by title
|
||||||
var pageList = this.getPageList();
|
var pageList = this.getPageList();
|
||||||
if (pageList.length > 0) {
|
if (pageList.length > 0) {
|
||||||
this.oAutoIt.WinActivate(title);
|
this.oAutoIt.WinActivate(_title);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("ChromeObject._focus() ->", e.message);
|
console.error("ChromeObject._focus() ->", e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return title;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.blur = function() {
|
this.blur = function() {
|
||||||
return this.setTitle(this.title);
|
this.setTitle(this.title);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getScrollHeight = function(selector) {
|
this.getScrollHeight = function(selector) {
|
||||||
|
@ -427,38 +423,28 @@ var ChromeObject = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.autoAdjustByScreen = function(sX, sY, divX, divY) {
|
this.autoAdjust = function(sX, sY) {
|
||||||
// catch focus
|
// get current title
|
||||||
var title = this.focus();
|
var _title = this.getTitle();
|
||||||
sleep(300);
|
|
||||||
|
// change webpage title
|
||||||
|
this.setTitle(this.pageId);
|
||||||
|
|
||||||
// adjust window position and size
|
// adjust window position and size
|
||||||
var bX = Math.floor(sX / divX);
|
var bX = Math.floor(sX / 6);
|
||||||
var bY = Math.floor(sY / divY);
|
var bY = Math.floor(sY / 3);
|
||||||
var x = this.getRandomInt(0, bX);
|
var x = this.getRandomInt(0, bX);
|
||||||
var y = this.getRandomInt(0, bY);
|
var y = this.getRandomInt(0, bY);
|
||||||
var w = this.getRandomInt(bX * 3, sX - bX);
|
var w = this.getRandomInt(bX * 3, sX - bX);
|
||||||
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(this.pageId, "", x, y, w, h);
|
||||||
|
|
||||||
// release focus
|
// change webpage title to original
|
||||||
this.blur();
|
this.setTitle(_title);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.autoAdjustByWindow = function(sX, sY, w1, w2, h1, h2) {
|
this.blur = function() {
|
||||||
// catch focus
|
return this.evaluate("window.blur()");
|
||||||
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.downMouseWheel = function(times) {
|
this.downMouseWheel = function(times) {
|
||||||
|
@ -654,7 +640,11 @@ var ChromeObject = function() {
|
||||||
} else {
|
} else {
|
||||||
var p = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
|
var p = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
|
||||||
var _selector = selector.substring(0, 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 + '"))');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user