diff --git a/src/assets/options.js b/src/assets/options.js index 0aa21fb..11c5ea7 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -205,6 +205,7 @@ let showOptions = () => { let showCustomize = () => { $("#customize").remove(); + $("#featureList").fadeOut() let options = `` customWindow = `

@@ -219,7 +220,7 @@ let showCustomize = () => {

类 型 图 标 @@ -237,60 +238,31 @@ let showCustomize = () => { - aa 输 出

-

- 操 作 - - - - ﹢按键 - - ﹢动作 -

脚 本 - - - - - + + + + + + + + ﹢动作 + ﹢按键 + ?帮助

@@ -316,13 +288,13 @@ let showCustomize = () => { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Ctrl-B": () => { - runQuickCommand() + runCurrentCommand() }, "Ctrl-S": () => { - SaveQuickCommand() + SaveCurrentCommand() }, "Ctrl-Q": () => { - quitQuickCommand() + quitCurrentCommand() }, "Alt-Up": "swapLineUp", "Alt-Down": "swapLineDown", @@ -418,18 +390,18 @@ let programCheck = () => { case 'custom': $('.customscript').show(); $('.simulation').hide(); - $('.varoutput').show(); + $('#showInTerm').show() break; case 'simulation': - $('.varoutput').hide(); $('.simulation').show(); $('.customscript').hide(); + $('#showInTerm').hide() mode = 'javascript'; break; default: $('.customscript').hide(); $('.simulation').hide(); - $('.varoutput').show(); + $('#showInTerm').show() break; } window.editor.setOption("mode", mode); @@ -501,41 +473,30 @@ $("#options").on('click', '.editBtn', function () { // 添加模拟按键 $("#options").on('click', '#addKey', function () { - var m1 = $('#modifier1').val(); - var m2 = $('#modifier2').val(); - var k = $('#presskey').val(); - var code = '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'); - } - }) - } + $("#addKey").text("▶ 录制中").addClass('record') + message('开始录制按键,可连续录制') + Mousetrap.record(sequence => { + sequence.forEach(s => { + var keys = s + if (s.includes('+') && s.length > 1) keys = s.split('+').reverse().map(x=>x.trim()).join(`", "`) + window.editor.replaceSelection(`keyTap("${keys}")\n`) + }) + $("#addKey").text("﹢按键").removeClass('record') + }); +}) + +// 内置环境的帮助 +$("#options").on('click', '#showHelp', function () { + $.get('./HELP.md', r => { + utools.ubrowser.goto(r).run() + }) }) // 添加延时 $("#options").on('click', '#addDelay', function () { var t = $('#keydelay').val(); if (/\d+/.test(t)) { - window.editor.replaceSelection(`await sleep(${t});\n`) + window.editor.replaceSelection(`sleep(${t});\n`) } else { Swal.fire({ icon: 'warning', @@ -545,61 +506,36 @@ $("#options").on('click', '#addDelay', function () { }) // 添加动作 -$("#options").on('click', '#addAction', async function () { - var a = $('#action').val(); - var text; - switch (a) { - case 'await sleep': - text = '要延时的毫秒'; - break; - 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 'send': - text = '要发送的文本' - break; - case 'alert': - text = '要弹窗的消息' - break; - case 'ubrowser': - text = '要访问的网站' - break; - default: - Swal.fire({ - icon: 'warning', - text: '未选中任何动作', - }) - return; - } - const { value: content } = await Swal.fire({ - title: text, - input: 'text', +$("#options").on('click', '#addAction', function () { + var html = ` + + + 加引号 + ` + Swal.fire({ + title: "预设动作", + html: html, showCancelButton: true, - }) - if (content) { - if (a == 'ubrowser') { - window.editor.replaceSelection(`utools.ubrowser.goto("${content}")\n .run()\n`) - } else if (a == 'await sleep') { - window.editor.replaceSelection(`${a}(${content})\n`) - } else { - window.editor.replaceSelection(`${a}("${content.replace(/\\/g, '\\\\')}");\n`) + preConfirm: () => { + var actionType = $("#actionType").val() + var actionArgs = $("#actionArgs").val() + if ($("#isString").is(':checked')) actionArgs = "String.raw\`" + actionArgs + "\`" + var action = `${actionType}(${actionArgs})` + if (actionType == 'utools.ubrowser.goto') action += `.run()` + window.editor.replaceSelection(`${action}\n`) } - } + }) }) // 导出 @@ -642,7 +578,7 @@ $("#options").on('click', '#icon, #iconame', function () { } }) -let SaveQuickCommand = async () => { +let SaveCurrentCommand = async () => { var type = $('#type').val(); var code = $("#code").val(); if (!code) { @@ -655,36 +591,16 @@ let SaveQuickCommand = async () => { // 合规性校验 if (type == 'key' && ['{{input}}', '{{SelectFile}}', '{{pwd}}', '{{WindowInfo}}'].map(x => cmd.includes(x)).includes(true)) { - Swal.fire({ - icon: 'error', - title: '啊嘞?!', - text: '关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!', - }) + Swal.fire('关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!') } else if (type == 'regex' && ['{{SelectFile}}', '{{WindowInfo}}', '{{pwd}}'].map(x => cmd.includes(x)).includes(true)) { - Swal.fire({ - icon: 'error', - title: '啊嘞?!', - text: '正则模式无法使用{{SelectFile}}、{{WindowInfo}}、{{pwd}}!', - }) + Swal.fire('正则模式无法使用{{SelectFile}}、{{WindowInfo}}、{{pwd}}!') } else if (type == 'window' && cmd.includes('{{input}}')) { - Swal.fire({ - icon: 'error', - title: '啊嘞?!', - text: '窗口模式无法使用{{input}}!', - }) + Swal.fire('窗口模式无法使用{{input}}!') } else if (['text', 'html'].includes($('#output').val()) && cmd.includes('{{SelectText}}')) { - Swal.fire({ - icon: 'error', - title: '啊嘞?!', - text: '显示文本或html输出时无法使用{{SelectText}}!', - }) + Swal.fire('显示文本或html输出时无法使用{{SelectText}}!') } else if (type == 'regex' && /^(|\/)\.[*+](|\/)$/.test($('#rule').val())) { - Swal.fire({ - icon: 'error', - title: '啊嘞?!', - text: '正则匹配 .* 和 .+ 已被uTools禁用!', - }) + Swal.fire('正则匹配 .* 和 .+ 已被uTools禁用!') } else { var program = $('#program').val(), @@ -763,11 +679,12 @@ let SaveQuickCommand = async () => { 'codec': $('#customcodec').val() } } - if (program == 'simulation') { - $('#output').val(''); - } + // if (program == 'simulation') { + // $('#output').val(''); + // } putCustomFts(code, pushData); showOptions(); + $("#customize").empty() $(`#${code}`).click(); if (!$(`#${code}`).is(':checked')) { $(`#${code}`).click(); @@ -776,25 +693,22 @@ let SaveQuickCommand = async () => { } // 显示运行结果 -let showResult = (content, raw, success) => { +let showRunResult = (content, raw, success) => { var options - var maxlength = raw ? 1000 : 100000 - var htmlEncode = (value, raw) => { - return raw ? String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/ { var result = $('#swal2-content').text() - var style = "text-align: left; padding: 0px 10px; white-space: pre-wrap; word-break: break-all;" result = htmlEncode(result, raw) $(".swal2-content").css("width", "100%") - $('#swal2-content').html(`
${result}
`) + $('#swal2-content').html(`
${result}
`) $('.swal2-popup').addClass('swal2-toast') } var contlength = content.length - if(contlength > maxlength) content = content.slice(0, maxlength - 100) + `\n\n...\n${contlength - maxlength - 100} 字省略\n...\n\n` + content.slice(contlength - 100) + if (contlength > maxlength) content = content.slice(0, maxlength - 100) + `\n\n...\n${contlength - maxlength - 100} 字省略\n...\n\n` + content.slice(contlength - 100) content += '\n' - if (Swal.isVisible()) { - $("#swal2-content > pre").append(htmlEncode(content, raw)) + var outputchannel = $("#swal2-content > pre") + if (outputchannel.is(":parent")) { + outputchannel.append(htmlEncode(content, raw)) } else { options = { onBeforeOpen: preView, @@ -814,8 +728,9 @@ let showResult = (content, raw, success) => { } } -let runQuickCommand = () => { +let runCurrentCommand = () => { var cmd = window.editor.getValue() + cmd = special(cmd) var program = $("#program").val() var output = $("#output").val() var terminal = false @@ -828,41 +743,43 @@ let runQuickCommand = () => { terminal = true break; case "ignore": - if(program != "simulation") utools.hideMainWindow() // todo 模拟操作选择输出方式 + utools.hideMainWindow() break; } if (program == "simulation") { runCodeInVm(cmd, (stdout, stderr) => { - if (stderr) return showResult(stderr, raw, false) - showResult(stdout, raw, true) + if (stderr) return showRunResult(stderr, raw, false) + showRunResult(stdout, raw, true) }); } else { var option = programs[program] runCodeFile(cmd, option, terminal, (stdout, stderr) => { if(terminal) return - if (stderr) return showResult(stderr, raw, false) - showResult(stdout, raw, true) + if (stderr) return showRunResult(stderr, raw, false) + showRunResult(stdout, raw, true) }) } } -let quitQuickCommand = () => { - $("#customize").animate({ top: '100%'}); +let quitCurrentCommand = () => { + $("#customize").animate({ top: '100%' }); + $("#featureList").fadeIn() + $("#customize").empty() } // 运行 $("#options").on('click', '.cmdBtn.run', function () { - runQuickCommand() + runCurrentCommand() }) // 取消 $("#options").on('click', '.cmdBtn.cancel', function () { - quitQuickCommand() + quitCurrentCommand() }) // 保存 $("#options").on('click', '.cmdBtn.save', function () { - SaveQuickCommand() + SaveCurrentCommand() }) // 语言选项改变时 @@ -891,3 +808,24 @@ $("#options").on('change', '#type', function () { resetVars(); typeCheck(); }) + +Mousetrap.bind('ctrl+s', () => { + if ($("#customize").is(":parent")) { + SaveCurrentCommand() + } + return false +}); + +Mousetrap.bind('ctrl+q', () => { + if ($("#customize").is(":parent")) { + quitCurrentCommand() + } + return false +}); + +Mousetrap.bind('ctrl+b', () => { + if ($("#customize").is(":parent")) { + runCurrentCommand() + } + return false +}); \ No newline at end of file