diff --git a/assets/options.js b/assets/options.js index 1940fbf..16ea3ce 100644 --- a/assets/options.js +++ b/assets/options.js @@ -18,6 +18,7 @@ putCustomFts = (code, pushData) => { } } +// 导入 importCommand = () => { var options = { filters: [{ name: 'json', extensions: ['json'] }, ] @@ -31,20 +32,16 @@ importCommand = () => { window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] }) return } + // 单个命令导入 if (typeof(pushData.features)=='object') { - var code = basename(file, '.json'); - if (code in customFts) { - window.messageBox({ type: 'error', icon: window.logo, message: "命令名称重复, 请先修改文件名再导入!", buttons: ['朕知道了'] }) - } else { - putCustomFts(code, pushData); - showOptions(); - } + var code = pushData.features.code; + putCustomFts(code, pushData); + showOptions(); + // 多个命令导入 } else { if (typeof (Object.values(pushData)[0].features) == 'object') { for (var code of Object.keys(pushData)){ - if (!(code in customFts)) { - putCustomFts(code, pushData[code]); - } + putCustomFts(code, pushData[code]); } showOptions(); } else { @@ -137,12 +134,14 @@ programs = { showOptions = () => { var currentFts = utools.getFeatures(), customFts = getCustomFts(); - let featureList = '
关键字
+ 模 式 + + 通过输入关键字进入插件 + 通过正则匹配主输入框文本 + 通过呼出uTools前的活动窗口匹配 + + 关键字
说 明
类 型 @@ -202,14 +208,15 @@ showCustomize = () => { 插入特殊变量 是否Window系统 - 本计算机名 - 主输入框的文本 + 本机唯一ID + 主输入框的文本 子输入框的文本 - 文件管理器当前目录 + 文件管理器当前目录 + 当前窗口信息(JSON格式) 浏览器当前链接 剪切板的文本 - aa选中的文本 - 选中的文件 + aa选中的文本 + 选中的文件 输 出 @@ -254,6 +261,49 @@ showCustomize = () => { $("#customize").animate({ top: '0px' }); } +// 重置变量下拉框 +resetVars = () => { + $('#vars').val(""); + $("#vars").css({ 'color': '#999' }); +} + +// 检查输出选项 +outputCheck = () => { + var output = $("#output").val() + if (output == 'text' || output == 'html') { + $(".selectText").hide() + } else { + $(".selectText").show() + } +} + +// 检查模式选项 +typeCheck = () => { + var type = $("#type").val(); + switch (type) { + case 'key': + $("#ruleWord").html("关键字"); + $(".var.regex").hide() + $(".var.window").hide() + $("#rule").prop("placeholder", '多个关键字用逗号隔开'); + break; + case 'regex': + $("#ruleWord").html("正 则"); + $(".var.regex").show() + $(".var.window").hide() + $("#rule").prop("placeholder", '匹配的正则规则,如/\\w+/i'); + break; + case 'window': + $("#ruleWord").html("进 程"); + $(".var.regex").hide() + $(".var.window").show() + $("#rule").prop("placeholder", '窗口的进程名,支持正则,如explorer.exe'); + break; + default: + break; + } +} + // 开关 $("#options").on('change', 'input[type=checkbox]', function () { var customFts = getCustomFts(), @@ -291,14 +341,18 @@ $("#options").on('click', '.editBtn', function () { var code = $(this).attr('code'); var data = utools.db.get("customFts").data[code]; showCustomize(); - // 判断是通过关键词进入还是主输入框进入 - if (data.noKeyword) { - $('#kw').val(data.features.code); - $('#kw').prop('disabled', true); + 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') + $('#rule').val(cmds.match.app); } else { - $('#kw').val(data.features.cmds.toString()); + $('#type').val('key') + $('#rule').val(data.features.cmds.toString()); } - $('#kw').attr('edit', true); + $('#code').val(code); $('#program').val(data.program); $('#output').val(data.output); $('#desc').val(data.features.explain); @@ -316,6 +370,9 @@ $("#options").on('click', '.editBtn', function () { mode == 'cmd' && (mode = 'powershell'); window.editor.setOption("mode", mode); window.editor.setValue(data.cmd); + resetVars(); + typeCheck(); + outputCheck(); }) // 导出 @@ -324,7 +381,6 @@ $("#options").on('click', '.exportBtn', function () { json = getCustomFts()[code], options = { title: '选择保存位置', - defaultPath: code, filters: [ { name: 'json', extensions: ['json'] }, ] @@ -359,30 +415,48 @@ $("#options").on('click', '#icon, #iconame', function () { // 保存 $("#options").on('click', '.saveBtn', function () { - var code = $('#kw').val().split(',')[0].trim() - var customFts = getCustomFts(), - output = $('#output').val(), - cmd = window.editor.getValue(); - // 如果 code 重复, 编辑状态下不检测 - if (code in customFts && !$('#kw').attr('edit')) { - $('#kw').css({ 'border-bottom-color': '#ec1212' }) + var type = $('#type').val(); + var code = $("#code").val(); + if (!code) { + // 生成唯一code + var uid = Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36); + var code = `${type}_${uid}`; + } + var output = $('#output').val(); + var cmd = window.editor.getValue(); + // 合规性校验 + if (type == 'key' + && ['{{input}}', '{{SelectFile}}', '{{pwd}}', '{{WindowInfo}}'].map(x => cmd.includes(x)).includes(true)) { window.messageBox({ type: 'error', icon: window.logo, - message: "命令名称重复!", + message: "关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!", buttons: ['朕知道了'] }) - } else if (['text', 'html'].includes($('#output').val()) - && ['{{SelectText}}', '{{SelectFile}}', '{{pwd}}'].map(x => cmd.includes(x)).includes(true)) { + } 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: ['朕知道了'] + }) + } else if (type == 'window' && cmd.includes('{{input}}')) { window.messageBox({ type: 'error', icon: window.logo, - message: "显示文本或html输出时无法使用{{SelectText}}、{{SelectFile}}或{{pwd}}!", + message: "窗口模式无法使用{{input}}!", + buttons: ['朕知道了'] + }) + } else if (['text', 'html'].includes($('#output').val()) && cmd.includes('{{SelectText}}')) { + window.messageBox({ + type: 'error', + icon: window.logo, + message: "显示文本或html输出时无法使用{{SelectText}}!", buttons: ['朕知道了'] }) } else { - var kw = $('#kw').val().split(','), - program = $('#program').val(), + var program = $('#program').val(), desc = $('#desc').val(), codec = $('#codec').val(), iconame = $("#iconame").val(), @@ -404,16 +478,30 @@ $("#options").on('click', '.saveBtn', function () { icon = iconpath; base64ico = ''; } - // 通过主输入框直接进入 - if (cmd.includes('{{input}}')) { - kw = [{ + var noKeyword; + var rule = $('#rule').val(); + if (type == 'key') { + cmds = rule.split(',') + noKeyword = false; + } + if (type == 'regex') { + cmds = [{ "label": desc, - "type": "over", + "type": "regex", + "match": rule, "minNum": 1 }]; noKeyword = true; - } else { - noKeyword = false; + } + if (type == 'window') { + cmds = [{ + "label": desc, + "type": "window", + "match": { + "app": rule + }, + }]; + noKeyword = true; } // 需要子输入框 if (cmd.includes('{{subinput}}')) { @@ -427,7 +515,7 @@ $("#options").on('click', '.saveBtn', function () { features: { "code": code, "explain": desc, - "cmds": kw, + "cmds": cmds, "icon": icon }, program: program, @@ -447,6 +535,10 @@ $("#options").on('click', '.saveBtn', function () { } putCustomFts(code, pushData); showOptions(); + $(`#${code}`).click(); + if (!$(`#${code}`).is(':checked')) { + $(`#${code}`).click(); + } } }) @@ -473,3 +565,16 @@ $("#options").on('change', '#vars', function () { $("#vars").css({'color':'black'}) window.editor.replaceSelection($("#vars").val()); }) + +// 输出选项改变时 +$("#options").on('change', '#output', function () { + resetVars(); + outputCheck(); +}) + + +// 方式选项改变时 +$("#options").on('change', '#type', function () { + resetVars(); + typeCheck(); +})