diff --git a/src/assets/index.js b/src/assets/index.js
old mode 100755
new mode 100644
index e1bd387..3f7add9
--- a/src/assets/index.js
+++ b/src/assets/index.js
@@ -10,18 +10,14 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
$("#out").show().text('');
var db = utools.db.get('customFts').data[code],
cmd = db.cmd;
- if (db.robotjs) {
- utools.setExpendHeight(0);
- utools.hideMainWindow();
- eval(cmd);
- utools.outPlugin();
- return;
- }
if (db.program == "custom") {
option = db.customOptions;
- } else {
+ } else if(db.program == "simulation"){
+ option = "simulation";
+ }else{
option = programs[db.program];
}
+ cmd = await special(cmd);
// 正则
if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
// 窗口
@@ -58,7 +54,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
if (event.keyCode == 13) {
$("#out").text('');
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
- runCmd(execmd, option, db.codec, db.output);
+ runCmd(execmd, option, db.output);
}
};
setSubInput();
@@ -68,40 +64,47 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
document.removeEventListener('keydown', handleEnter);
})
} else {
- runCmd(cmd, option, db.codec, db.output);
+ runCmd(cmd, option, db.output);
}
}
});
-function runCmd(cmd, option, codec, output) {
+function runCmd(cmd, option, output) {
+ if (option == "simulation") {
+ utools.setExpendHeight(0);
+ // utools.hideMainWindow();
+ eval(`(async () => {
+ ${cmd}
+ })()`);
+ utools.outPlugin();
+ return;
+ }
// 不需要输出的,提前关闭窗口
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
- utools.hideMainWindow()
+ utools.setExpendHeight(0);
+ utools.outPlugin();
+ // utools.hideMainWindow();
}
var terminal = false;
if(output == 'terminal') terminal = true;
// 运行脚本
- window.run(cmd, option, codec, terminal, (stdout, stderr) => {
+ window.run(cmd, option, terminal, (stdout, stderr) => {
if (stderr) {
// 报错
- utools.showMainWindow()
- Swal.fire({
+ messageBox({
+ type: 'error',
title: '啊嘞?!',
- text: stderr,
- icon: 'error',
- showCancelButton: true,
- confirmButtonColor: '#3085d6',
- cancelButtonColor: '#d33',
- confirmButtonText: '转至脚本目录',
- cancelButtonText: '退出',
- }).then((result) => {
- if (result.value) {
- open(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
- }
- copyTo(stderr);
- utools.showNotification("已复制报错信息");
- utools.outPlugin();
- })
+ icon: window.logo,
+ message: stderr,
+ buttons: ['转至脚本目录', '退出']
+ }, index => {
+ if (index == 0) {
+ locate(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
+ }
+ copyTo(stderr);
+ message("已复制报错信息");
+ utools.outPlugin();
+ })
} else if (stdout) {
// 有输出
switch (output) {
@@ -113,7 +116,6 @@ function runCmd(cmd, option, codec, output) {
break;
case "clip":
copyTo(stdout);
- utools.outPlugin();
break;
case "send":
// 暂存用户剪贴板
@@ -123,15 +125,12 @@ function runCmd(cmd, option, codec, output) {
setTimeout(() => {
restoreClip(historyData);
}, 500);
- utools.outPlugin();
break;
case "notice":
// 发送系统通知
- utools.showNotification(stdout);
- utools.outPlugin();
+ message(stdout);
break;
case "ignore":
- utools.outPlugin();
break;
default:
break;
diff --git a/src/assets/options.css b/src/assets/options.css
old mode 100755
new mode 100644
index c3b99a3..4a92d7a
--- a/src/assets/options.css
+++ b/src/assets/options.css
@@ -180,18 +180,10 @@
color: rgb(48, 21, 122);
}
-#options .keyword.key {
- color: rgb(122, 115, 21);
-}
-
#options .logo {
width: 32px;
}
-#options #customize .robot{
- display: none;
-}
-
#options #customize .keys{
width: 10%;
}
@@ -291,6 +283,7 @@
#options #customize {
position: fixed;
+ z-index: 999;
height: 100%;
top: 100%;
left: 0;
@@ -301,6 +294,10 @@
background: white;
}
+#options .varoutput{
+ display: none;
+}
+
#options #customize p {
line-height: 1.25rem;
}
@@ -399,7 +396,7 @@ input::-webkit-input-placeholder {
transition: 0.5s;
}
-#options #customize select#vars {
+#options #customize select#vars,#action {
color: #999;
}
diff --git a/src/assets/options.js b/src/assets/options.js
old mode 100755
new mode 100644
index 9e38b4e..05a6108
--- a/src/assets/options.js
+++ b/src/assets/options.js
@@ -149,9 +149,10 @@ programs = {
}
showOptions = () => {
+ $("#featureList").remove();
var currentFts = utools.getFeatures(),
customFts = getCustomFts();
- let featureList = '
| 模式 | 说明 | 启用 |
';
+ let featureList = ' | 模式 | 说明 | 启用 |
';
for (var fts in customFts) {
let features = customFts[fts].features;
var cmds = '';
@@ -162,11 +163,7 @@ showOptions = () => {
} else if (features.cmds[0].type == 'window') {
var app = features.cmds[0].match.app
if (app.length > 15) app = app.slice(0, 15) + '...';
- if (customFts[fts].robotjs) {
- cmds = `按键: ${app}`;
- } else {
- cmds = `窗口: ${app}`;
- }
+ cmds = `窗口: ${app}`;
} else {
features.cmds.forEach(cmd => {
cmds += `${cmd}`;
@@ -199,8 +196,8 @@ showOptions = () => {
- `
- $("#options").html(featureList);
+ `
+ $("#options").append(featureList);
}
showCustomize = () => {
@@ -213,19 +210,19 @@ showCustomize = () => {
-
关键字
说 明
类 型
图 标
-
+
变 量
-
- 脚 本
-
+
+ 操 作
-
-
-
-
-
+
+
+
+
+
+
+
+
+ 脚 本
-
-
-
+
+
+
@@ -285,20 +294,12 @@ showCustomize = () => {
`
$("#options").append(customWindow)
- if (window.isWin) {
- var shell = 'cmd',
- mode = 'powershell';
- } else {
- var shell = 'shell',
- mode = 'shell';
- }
- $("#program").val(shell);
- $("#icon").attr('src', `logo/${shell}.png`);
+ $("#icon").attr('src', 'logo/simulation.png');
window.editor = CodeMirror.fromTextArea(document.getElementById("cmd"), {
lineNumbers: true,
lineWrapping: true
});
- window.editor.setOption("mode", mode);
+ window.editor.setOption("mode", 'javascript');
$("#customize").animate({ top: '0px' });
}
@@ -321,8 +322,10 @@ outputCheck = () => {
// 检查模式选项
typeCheck = () => {
var type = $("#type").val();
- $("#output, #program, #vars").prop("disabled", false);
- $(".robot").hide()
+ // $("#output, #program, #vars").prop("disabled", false);
+ // $('.varoutput').show()
+ // $(".simulation").hide()
+ // $("#program").prop("disabled", false)
switch (type) {
case 'key':
$("#ruleWord").html("关键字");
@@ -336,14 +339,6 @@ typeCheck = () => {
$(".var.window").hide()
$("#rule").prop("placeholder", '匹配的正则规则,如/\\w+/i');
break;
- case 'robotjs':
- $("#ruleWord").html("进 程");
- $("#output, #program, #vars").prop("disabled", true).val('');
- $("#rule").prop("placeholder", '窗口的进程名,支持正则,如explorer.exe');
- $(".robot").show();
- $('.customscript').hide();
- window.editor.setOption("mode", 'javascript');
- break;
case 'window':
$("#ruleWord").html("进 程");
$(".var.regex").hide()
@@ -400,13 +395,12 @@ $("#options").on('click', '.editBtn', function () {
var code = $(this).attr('code');
var data = utools.db.get("customFts").data[code];
showCustomize();
- var robotjs = data.robotjs;
var cmds = data.features.cmds[0]
if (cmds.type == 'regex') {
$('#type').val('regex')
$('#rule').val(cmds.match);
} else if (cmds.type == 'window') {
- robotjs ? $('#type').val('robotjs') : $('#type').val('window')
+ $('#type').val('window');
$('#rule').val(cmds.match.app);
} else {
$('#type').val('key')
@@ -423,12 +417,13 @@ $("#options").on('click', '.editBtn', function () {
$('#customarg').show().val(data.customOptions.argv);
$('#customext').show().val(data.customOptions.ext);
}
- mode == 'applescript' && (mode = 'shell');
- mode == 'cmd' && (mode = 'powershell');
- window.editor.setOption("mode", mode);
+ // mode == 'applescript' && (mode = 'shell');
+ // mode == 'cmd' && (mode = 'powershell');
+ // window.editor.setOption("mode", mode);
window.editor.setValue(data.cmd);
resetVars();
typeCheck();
+ programCheck();
outputCheck();
})
@@ -468,7 +463,7 @@ $("#options").on('click', '#addKey', function () {
$("#options").on('click', '#addDelay', function () {
var t = $('#keydelay').val();
if (/\d+/.test(t)) {
- window.editor.replaceSelection(`utools.robot.setKeyboardDelay(${t});\n`)
+ window.editor.replaceSelection(`await sleep(${t});\n`)
} else {
Swal.fire({
icon: 'warning',
@@ -477,6 +472,49 @@ $("#options").on('click', '#addDelay', function () {
}
})
+// 添加动作
+$("#options").on('click', '#addAction', async function () {
+ var a = $('#action').val();
+ var text;
+ switch (a) {
+ case 'open':
+ text = '要打开的文件';
+ break;
+ case 'visit':
+ text = '要访问的网址';
+ break;
+ case 'locate':
+ text = '要定位的文件'
+ break;
+ case 'system':
+ text = '要执行的命令'
+ break;
+ case 'message':
+ text = '要发送的消息'
+ break;
+ case 'copyTo':
+ text = '要写入的内容'
+ break;
+ case 'alert':
+ text = '要弹窗的消息'
+ break;
+ default:
+ Swal.fire({
+ icon: 'warning',
+ text: '未选中任何动作',
+ })
+ return;
+ }
+ const { value: content } = await Swal.fire({
+ title: text,
+ input: 'text',
+ showCancelButton: true,
+ })
+ if (content) {
+ window.editor.replaceSelection(`${a}("${content.replace(/\\/g, '\\\\')}");\n`)
+ }
+})
+
// 导出
$("#options").on('click', '.exportBtn', function () {
var code = $(this).attr('code'),
@@ -553,18 +591,11 @@ $("#options").on('click', '.saveBtn', function () {
title: '啊嘞?!',
text: '显示文本或html输出时无法使用{{SelectText}}!',
})
- } else if (type == 'robotjs' && /\{\{.*?\}\}/.test(cmd)) {
- Swal.fire({
- icon: 'error',
- title: '啊嘞?!',
- text: '模拟按键模式无法使用特殊变量!',
- })
- }else {
+ } else {
var program = $('#program').val(),
desc = $('#desc').val(),
iconame = $("#iconame").val(),
iconpath = $("#icon").attr('src'),
- robotjs = false,
icon,
base64ico,
hasSubInput;
@@ -589,7 +620,7 @@ $("#options").on('click', '.saveBtn', function () {
"minNum": 1
}];
}
- if (type == 'window' || type == 'robotjs') {
+ if (type == 'window') {
cmds = [{
"label": desc,
"type": "window",
@@ -605,11 +636,11 @@ $("#options").on('click', '.saveBtn', function () {
hasSubInput = false;
}
$("#customize").animate({ top: '100%' });
- if (type == "robotjs") {
- program = "";
- output = "";
- robotjs = true;
- }
+ // if (type == "robotjs") {
+ // program = "";
+ // output = "";
+ // robotjs = true;
+ // }
// 添加特性
pushData = {
features: {
@@ -621,8 +652,8 @@ $("#options").on('click', '.saveBtn', function () {
program: program,
cmd: cmd,
output: output,
- hasSubInput: hasSubInput,
- robotjs: robotjs
+ hasSubInput: hasSubInput
+ // robotjs: robotjs
}
if (program == 'custom') {
pushData.customOptions = {
@@ -631,6 +662,9 @@ $("#options").on('click', '.saveBtn', function () {
"ext": $('#customext').val()
}
}
+ if (program == 'simulation') {
+ $('#output').val('');
+ }
putCustomFts(code, pushData);
showOptions();
$(`#${code}`).click();
@@ -646,18 +680,32 @@ hasCustomIcon = () => {
return /data:image\/png;base64,/.test(src) || iconame
}
+programCheck = () => {
+ let mode = $('#program').val();
+ if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`);
+ switch (mode) {
+ case 'custom':
+ $('.customscript').show();
+ break;
+ case 'simulation':
+ $('.varoutput').hide();
+ $('.simulation').show();
+ mode = 'javascript';
+ break;
+ default:
+ $('.customscript').hide();
+ $('.simulation').hide();
+ $('.varoutput').show();
+ break;
+ }
+ if('applescript') mode = 'shell';
+ if('cmd') mode = 'powershell';
+ window.editor.setOption("mode", mode);
+}
+
// 语言选项改变时
$("#options").on('change', '#program', function () {
- let mode = $(this).val();
- if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`);
- if (mode == 'custom') {
- $('.customscript').show();
- } else {
- $('.customscript').hide();
- }
- mode == 'applescript' && (mode = 'shell');
- mode == 'cmd' && (mode = 'powershell');
- window.editor.setOption("mode", mode);
+ programCheck()
})
// 变量选项改变时
@@ -666,6 +714,10 @@ $("#options").on('change', '#vars', function () {
window.editor.replaceSelection($("#vars").val());
})
+$("#options").on('change', '#action', function () {
+ $("#action").css({ 'color': 'black' })
+})
+
// 输出选项改变时
$("#options").on('change', '#output', function () {
resetVars();