From 5254f16b3f0f6cf2e03dcabed2d1aae0d4fe56cb Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Thu, 3 Mar 2022 15:11:39 +0900 Subject: [PATCH] Update toolkit.js --- lib/toolkit.js | 85 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/lib/toolkit.js b/lib/toolkit.js index 0cc2053..ba88c28 100644 --- a/lib/toolkit.js +++ b/lib/toolkit.js @@ -15,43 +15,62 @@ var ToolkitObject = function() { } }; - this.getInterface = function() { - return this.interface; + this.checkIsEnabled = function() { + return (this.interface != null); }; + this.sendClick = function(wName, x, y, retry) { + if (!this.checkIsEnabled()) + return; + + var i = 0; + while (i < retry) { + this.interface.SendClick(wName, x, y); + i++; + } + }; + + this.sendKey = function(wName, s) { + if (!this.checkIsEnabled()) + return; + + return this.interface.SendKeys(wName, s); + }; + + // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html + + this.alert = function(message) { + if (!this.checkIsEnabled()) + return; + + return this.interface.Alert(message); + }; + + this.confirm = function(message) { + if (!this.checkIsEnabled()) + return; + + return this.interface.Confirm(message); + }; + + this.prompt = function(message, _default) { + if (!this.checkIsEnabled()) + return; + + return this.interface.Prompt(message, _default); + }; + this.create(); }; -exports.create = function() { - return new ToolkitObject(); -}; +var instance = new ToolkitObject(); -exports.getInterface = function() { - return exports.create().getInterface(); -}; +exports.sendClick = instance.sendClick; +exports.sendKeys = instance.sendKeys; +exports.alert = instance.alert; +exports.confirm = instance.confirm; +exports.prompt = instance.prompt; -exports.sendClick = function(wName, x, y, retry) { - var i = 0; - while (i < retry) { - exports.getInterface().SendClick(wName, x, y); - i++; - } -}; - -exports.sendKeys = function(wName, s) { - return exports.getInterface().SendKeys(wName, s); -}; - -// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html - -exports.alert = function(message) { - return exports.getInterface().Alert(message); -}; - -exports.confirm = function(message) { - return exports.getInterface().Confirm(message); -}; - -exports.prompt = function(message, _default) { - return exports.getInterface().Prompt(message, _default); -}; \ No newline at end of file +exports.VERSIONINFO = "WelsonJS Toolkit (toolkit.js) version 0.2"; +exports.global = global; +exports.require = global.require;