From 6a21e11817e1a831b4b257eac7f9719cf6069730 Mon Sep 17 00:00:00 2001
From: fofolee
说 明
@@ -232,9 +254,29 @@ showCustomize = () => {脚 本 - - - + + + + 添加 + + 添加 + + + + +
@@ -249,7 +291,6 @@ showCustomize = () => { } else { var shell = 'shell', mode = 'shell'; - $("#codec").hide(); } $("#program").val(shell); $("#icon").attr('src', `logo/${shell}.png`); @@ -280,6 +321,8 @@ outputCheck = () => { // 检查模式选项 typeCheck = () => { var type = $("#type").val(); + $("#output, #program, #vars").prop("disabled", false); + $(".robot").hide() switch (type) { case 'key': $("#ruleWord").html("关键字"); @@ -293,6 +336,14 @@ 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() @@ -322,6 +373,8 @@ $("#options").on('change', 'input[type=checkbox]', function () { // 底部功能按钮 $("#options").on('click', '.footBtn', function () { switch ($(this).attr('id')) { + case 'sample': visit('https://github.com/fofolee/uTools-QuickerCommand/tree/master/CommandCollections'); + break; case 'add': showCustomize(); break; case 'import': importCommand(); @@ -347,12 +400,13 @@ $("#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') { - $('#type').val('window') + robotjs ? $('#type').val('robotjs') : $('#type').val('window') $('#rule').val(cmds.match.app); } else { $('#type').val('key') @@ -362,7 +416,6 @@ $("#options").on('click', '.editBtn', function () { $('#program').val(data.program); $('#output').val(data.output); $('#desc').val(data.features.explain); - $('#codec').val(data.codec); $("#icon").attr('src', data.features.icon); let mode = data.program; if (mode == 'custom') { @@ -379,6 +432,51 @@ $("#options").on('click', '.editBtn', function () { outputCheck(); }) +// 添加模拟按键 +$("#options").on('click', '#addKey', function () { + var m1 = $('#modifier1').val(); + var m2 = $('#modifier2').val(); + var k = $('#presskey').val(); + var code = 'utools.robot.keyTap'; + if (/^(\S|f1[0-2]|f[1-9]|backspace|delete|enter|tab|escape|up|down|right|left|home|end|pageup|pagedown|command|alt|control|shift|right_shift|space|printscreen|insert')$/.test(k)) { + if (!m1 && !m2) { + code += `('${k}');\n`; + } else if(m1 && m2){ + code += `('${k}', ['${m1}', '${m2}']);\n` + } else { + code += `('${k}', '${m1}${m2}');\n` + } + window.editor.replaceSelection(code); + } else { + Swal.fire({ + text: '请输入正确的按键', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: '帮助', + cancelButtonText: '确定', + }).then((result) => { + if (result.value) { + visit('https://robotjs.io/docs/syntax#keys'); + } + }) + } +}) + +// 添加延时 +$("#options").on('click', '#addDelay', function () { + var t = $('#keydelay').val(); + if (/\d+/.test(t)) { + window.editor.replaceSelection(`utools.robot.setKeyboardDelay(${t});\n`) + } else { + Swal.fire({ + icon: 'warning', + text: '请输入正确的时间, 单位 ms', + }) + } +}) + // 导出 $("#options").on('click', '.exportBtn', function () { var code = $(this).attr('code'), @@ -431,40 +529,42 @@ $("#options").on('click', '.saveBtn', function () { // 合规性校验 if (type == 'key' && ['{{input}}', '{{SelectFile}}', '{{pwd}}', '{{WindowInfo}}'].map(x => cmd.includes(x)).includes(true)) { - window.messageBox({ - type: 'error', - icon: window.logo, - message: "关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!", - buttons: ['朕知道了'] - }) + Swal.fire({ + icon: 'error', + title: '啊嘞?!', + text: '关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!', + }) } else if (type == 'regex' - && ['{{SelectFile}}', '{{WindowInfo}}','{{pwd}}'].map(x => cmd.includes(x)).includes(true)) { - window.messageBox({ - type: 'error', - icon: window.logo, - message: "正则模式无法使用{{SelectFile}}、{{WindowInfo}}、{{pwd}}!", - buttons: ['朕知道了'] - }) + && ['{{SelectFile}}', '{{WindowInfo}}', '{{pwd}}'].map(x => cmd.includes(x)).includes(true)) { + Swal.fire({ + icon: 'error', + title: '啊嘞?!', + text: '正则模式无法使用{{SelectFile}}、{{WindowInfo}}、{{pwd}}!', + }) } else if (type == 'window' && cmd.includes('{{input}}')) { - window.messageBox({ - type: 'error', - icon: window.logo, - message: "窗口模式无法使用{{input}}!", - buttons: ['朕知道了'] - }) + Swal.fire({ + icon: 'error', + title: '啊嘞?!', + text: '窗口模式无法使用{{input}}!', + }) } else if (['text', 'html'].includes($('#output').val()) && cmd.includes('{{SelectText}}')) { - window.messageBox({ - type: 'error', - icon: window.logo, - message: "显示文本或html输出时无法使用{{SelectText}}!", - buttons: ['朕知道了'] - }) - } else { + Swal.fire({ + icon: 'error', + title: '啊嘞?!', + text: '显示文本或html输出时无法使用{{SelectText}}!', + }) + } else if (type == 'robotjs' && /\{\{.*?\}\}/.test(cmd)) { + Swal.fire({ + icon: 'error', + title: '啊嘞?!', + text: '模拟按键模式无法使用特殊变量!', + }) + }else { var program = $('#program').val(), desc = $('#desc').val(), - codec = $('#codec').val(), iconame = $("#iconame").val(), iconpath = $("#icon").attr('src'), + robotjs = false, icon, base64ico, hasSubInput; @@ -477,11 +577,9 @@ $("#options").on('click', '.saveBtn', function () { } else { icon = iconpath; } - var noKeyword; var rule = $('#rule').val(); if (type == 'key') { cmds = rule.split(',') - noKeyword = false; } if (type == 'regex') { cmds = [{ @@ -490,17 +588,15 @@ $("#options").on('click', '.saveBtn', function () { "match": rule, "minNum": 1 }]; - noKeyword = true; } - if (type == 'window') { + if (type == 'window' || type == 'robotjs') { cmds = [{ "label": desc, "type": "window", "match": { "app": rule - }, + } }]; - noKeyword = true; } // 需要子输入框 if (cmd.includes('{{subinput}}')) { @@ -509,6 +605,11 @@ $("#options").on('click', '.saveBtn', function () { hasSubInput = false; } $("#customize").animate({ top: '100%' }); + if (type == "robotjs") { + program = ""; + output = ""; + robotjs = true; + } // 添加特性 pushData = { features: { @@ -520,9 +621,8 @@ $("#options").on('click', '.saveBtn', function () { program: program, cmd: cmd, output: output, - codec: codec, - noKeyword: noKeyword, - hasSubInput: hasSubInput + hasSubInput: hasSubInput, + robotjs: robotjs } if (program == 'custom') { pushData.customOptions = { @@ -551,13 +651,9 @@ $("#options").on('change', '#program', function () { let mode = $(this).val(); if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`); if (mode == 'custom') { - $('#custombin').show(); - $('#customarg').show(); - $('#customext').show(); + $('.customscript').show(); } else { - $('#custombin').hide(); - $('#customarg').hide(); - $('#customext').hide(); + $('.customscript').hide(); } mode == 'applescript' && (mode = 'shell'); mode == 'cmd' && (mode = 'powershell');