mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-16 14:41:03 +00:00
Update chrome.js
This commit is contained in:
parent
0f5feece79
commit
0cd8f24182
|
@ -362,13 +362,15 @@ var ChromeObject = function() {
|
||||||
|
|
||||||
this.terminate = function() {
|
this.terminate = function() {
|
||||||
try {
|
try {
|
||||||
this.oAutoIt.WinKill(this.title);
|
this.oAutoIt.WinKill(this.getTitle());
|
||||||
} 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
|
||||||
|
@ -379,25 +381,28 @@ var ChromeObject = function() {
|
||||||
// get current title
|
// get current title
|
||||||
this.title = this.getTitle();
|
this.title = this.getTitle();
|
||||||
|
|
||||||
// new title
|
// will be change title
|
||||||
var _title = this.title + " " + this.pageId.substring(0, 6);
|
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() {
|
||||||
this.setTitle(this.title);
|
return this.setTitle(this.title);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getScrollHeight = function(selector) {
|
this.getScrollHeight = function(selector) {
|
||||||
|
@ -423,24 +428,38 @@ var ChromeObject = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.autoAdjust = function(sX, sY) {
|
this.autoAdjustByScreen = function(sX, sY, divX, divY) {
|
||||||
// get current title
|
// catch focus
|
||||||
var _title = this.getTitle();
|
var title = this.focus();
|
||||||
|
sleep(300);
|
||||||
// change webpage title
|
|
||||||
this.setTitle(this.pageId);
|
|
||||||
|
|
||||||
// adjust window position and size
|
// adjust window position and size
|
||||||
var bX = Math.floor(sX / 6);
|
var bX = Math.floor(sX / divX);
|
||||||
var bY = Math.floor(sY / 3);
|
var bY = Math.floor(sY / divY);
|
||||||
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(this.pageId, "", x, y, w, h);
|
this.oAutoIt.WinMove(title, "", x, y, w, h);
|
||||||
|
|
||||||
// change webpage title to original
|
// release focus
|
||||||
this.setTitle(_title);
|
this.blur();
|
||||||
|
};
|
||||||
|
|
||||||
|
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() {
|
this.blur = function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user