diff --git a/src/assets/options.js b/src/assets/options.js index c77d8b3..547188d 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -185,6 +185,10 @@ let showOptions = (tag = "默认") => { var app = features.cmds[0].match.app if (app.length > 10) app = app.slice(0, 10) + '...'; cmds = `窗口: ${app}`; + } else if (features.cmds[0].type == 'files') { + var app = features.cmds[0].match + if (app.length > 10) app = app.slice(0, 10) + '...'; + cmds = `文件: ${app}`; } else { features.cmds.forEach(cmd => { cmds += `${cmd}`; @@ -239,9 +243,10 @@ let showCustomize = () => {

模 式 关键字

说 明 @@ -260,15 +265,16 @@ let showCustomize = () => { 变 量 输 出

+ + + @@ -405,19 +414,24 @@ let typeCheck = () => { switch (type) { case 'key': $("#ruleWord").html("关键字"); - $(".var.regex").hide() - $(".var.window").hide() + $(".var.regex, .var.window, .var.files").hide() $("#rule").prop("placeholder", '多个关键字用逗号隔开'); break; case 'regex': $("#ruleWord").html("正 则"); + $(".var.window, .var.files").hide() $(".var.regex").show() - $(".var.window").hide() - $("#rule").prop("placeholder", '匹配的正则规则,如 /.*?\\.exe$/i'); + $("#rule").prop("placeholder", '匹配文本的正则,如 /.*?\\.exe$/i'); + break; + case 'files': + $("#ruleWord").html("正 则"); + $(".var.regex, .var.window").hide() + $(".var.files").show() + $("#rule").prop("placeholder", '匹配文件的正则,如 /.*?\\.exe$/i'); break; case 'window': $("#ruleWord").html("进 程"); - $(".var.regex").hide() + $(".var.regex, .var.files").hide() $(".var.window").show() $("#rule").prop("placeholder", '窗口的进程名,多个用逗号隔开'); break; @@ -499,11 +513,12 @@ $("#options").on('click', '.editBtn', function () { showCustomize(); data.tags && $('#tags').val(data.tags.join(",")) var cmds = data.features.cmds[0] - if (cmds.type == 'regex') { - $('#type').val('regex') + var platform = data.features.platform + if (platform) ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled'))) + $('#type').val(cmds.type) + if (cmds.type == 'regex' || cmds.type == 'files') { $('#rule').val(cmds.match); } else if (cmds.type == 'window') { - $('#type').val('window'); $('#rule').val(cmds.match.app); } else { $('#type').val('key') @@ -650,13 +665,15 @@ let SaveCurrentCommand = async () => { var cmd = window.editor.getValue(); // 合规性校验 if (type == 'key' - && ['{{input}}', '{{SelectFile}}', '{{pwd}}', '{{WindowInfo}}'].map(x => cmd.includes(x)).includes(true)) { - Swal.fire('关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!') + && ['{{input}}', '{{SelectFile}}', '{{pwd}}', '{{WindowInfo}}', '{{MatchedFiles}}'].map(x => cmd.includes(x)).includes(true)) { + Swal.fire('关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}、{{MatchedFiles}}!') } else if (type == 'regex' - && ['{{SelectFile}}', '{{WindowInfo}}', '{{pwd}}'].map(x => cmd.includes(x)).includes(true)) { - Swal.fire('正则模式无法使用{{SelectFile}}、{{WindowInfo}}、{{pwd}}!') - } else if (type == 'window' && cmd.includes('{{input}}')) { - Swal.fire('窗口模式无法使用{{input}}!') + && ['{{SelectFile}}', '{{WindowInfo}}', '{{pwd}}', '{{MatchedFiles}}'].map(x => cmd.includes(x)).includes(true)) { + Swal.fire('正则模式无法使用{{SelectFile}}、{{WindowInfo}}、{{pwd}}、{{MatchedFiles}}!') + } else if (type == 'window' && cmd.includes('{{input}}', '{{MatchedFiles}}')) { + Swal.fire('窗口模式无法使用{{input}}、{{MatchedFiles}}!') + } else if (type == 'files' && cmd.includes('{{input}}', '{{MatchedFiles}}')) { + Swal.fire('窗口模式无法使用{{input}}、{{MatchedFiles}}!') } else if (['text', 'html'].includes($('#output').val()) && cmd.includes('{{SelectText}}')) { Swal.fire('显示文本或html输出时无法使用{{SelectText}}!') } else if (type == 'regex' && /^(|\/)\.[*+](|\/)$/.test($('#rule').val())) { @@ -684,10 +701,6 @@ let SaveCurrentCommand = async () => { cmds = rule.split(",").map(x => x.trim()) } else if (type == 'regex') { if (!/^\/.*?\/[igm]*$/.test(rule)) { - await Swal.fire({ - icon: 'info', - text: '亲,是不是忘了正则表达式两边的"/"了?正确的写法是/xxxx/,不过作者会很贴心地帮你自动加上哟', - }) rule = "/" + rule + "/" } cmds = [{ @@ -711,6 +724,16 @@ let SaveCurrentCommand = async () => { } } cmds = [cmdOfWin]; + } else if (type == 'files') { + if (!/^\/.*?\/[igm]*$/.test(rule)) { + rule = "/" + rule + "/" + } + cmds = [{ + "label": desc, + "type": "files", + "match": rule, + "minNum": 1 + }]; } // 需要子输入框 if (cmd.includes('{{subinput}}')) { @@ -718,13 +741,17 @@ let SaveCurrentCommand = async () => { } else { hasSubInput = false; } + // platform + var platform = [] + $('.platform').not('.disabled').each(function() { platform.push($(this).attr('id')) }) // 添加特性 pushData = { features: { "code": code, "explain": desc, "cmds": cmds, - "icon": icon + "icon": icon, + "platform": platform }, program: program, cmd: cmd, @@ -967,6 +994,16 @@ $("#options").on('change', '#type', function () { typeCheck(); }) +// 平台按钮 +$("#options").on('click', '.platform', function () { + if ($(this).hasClass('disabled')){ + $(this).removeClass('disabled') + } else { + if ($('.disabled').length == 2) message('至少保留一个平台') + else $(this).addClass('disabled') + } +}) + Mousetrap.bind('ctrl+s', () => { SaveCurrentCommand() return false diff --git a/src/img/linux.svg b/src/img/linux.svg new file mode 100644 index 0000000..f0d72e3 --- /dev/null +++ b/src/img/linux.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/img/macos.svg b/src/img/macos.svg new file mode 100644 index 0000000..c55a9c0 --- /dev/null +++ b/src/img/macos.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/img/windows.svg b/src/img/windows.svg new file mode 100644 index 0000000..b59b8fc --- /dev/null +++ b/src/img/windows.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/logo/applescript.png b/src/logo/applescript.png index 2790db4..979b022 100755 Binary files a/src/logo/applescript.png and b/src/logo/applescript.png differ