welsonjs/lib/toolkit.js

102 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-12-20 08:58:42 +00:00
// toolkit.js
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs
2021-08-10 11:39:27 +00:00
2023-12-20 08:58:42 +00:00
function ToolkitObject() {
2021-08-10 11:39:27 +00:00
this.interface = null;
this.create = function() {
try {
this.interface = CreateObject("WelsonJS.Toolkit");
} catch (e) {
2023-12-20 08:01:24 +00:00
console.info("WelsonJS.Toolkit not installed");
console.info("It could be download from https://github.com/gnh1201/welsonjs");
console.error(e.message);
2021-08-10 11:39:27 +00:00
}
2023-12-20 08:58:42 +00:00
return this;
2021-08-10 11:39:27 +00:00
};
2022-02-14 07:03:55 +00:00
2022-03-03 07:16:08 +00:00
this.getInterface = function() {
return this.interface;
2022-02-14 06:43:14 +00:00
};
2023-12-20 08:58:42 +00:00
2022-03-03 07:16:08 +00:00
this.create();
};
2022-02-14 07:03:55 +00:00
2022-10-20 19:03:06 +00:00
function create() {
2022-03-03 07:16:08 +00:00
return new ToolkitObject();
2022-10-20 19:03:06 +00:00
}
2022-02-14 07:03:55 +00:00
2022-10-20 19:03:06 +00:00
function getInterface() {
return create().getInterface();
}
2022-02-14 07:03:55 +00:00
2022-10-20 19:03:06 +00:00
function sendClick(wName, x, y, retry) {
2022-03-03 07:16:08 +00:00
var i = 0;
while (i < retry) {
2022-10-20 19:03:06 +00:00
getInterface().SendClick(wName, x, y);
2022-03-03 07:16:08 +00:00
i++;
}
2022-10-20 19:03:06 +00:00
}
2022-02-14 07:03:55 +00:00
2022-10-20 19:03:06 +00:00
function sendKeys(wName, s) {
return getInterface().SendKeys(wName, s);
}
function sendFnKey(wName, num) {
return getInterface().SendFnKey(wName, num);
}
2022-02-14 07:03:55 +00:00
2023-12-20 08:58:42 +00:00
// [lib/toolkit] Implementation of User prompts (alert, confirm. prompt) #21
2022-03-03 07:16:08 +00:00
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html
2022-10-20 19:03:06 +00:00
function alert(message) {
return getInterface().Alert(message);
}
2022-02-14 07:03:55 +00:00
2022-10-20 19:03:06 +00:00
function confirm(message) {
return getInterface().Confirm(message);
}
2022-03-03 06:11:39 +00:00
2022-10-20 19:03:06 +00:00
function prompt(message, _default) {
return getInterface().Prompt(message, _default);
}
2023-12-20 08:58:42 +00:00
// [Toolkit] Access to a shared memory #96
function NamedSharedMemory(name) {
var Toolkit = create().getInterface();
this.name = name;
this.isInitialized = false;
this.open = function() {
this.isInitialized = Toolkit.OpenNamedSharedMemory(this.name);
};
this.readText = function() {
return Toolkit.ReadTextFromSharedMemory(this.name);
};
this.writeText = function(text) {
Toolkit.WriteTextToSharedMemory(this.name, text);
};
this.clear = function() {
Toolkit.ClearSharedMemory(this.name);
};
}
2022-10-20 19:03:06 +00:00
exports.create = create;
exports.getInterface = getInterface;
exports.sendClick = sendClick;
exports.sendKeys = sendKeys;
exports.sendFnKey = sendFnKey;
exports.alert = alert;
exports.confirm = confirm;
exports.prompt = prompt;
2023-12-20 08:58:42 +00:00
exports.NamedSharedMemory = NamedSharedMemory;
2022-10-20 19:03:06 +00:00
2023-12-20 08:58:42 +00:00
exports.VERSIONINFO = "WelsonJS.Toolkit Native API version 0.3.2";
2022-11-25 14:11:37 +00:00
exports.AUTHOR = "abuse@catswords.net";
2022-10-20 19:03:06 +00:00
exports.global = global;
exports.require = global.require;