Update chrome.js

This commit is contained in:
Namhyeon Go 2022-01-26 03:46:17 +09:00 committed by GitHub
parent 22fa86f7ba
commit 6d4d224e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,10 +53,22 @@ var ChromeObject = function() {
this.isPreventEvaluate = false; this.isPreventEvaluate = false;
this.create = function() { this.create = function() {
try {
this.oAutoIt = AutoItX.create().getInterface(); this.oAutoIt = AutoItX.create().getInterface();
} catch (e) {
console.warn("AutoItX is disabled");
}
return this; return this;
}; };
this.callAutoIt = function(FN, args) {
if (this.oAutoIt != null) {
this.oAutoIt[FN].apply(args);
} else {
console.warn("AutoItX is disabled");
}
};
this.setIsPreventEvaluate = function(flag) { this.setIsPreventEvaluate = function(flag) {
this.isPreventEvaluate = flag; this.isPreventEvaluate = flag;
}; };
@ -505,7 +517,7 @@ var ChromeObject = function() {
this.terminate = function() { this.terminate = function() {
try { try {
this.oAutoIt.WinKill(this.getTitle()); this.callAutoIt("WinKill", [this.getTitle()]);
} catch (e) { } catch (e) {
console.error("ChromeObject.terminate() ->", e.message); console.error("ChromeObject.terminate() ->", e.message);
} }
@ -527,7 +539,7 @@ var ChromeObject = function() {
// 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.callAutoIt("WinActivate", [title]);
} }
} catch (e) { } catch (e) {
console.error("ChromeObject._focus() ->", e.message); console.error("ChromeObject._focus() ->", e.message);
@ -602,7 +614,7 @@ var ChromeObject = function() {
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.callAutoIt("WinMove", [title, "", x, y, w, h]);
// blur // blur
this.blur(); this.blur();
@ -618,7 +630,7 @@ var ChromeObject = function() {
var h = this.getRandomInt(h1, h2); var h = this.getRandomInt(h1, h2);
var x = this.getRandomInt(0, (sX - w < 0 ? parseInt(sX * 0.2) : (sX - w))); 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))); var y = this.getRandomInt(0, (sY - h < 0 ? parseInt(sY * 0.2) : (sY - h)));
this.oAutoIt.WinMove(title, "", x, y, w, h); this.callAutoIt("WinMove", [title, "", x, y, w, h]);
// blur // blur
this.blur(); this.blur();
@ -628,8 +640,8 @@ var ChromeObject = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { try {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
this.oAutoIt.MouseMove(pos.x + 100, pos.y + 100); this.callAutoIt("MouseMove" [pos.x + 100, pos.y + 100]);
this.oAutoIt.MouseWheel("down", times); this.callAutoIt("MouseWheel", ["down", times]);
} catch (e) { } catch (e) {
console.error("ChromeObject.downMouseWheel() ->", e.message); console.error("ChromeObject.downMouseWheel() ->", e.message);
} }
@ -640,8 +652,8 @@ var ChromeObject = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { try {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
this.oAutoIt.MouseMove(pos.x + 100, pos.y + 100); this.callAutoIt("MouseMove", [pos.x + 100, pos.y + 100]);
this.oAutoIt.MouseWheel("up", times); this.callAutoIt("MouseWheel", ["up", times]);
} catch (e) { } catch (e) {
console.error("ChromeObject.upMouseWheel() ->", e.message); console.error("ChromeObject.upMouseWheel() ->", e.message);
} }
@ -1068,7 +1080,7 @@ var ChromeObject = function() {
}; };
this.sendSpaceKey = function() { this.sendSpaceKey = function() {
this.oAutoIt.Send("{SPACE}"); this.callAutoIt("Send", ["{SPACE}"]);
}; };
this.setValue = function(selector, value, repeat, searchIndex) { this.setValue = function(selector, value, repeat, searchIndex) {
@ -1134,6 +1146,10 @@ var ChromeObject = function() {
return 'decodeURIComponent("' + encodeURIComponent(value) + '")'; return 'decodeURIComponent("' + encodeURIComponent(value) + '")';
}; };
this.prompt = function(s) {
return this.getEvaluatedValue('prompt("' + s + '")');
};
this.setVendor = function(vendor) { this.setVendor = function(vendor) {
var vendor = vendor.toLowerCase(); var vendor = vendor.toLowerCase();