welsonjs/lib/toolkit.js

121 lines
3.1 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) {
2023-12-29 06:03:02 +00:00
var _interface = create().getInterface();
2023-12-20 08:58:42 +00:00
this.name = name;
2023-12-29 06:03:02 +00:00
this.writeText = function(text) {
return _interface.WriteTextToSharedMemory(this.name, text);
2023-12-20 08:58:42 +00:00
};
2023-12-29 06:03:02 +00:00
2023-12-20 08:58:42 +00:00
this.readText = function() {
2023-12-29 06:03:02 +00:00
return _interface.ReadTextFromSharedMemory(this.name);
2023-12-20 08:58:42 +00:00
};
this.clear = function() {
2023-12-29 06:03:02 +00:00
return _interface.ClearSharedMemory(this.name);
2023-12-20 08:58:42 +00:00
};
2024-01-04 06:23:26 +00:00
this.close = function() {
return _interface.CloseSharedMemory(this.name);
};
}
function openProcess(filepath) {
return getInterface().OpenProcess(filepath);
}
function closeProcess(pid) {
return getInterface().CloseProcess(pid);
2023-12-20 08:58:42 +00:00
}
function encryptStringHIGHT(userKey, data) {
return getInterface().EncryptStringHIGHT(userKey, data);
}
function decryptStringHIGHT(userKey, encryptedData) {
return getInterface().DecryptStringHIGHT(userKey, encryptedData);
}
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;
2024-01-04 06:23:26 +00:00
exports.openProcess = openProcess;
exports.closeProcess = closeProcess;
exports.encryptStringHIGHT = encryptStringHIGHT;
exports.decryptStringHIGHT = decryptStringHIGHT;
2022-10-20 19:03:06 +00:00
exports.VERSIONINFO = "WelsonJS native component (WelsonJS.Toolkit) version 0.3.5";
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;