diff --git a/assets/index.js b/assets/index.js index ae28264..4cd2e6b 100644 --- a/assets/index.js +++ b/assets/index.js @@ -7,8 +7,6 @@ utools.onPluginEnter(({ code, type, payload }) => { $("#options").show(); showOptions(); } else { - utools.setExpendHeight(0); - utools.hideMainWindow(); $("#options").hide(); $("#out").show(); var db = utools.db.get('customFts').data[code], @@ -22,44 +20,71 @@ utools.onPluginEnter(({ code, type, payload }) => { if (type == 'over') cmd = cmd.replace(/\{\{input\}\}/mg, payload); // 无输出的批处理 if (db.output == 'ignore' && option.ext == 'bat') option.bin = 'explorer'; - // 运行脚本 - window.run(cmd, option, db.codec, (stdout, stderr) => { - // 报错 - if (stderr) { - window.messageBox({ type: 'error', icon: window.logo, message: stderr, buttons: ['纳尼?!'] }) - utools.outPlugin(); - return; + if (db.hasSubInput) { + // 启动子命令输入 + // 清空输出 + $("#out").text(''); + var subinput = ''; + var setSubInput = () => { + utools.setSubInput(({text}) => { + subinput = text; + }, ''); } - // 有输出 - if (stdout) { - switch (db.output) { - case "ignore": - utools.outPlugin(); - break; - case "text": - utools.showMainWindow(); - utools.setExpendHeight(600); - $("#out").text(stdout); - break; - case "html": - utools.showMainWindow(); - utools.setExpendHeight(600); - $("#out").html(stdout); - break; - case "clip": - copyTo(stdout); - utools.outPlugin(); - break; - case "send": - copyTo(stdout); - paste(); - utools.outPlugin(); - break; + var handleEnter = (event) => { + if (event.keyCode == 13) { + $("#out").text(''); + var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput); + runCmd(execmd, option, db.codec, db.output); } - // 无输出 - } else { - utools.outPlugin(); - } - }) + }; + setSubInput(); + document.addEventListener('keydown', handleEnter); + } else { + utools.setExpendHeight(0); + utools.hideMainWindow(); + runCmd(cmd, option, db.codec, db.output); + } } -}); \ No newline at end of file +}); + +function runCmd(cmd, option, codec, output) { + // 运行脚本 + window.run(cmd, option, codec, (stdout, stderr) => { + // 报错 + if (stderr) { + window.messageBox({ type: 'error', icon: window.logo, message: stderr, buttons: ['纳尼?!'] }) + utools.outPlugin(); + return; + } + // 有输出 + if (stdout) { + switch (output) { + case "ignore": + utools.outPlugin(); + break; + case "text": + utools.showMainWindow(); + utools.setExpendHeight(600); + $("#out").text(stdout); + break; + case "html": + utools.showMainWindow(); + utools.setExpendHeight(600); + $("#out").html(stdout); + break; + case "clip": + copyTo(stdout); + utools.outPlugin(); + break; + case "send": + copyTo(stdout); + paste(); + utools.outPlugin(); + break; + } + // 无输出 + } else { + utools.outPlugin(); + } + }) +} diff --git a/assets/options.js b/assets/options.js index edae5c8..4163a4e 100644 --- a/assets/options.js +++ b/assets/options.js @@ -15,7 +15,7 @@ putCustomFts = (code, pushData) => { var data = {}; data[code] = pushData; utools.db.put({ _id: "customFts", data: data }); - } + } } importCommand = () => { @@ -38,7 +38,7 @@ importCommand = () => { } else { putCustomFts(code, pushData); showOptions(); - } + } } else { if (typeof (Object.values(pushData)[0].features) == 'object') { for (var code of Object.keys(pushData)){ @@ -46,7 +46,7 @@ importCommand = () => { putCustomFts(code, pushData[code]); } } - showOptions(); + showOptions(); } else { window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] }) } @@ -71,7 +71,7 @@ clearAll = () => { window.messageBox({ type: 'question', icon: window.logo, message: "将会清空所有命令,请确认!", buttons: ['手抖...', '确定!'] }, index => { if (index) { utools.db.remove('customFts') - showOptions(); + showOptions(); } }) } @@ -90,47 +90,47 @@ programs = { cmd: { bin: '', agrv: '', - ext: 'bat' + ext: 'bat' }, powershell: { bin: 'powershell', agrv: '-NoProfile -File', - ext: 'ps1' + ext: 'ps1' }, python: { bin: 'python', agrv: '-u', - ext: 'py' + ext: 'py' }, javascript: { bin: 'node', agrv: '', - ext: 'js' + ext: 'js' }, ruby: { bin: 'ruby', agrv: '', - ext: 'rb' + ext: 'rb' }, php: { bin: 'php', agrv: '', - ext: 'php' + ext: 'php' }, lua: { bin: 'lua', agrv: '', - ext: 'lua' + ext: 'lua' }, perl: { bin: 'perl', agrv: '', - ext: 'pl' + ext: 'pl' }, custom: { bin: '', agrv: '', - ext: '' + ext: '' } } @@ -204,6 +204,7 @@ showCustomize = () => { + @@ -295,7 +296,7 @@ $("#options").on('click', '.editBtn', function () { } else { $('#kw').val(data.features.cmds.toString()); } - $('#kw').attr('edit', true); + $('#kw').attr('edit', true); $('#program').val(data.program); $('#output').val(data.output); $('#desc').val(data.features.explain); @@ -307,7 +308,7 @@ $("#options").on('click', '.editBtn', function () { if (mode == 'custom') { $('#custombin').show().val(data.customOptions.bin); $('#customarg').show().val(data.customOptions.args); - $('#customext').show().val(data.customOptions.ext); + $('#customext').show().val(data.customOptions.ext); } mode == 'applescript' && (mode = 'shell'); mode == 'cmd' && (mode = 'powershell'); @@ -336,7 +337,7 @@ $("#options").on('click', '.delBtn', function () { data = db.data; delete data[code]; utools.removeFeature(code); - utools.db.put({ _id: "customFts", data: data, _rev: db._rev }); + utools.db.put({ _id: "customFts", data: data, _rev: db._rev }); showOptions(); }) @@ -372,7 +373,8 @@ $("#options").on('click', '.saveBtn', function () { iconpath = $("#icon").attr('src'), cmd = window.editor.getValue(), icon, - base64ico; + base64ico, + hasSubInput; if (!desc) desc = ' '; // 自定义了图标的情况下 if (iconame) { @@ -381,7 +383,7 @@ $("#options").on('click', '.saveBtn', function () { base64ico = window.getBase64Ico(resolve(dirname, iconpath)); } else { base64ico = window.getBase64Ico(iconpath); - } + } // 未自定义使用默认 } else { icon = iconpath; @@ -398,6 +400,12 @@ $("#options").on('click', '.saveBtn', function () { } else { noKeyword = false; } + // 需要子输入框 + if (cmd.includes('{{subinput}}')) { + hasSubInput = true; + } else { + hasSubInput = false; + } $("#customize").animate({ top: '100%' }); // 添加特性 pushData = { @@ -412,7 +420,8 @@ $("#options").on('click', '.saveBtn', function () { output: output, codec: codec, base64Ico: base64ico, - noKeyword: noKeyword + noKeyword: noKeyword, + hasSubInput: hasSubInput } if (program == 'custom') { pushData.customOptions = {