mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 06:54:11 +08:00
新增通过uTools呼出前的窗口匹配的模式
This commit is contained in:
parent
2f0e8d2be6
commit
3588abc85e
@ -18,6 +18,7 @@ putCustomFts = (code, pushData) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 导入
|
||||||
importCommand = () => {
|
importCommand = () => {
|
||||||
var options = {
|
var options = {
|
||||||
filters: [{ name: 'json', extensions: ['json'] }, ]
|
filters: [{ name: 'json', extensions: ['json'] }, ]
|
||||||
@ -31,20 +32,16 @@ importCommand = () => {
|
|||||||
window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] })
|
window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 单个命令导入
|
||||||
if (typeof(pushData.features)=='object') {
|
if (typeof(pushData.features)=='object') {
|
||||||
var code = basename(file, '.json');
|
var code = pushData.features.code;
|
||||||
if (code in customFts) {
|
putCustomFts(code, pushData);
|
||||||
window.messageBox({ type: 'error', icon: window.logo, message: "命令名称重复, 请先修改文件名再导入!", buttons: ['朕知道了'] })
|
showOptions();
|
||||||
} else {
|
// 多个命令导入
|
||||||
putCustomFts(code, pushData);
|
|
||||||
showOptions();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (typeof (Object.values(pushData)[0].features) == 'object') {
|
if (typeof (Object.values(pushData)[0].features) == 'object') {
|
||||||
for (var code of Object.keys(pushData)){
|
for (var code of Object.keys(pushData)){
|
||||||
if (!(code in customFts)) {
|
putCustomFts(code, pushData[code]);
|
||||||
putCustomFts(code, pushData[code]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
showOptions();
|
showOptions();
|
||||||
} else {
|
} else {
|
||||||
@ -137,12 +134,14 @@ programs = {
|
|||||||
showOptions = () => {
|
showOptions = () => {
|
||||||
var currentFts = utools.getFeatures(),
|
var currentFts = utools.getFeatures(),
|
||||||
customFts = getCustomFts();
|
customFts = getCustomFts();
|
||||||
let featureList = '<table><tr><td></td><td>关键字</td><td>说明</td><td>启用</td></tr>';
|
let featureList = '<table><tr><td></td><td>模式</td><td>说明</td><td>启用</td></tr>';
|
||||||
for (var fts in customFts) {
|
for (var fts in customFts) {
|
||||||
let features = customFts[fts].features;
|
let features = customFts[fts].features;
|
||||||
var cmds = '';
|
var cmds = '';
|
||||||
if (customFts[fts].noKeyword) {
|
if (features.cmds[0].type == 'regex') {
|
||||||
cmds = '<span class="keyword">匹配主输入框文本进入</span>';
|
cmds = `<span class="keyword re">正则: ${features.cmds[0].match}</span>`;
|
||||||
|
} else if (features.cmds[0].type == 'window') {
|
||||||
|
cmds = `<span class="keyword win">窗口: ${features.cmds[0].match.app}</span>`;
|
||||||
} else {
|
} else {
|
||||||
features.cmds.forEach(cmd => {
|
features.cmds.forEach(cmd => {
|
||||||
cmds += `<span class="keyword">${cmd}</span>`;
|
cmds += `<span class="keyword">${cmd}</span>`;
|
||||||
@ -161,7 +160,7 @@ showOptions = () => {
|
|||||||
window.messageBox({ type: 'error', icon: window.logo, message: e.toString(), buttons: ['啊嘞?!'] })
|
window.messageBox({ type: 'error', icon: window.logo, message: e.toString(), buttons: ['啊嘞?!'] })
|
||||||
}
|
}
|
||||||
featureList += `<tr><td><img class="logo" src="${iconpath}"></td>
|
featureList += `<tr><td><img class="logo" src="${iconpath}"></td>
|
||||||
<td>${cmds}</td><td width="300px">${features.explain}</td><td>
|
<td><div class="cmds">${cmds}</div></td><td width="300px">${features.explain}</td><td>
|
||||||
<label class="switch-btn">
|
<label class="switch-btn">
|
||||||
<input class="checked-switch" id="${features.code}" type="checkbox" ${isChecked}>
|
<input class="checked-switch" id="${features.code}" type="checkbox" ${isChecked}>
|
||||||
<span class="text-switch"></span>
|
<span class="text-switch"></span>
|
||||||
@ -187,7 +186,14 @@ showCustomize = () => {
|
|||||||
$("#customize").remove();
|
$("#customize").remove();
|
||||||
let options = `<option>${Object.keys(programs).join('</option><option>')}</option>`
|
let options = `<option>${Object.keys(programs).join('</option><option>')}</option>`
|
||||||
customWindow = `<div id="customize">
|
customWindow = `<div id="customize">
|
||||||
<p><span class="word">关键字</span><input type="text" id="kw" placeholder="多个关键字用逗号隔开"></p>
|
<p><input type="text" id="code" style="display: none">
|
||||||
|
<span class="word">模 式</span>
|
||||||
|
<select id="type">
|
||||||
|
<option value="key">通过输入关键字进入插件</option>
|
||||||
|
<option value="regex">通过正则匹配主输入框文本</option>
|
||||||
|
<option value="window">通过呼出uTools前的活动窗口匹配</option>
|
||||||
|
</select>
|
||||||
|
<span class="word" id="ruleWord">关键字</span><input type="text" id="rule" placeholder="多个关键字用逗号隔开"></p>
|
||||||
<p><span class="word">说 明</span><input type="text" id="desc" placeholder="命令功能的描述"></p>
|
<p><span class="word">说 明</span><input type="text" id="desc" placeholder="命令功能的描述"></p>
|
||||||
<p>
|
<p>
|
||||||
<span class="word">类 型</span>
|
<span class="word">类 型</span>
|
||||||
@ -202,14 +208,15 @@ showCustomize = () => {
|
|||||||
<select id="vars">
|
<select id="vars">
|
||||||
<option value="" style="display:none">插入特殊变量</option>
|
<option value="" style="display:none">插入特殊变量</option>
|
||||||
<option value="{{isWin}}">是否Window系统</option>
|
<option value="{{isWin}}">是否Window系统</option>
|
||||||
<option value="{{HostName}}">本计算机名</option>
|
<option value="{{LocalId()}}">本机唯一ID</option>
|
||||||
<option value="{{input}}">主输入框的文本</option>
|
<option value="{{input}}" class="var regex">主输入框的文本</option>
|
||||||
<option value="{{subinput}}">子输入框的文本</option>
|
<option value="{{subinput}}">子输入框的文本</option>
|
||||||
<option value="{{pwd}}">文件管理器当前目录</option>
|
<option value="{{pwd}}" class="var window">文件管理器当前目录</option>
|
||||||
|
<option value="{{WindowInfo}}" class="var window">当前窗口信息(JSON格式)</option>
|
||||||
<option value="{{BrowserUrl}}">浏览器当前链接</option>
|
<option value="{{BrowserUrl}}">浏览器当前链接</option>
|
||||||
<option value="{{ClipText}}">剪切板的文本</option>
|
<option value="{{ClipText}}">剪切板的文本</option>
|
||||||
aa<option value="{{SelectText}}">选中的文本</option>
|
aa<option value="{{SelectText}}" class="selectText">选中的文本</option>
|
||||||
<option value="{{SelectFile}}">选中的文件</option>
|
<option value="{{SelectFile}}" class="var window">选中的文件</option>
|
||||||
</select>
|
</select>
|
||||||
<span class="word">输 出</span>
|
<span class="word">输 出</span>
|
||||||
<select id="output">
|
<select id="output">
|
||||||
@ -254,6 +261,49 @@ showCustomize = () => {
|
|||||||
$("#customize").animate({ top: '0px' });
|
$("#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 () {
|
$("#options").on('change', 'input[type=checkbox]', function () {
|
||||||
var customFts = getCustomFts(),
|
var customFts = getCustomFts(),
|
||||||
@ -291,14 +341,18 @@ $("#options").on('click', '.editBtn', function () {
|
|||||||
var code = $(this).attr('code');
|
var code = $(this).attr('code');
|
||||||
var data = utools.db.get("customFts").data[code];
|
var data = utools.db.get("customFts").data[code];
|
||||||
showCustomize();
|
showCustomize();
|
||||||
// 判断是通过关键词进入还是主输入框进入
|
var cmds = data.features.cmds[0]
|
||||||
if (data.noKeyword) {
|
if (cmds.type == 'regex') {
|
||||||
$('#kw').val(data.features.code);
|
$('#type').val('regex')
|
||||||
$('#kw').prop('disabled', true);
|
$('#rule').val(cmds.match);
|
||||||
|
} else if (cmds.type == 'window') {
|
||||||
|
$('#type').val('window')
|
||||||
|
$('#rule').val(cmds.match.app);
|
||||||
} else {
|
} 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);
|
$('#program').val(data.program);
|
||||||
$('#output').val(data.output);
|
$('#output').val(data.output);
|
||||||
$('#desc').val(data.features.explain);
|
$('#desc').val(data.features.explain);
|
||||||
@ -316,6 +370,9 @@ $("#options").on('click', '.editBtn', function () {
|
|||||||
mode == 'cmd' && (mode = 'powershell');
|
mode == 'cmd' && (mode = 'powershell');
|
||||||
window.editor.setOption("mode", mode);
|
window.editor.setOption("mode", mode);
|
||||||
window.editor.setValue(data.cmd);
|
window.editor.setValue(data.cmd);
|
||||||
|
resetVars();
|
||||||
|
typeCheck();
|
||||||
|
outputCheck();
|
||||||
})
|
})
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
@ -324,7 +381,6 @@ $("#options").on('click', '.exportBtn', function () {
|
|||||||
json = getCustomFts()[code],
|
json = getCustomFts()[code],
|
||||||
options = {
|
options = {
|
||||||
title: '选择保存位置',
|
title: '选择保存位置',
|
||||||
defaultPath: code,
|
|
||||||
filters: [
|
filters: [
|
||||||
{ name: 'json', extensions: ['json'] },
|
{ name: 'json', extensions: ['json'] },
|
||||||
]
|
]
|
||||||
@ -359,30 +415,48 @@ $("#options").on('click', '#icon, #iconame', function () {
|
|||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
$("#options").on('click', '.saveBtn', function () {
|
$("#options").on('click', '.saveBtn', function () {
|
||||||
var code = $('#kw').val().split(',')[0].trim()
|
var type = $('#type').val();
|
||||||
var customFts = getCustomFts(),
|
var code = $("#code").val();
|
||||||
output = $('#output').val(),
|
if (!code) {
|
||||||
cmd = window.editor.getValue();
|
// 生成唯一code
|
||||||
// 如果 code 重复, 编辑状态下不检测
|
var uid = Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36);
|
||||||
if (code in customFts && !$('#kw').attr('edit')) {
|
var code = `${type}_${uid}`;
|
||||||
$('#kw').css({ 'border-bottom-color': '#ec1212' })
|
}
|
||||||
|
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({
|
window.messageBox({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
icon: window.logo,
|
icon: window.logo,
|
||||||
message: "命令名称重复!",
|
message: "关键字模式无法使用{{input}}、{{SelectFile}}、{{WindowInfo}}、{{pwd}}!",
|
||||||
buttons: ['朕知道了']
|
buttons: ['朕知道了']
|
||||||
})
|
})
|
||||||
} else if (['text', 'html'].includes($('#output').val())
|
} else if (type == 'regex'
|
||||||
&& ['{{SelectText}}', '{{SelectFile}}', '{{pwd}}'].map(x => cmd.includes(x)).includes(true)) {
|
&& ['{{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({
|
window.messageBox({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
icon: window.logo,
|
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: ['朕知道了']
|
buttons: ['朕知道了']
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var kw = $('#kw').val().split(','),
|
var program = $('#program').val(),
|
||||||
program = $('#program').val(),
|
|
||||||
desc = $('#desc').val(),
|
desc = $('#desc').val(),
|
||||||
codec = $('#codec').val(),
|
codec = $('#codec').val(),
|
||||||
iconame = $("#iconame").val(),
|
iconame = $("#iconame").val(),
|
||||||
@ -404,16 +478,30 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
icon = iconpath;
|
icon = iconpath;
|
||||||
base64ico = '';
|
base64ico = '';
|
||||||
}
|
}
|
||||||
// 通过主输入框直接进入
|
var noKeyword;
|
||||||
if (cmd.includes('{{input}}')) {
|
var rule = $('#rule').val();
|
||||||
kw = [{
|
if (type == 'key') {
|
||||||
|
cmds = rule.split(',')
|
||||||
|
noKeyword = false;
|
||||||
|
}
|
||||||
|
if (type == 'regex') {
|
||||||
|
cmds = [{
|
||||||
"label": desc,
|
"label": desc,
|
||||||
"type": "over",
|
"type": "regex",
|
||||||
|
"match": rule,
|
||||||
"minNum": 1
|
"minNum": 1
|
||||||
}];
|
}];
|
||||||
noKeyword = true;
|
noKeyword = true;
|
||||||
} else {
|
}
|
||||||
noKeyword = false;
|
if (type == 'window') {
|
||||||
|
cmds = [{
|
||||||
|
"label": desc,
|
||||||
|
"type": "window",
|
||||||
|
"match": {
|
||||||
|
"app": rule
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
noKeyword = true;
|
||||||
}
|
}
|
||||||
// 需要子输入框
|
// 需要子输入框
|
||||||
if (cmd.includes('{{subinput}}')) {
|
if (cmd.includes('{{subinput}}')) {
|
||||||
@ -427,7 +515,7 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
features: {
|
features: {
|
||||||
"code": code,
|
"code": code,
|
||||||
"explain": desc,
|
"explain": desc,
|
||||||
"cmds": kw,
|
"cmds": cmds,
|
||||||
"icon": icon
|
"icon": icon
|
||||||
},
|
},
|
||||||
program: program,
|
program: program,
|
||||||
@ -447,6 +535,10 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
}
|
}
|
||||||
putCustomFts(code, pushData);
|
putCustomFts(code, pushData);
|
||||||
showOptions();
|
showOptions();
|
||||||
|
$(`#${code}`).click();
|
||||||
|
if (!$(`#${code}`).is(':checked')) {
|
||||||
|
$(`#${code}`).click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -473,3 +565,16 @@ $("#options").on('change', '#vars', function () {
|
|||||||
$("#vars").css({'color':'black'})
|
$("#vars").css({'color':'black'})
|
||||||
window.editor.replaceSelection($("#vars").val());
|
window.editor.replaceSelection($("#vars").val());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 输出选项改变时
|
||||||
|
$("#options").on('change', '#output', function () {
|
||||||
|
resetVars();
|
||||||
|
outputCheck();
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// 方式选项改变时
|
||||||
|
$("#options").on('change', '#type', function () {
|
||||||
|
resetVars();
|
||||||
|
typeCheck();
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user