mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
feat: 新增专业模式
This commit is contained in:
parent
6948ffcbbc
commit
07635d68c0
@ -102,8 +102,8 @@
|
|||||||
let Matched = cmd.match(/\{\{MatchedFiles(\[\d+\]){0,1}(\.\w{1,11}){0,1}\}\}/g)
|
let Matched = cmd.match(/\{\{MatchedFiles(\[\d+\]){0,1}(\.\w{1,11}){0,1}\}\}/g)
|
||||||
Matched && Matched.forEach(m => {
|
Matched && Matched.forEach(m => {
|
||||||
repl = eval(m.slice(2, -2))
|
repl = eval(m.slice(2, -2))
|
||||||
typeof repl == 'object' && (repl = JSON.stringify(repl))
|
typeof repl == 'object' ? (repl = JSON.stringify(repl)) : (repl = repl.replace('\\', '\\\\'))
|
||||||
cmd = cmd.replace(m, repl)
|
cmd = cmd.replace(m, repl.replace('$','$$$'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 窗口
|
// 窗口
|
||||||
@ -117,7 +117,9 @@
|
|||||||
// 获取资源管理器或访达当前目录
|
// 获取资源管理器或访达当前目录
|
||||||
if (cmd.includes('{{pwd}}')) {
|
if (cmd.includes('{{pwd}}')) {
|
||||||
repl = getCurrentFolderPathFix();
|
repl = getCurrentFolderPathFix();
|
||||||
|
console.log(repl);
|
||||||
cmd = cmd.replace(/\{\{pwd\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{pwd\}\}/mg, repl)
|
||||||
|
console.log(cmd)
|
||||||
}
|
}
|
||||||
// 获取窗口信息
|
// 获取窗口信息
|
||||||
if (cmd.includes('{{WindowInfo')) {
|
if (cmd.includes('{{WindowInfo')) {
|
||||||
@ -235,6 +237,7 @@
|
|||||||
message(stdout)
|
message(stdout)
|
||||||
break;
|
break;
|
||||||
case "ignore":
|
case "ignore":
|
||||||
|
case "nothing":
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -466,36 +469,60 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let getCmdsType = cmds => {
|
||||||
|
try {
|
||||||
|
JSON.stringify(cmds)
|
||||||
|
} catch (error) {
|
||||||
|
return 'illegal'
|
||||||
|
}
|
||||||
|
if (cmds.length == 0) return 'null'
|
||||||
|
if (cmds.length == 1) {
|
||||||
|
let type = cmds[0].type
|
||||||
|
if (!type) return 'key'
|
||||||
|
if (type == 'window' || cmds[0].minNum) return type
|
||||||
|
return 'professional'
|
||||||
|
}
|
||||||
|
let counts = cmds.filter(x => typeof x == 'string').length
|
||||||
|
return counts == cmds.length ? 'key' : 'professional'
|
||||||
|
}
|
||||||
|
|
||||||
let showCommandByType = features => {
|
let showCommandByType = features => {
|
||||||
let qcType = '', rules = features.cmds[0].match
|
let qcType = ''
|
||||||
if (features.cmds[0].type == 'regex') {
|
let cmds = features.cmds
|
||||||
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
let type = getCmdsType(cmds)
|
||||||
qcType = `<div class="topchild">正则</div><div><span class="keyword re">${rules}</span></div>`;
|
if (type == 'professional') {
|
||||||
} else if (features.cmds[0].type == 'window') {
|
qcType = `<div class="topchild">专业模式</div><div><span class="keyword">[{...}]</span></div>`;
|
||||||
qcType += `<div class="topchild">窗口</div><div>`
|
|
||||||
if (!rules) {
|
|
||||||
qcType += `<span class="keyword win">所有窗口</span>`
|
|
||||||
} else if (rules.title || rules.class) {
|
|
||||||
qcType += `<span class="keyword win">${JSON.stringify(rules).slice(0, 14) + '...'}</span>`;
|
|
||||||
} else if (rules.app) {
|
|
||||||
rules = rules.app.join(",")
|
|
||||||
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
|
||||||
rules.split(',').forEach(r => {
|
|
||||||
qcType += `<span class="keyword win">${r}</span>`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
qcType += `</div>`
|
|
||||||
} else if (features.cmds[0].type == 'files') {
|
|
||||||
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
|
||||||
qcType = `<div class="topchild">文件</div><div><span class="keyword fil">${rules}</span></div>`;
|
|
||||||
} else {
|
} else {
|
||||||
rules = features.cmds.join(",")
|
let rules = cmds[0].match
|
||||||
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
if (type == 'regex') {
|
||||||
qcType += `<div class="topchild">关键字</div><div>`
|
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
||||||
rules.split(',').forEach(r => {
|
qcType = `<div class="topchild">正则</div><div><span class="keyword re">${rules}</span></div>`;
|
||||||
qcType += `<span class="keyword">${r}</span>`;
|
} else if (type == 'window') {
|
||||||
});
|
qcType += `<div class="topchild">窗口</div><div>`
|
||||||
qcType += `</div>`
|
if (!rules) {
|
||||||
|
qcType += `<span class="keyword win">所有窗口</span>`
|
||||||
|
} else if (rules.title || rules.class) {
|
||||||
|
qcType += `<span class="keyword win">${JSON.stringify(rules).slice(0, 14) + '...'}</span>`;
|
||||||
|
} else if (rules.app) {
|
||||||
|
rules = rules.app.join(",")
|
||||||
|
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
||||||
|
rules.split(',').forEach(r => {
|
||||||
|
qcType += `<span class="keyword win">${r}</span>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
qcType += `</div>`
|
||||||
|
} else if (type == 'files') {
|
||||||
|
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
||||||
|
qcType = `<div class="topchild">文件</div><div><span class="keyword fil">${rules}</span></div>`;
|
||||||
|
} else {
|
||||||
|
rules = features.cmds.join(",")
|
||||||
|
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
|
||||||
|
qcType += `<div class="topchild">关键字</div><div>`
|
||||||
|
rules.split(',').forEach(r => {
|
||||||
|
qcType += `<span class="keyword">${r}</span>`;
|
||||||
|
});
|
||||||
|
qcType += `</div>`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return qcType
|
return qcType
|
||||||
}
|
}
|
||||||
@ -628,7 +655,8 @@
|
|||||||
</select>
|
</select>
|
||||||
<span class="word">输 出</span>
|
<span class="word">输 出</span>
|
||||||
<select id="output">
|
<select id="output">
|
||||||
<option value="ignore">隐藏并忽略输出</option>
|
<option value="ignore">忽略输出并隐藏</option>
|
||||||
|
<option value="nothing">忽略输出并保留窗口</option>
|
||||||
<option value="text">显示纯文本输出</option>
|
<option value="text">显示纯文本输出</option>
|
||||||
<option value="html">显示html格式的输出</option>
|
<option value="html">显示html格式的输出</option>
|
||||||
<option value="terminal" id="showInTerm" disabled>在终端显示输出</option>
|
<option value="terminal" id="showInTerm" disabled>在终端显示输出</option>
|
||||||
@ -722,6 +750,11 @@
|
|||||||
id: "files",
|
id: "files",
|
||||||
text: "复制/选中文件",
|
text: "复制/选中文件",
|
||||||
html: "<img src='img/file.svg'><span>复制/选中文件</span><div>匹配拖入主输入框的文件或唤出超级面板时选中的文件,可以获取复制及选中的文件信息作为变量</div>"
|
html: "<img src='img/file.svg'><span>复制/选中文件</span><div>匹配拖入主输入框的文件或唤出超级面板时选中的文件,可以获取复制及选中的文件信息作为变量</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "professional",
|
||||||
|
text: "专业模式",
|
||||||
|
html: "<img src='img/professional.svg'><span>专业模式</span><div>通过json格式的配置实现同时匹配关键字、窗口、文件甚至图片,或者指定文件数量、窗口类等</div>"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -834,6 +867,10 @@
|
|||||||
$(".var.window").prop("disabled", false)
|
$(".var.window").prop("disabled", false)
|
||||||
$("#rule").prop("placeholder", '多个窗口进程逗号隔开,留空匹配所有窗口');
|
$("#rule").prop("placeholder", '多个窗口进程逗号隔开,留空匹配所有窗口');
|
||||||
break;
|
break;
|
||||||
|
case 'professional':
|
||||||
|
$("#ruleWord").html("配 置");
|
||||||
|
$(".var.regex, .var.window, .var.files").prop("disabled", false)
|
||||||
|
$("#rule").prop("placeholder", '等效于 features.cmds');
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -961,7 +998,6 @@
|
|||||||
|
|
||||||
let editCurrentCommand = data => {
|
let editCurrentCommand = data => {
|
||||||
let code = data.features.code
|
let code = data.features.code
|
||||||
let cmds = data.features.cmds[0]
|
|
||||||
let platform = data.features.platform
|
let platform = data.features.platform
|
||||||
let readonly = false
|
let readonly = false
|
||||||
let extraInfo = {
|
let extraInfo = {
|
||||||
@ -974,16 +1010,23 @@
|
|||||||
$('#customize').data('extraInfo', extraInfo)
|
$('#customize').data('extraInfo', extraInfo)
|
||||||
data.tags && $('#tags').val(data.tags).trigger('change')
|
data.tags && $('#tags').val(data.tags).trigger('change')
|
||||||
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
|
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
|
||||||
$('#type').val(cmds.type).trigger("change")
|
let cmds = data.features.cmds
|
||||||
if (cmds.type == 'regex' || cmds.type == 'files') {
|
let type = getCmdsType(cmds)
|
||||||
$('#rule').val(cmds.match);
|
$('#type').val(type).trigger("change")
|
||||||
} else if (cmds.type == 'window') {
|
if (type == 'professional') {
|
||||||
if (!cmds.match) $('#rule').val('');
|
$('#rule').val(JSON.stringify(cmds))
|
||||||
else if (cmds.match.title || cmds.match.class) $('#rule').val(JSON.stringify(cmds.match));
|
|
||||||
else $('#rule').val(cmds.match.app);
|
|
||||||
} else {
|
} else {
|
||||||
$('#type').val('key').trigger("change")
|
cmds = cmds[0]
|
||||||
$('#rule').val(data.features.cmds.toString());
|
if (type == 'regex' || type == 'files') {
|
||||||
|
$('#rule').val(cmds.match);
|
||||||
|
} else if (type == 'window') {
|
||||||
|
if (!cmds.match) $('#rule').val('');
|
||||||
|
else if (cmds.match.title || cmds.match.class) $('#rule').val(JSON.stringify(cmds.match));
|
||||||
|
else $('#rule').val(cmds.match.app);
|
||||||
|
} else {
|
||||||
|
$('#type').val('key').trigger("change")
|
||||||
|
$('#rule').val(data.features.cmds.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$('#code').val(code);
|
$('#code').val(code);
|
||||||
$('#program').val(data.program).trigger("change");
|
$('#program').val(data.program).trigger("change");
|
||||||
@ -1235,7 +1278,9 @@
|
|||||||
.filter(d => {
|
.filter(d => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(d.custom_description).platform.includes(platform)
|
return JSON.parse(d.custom_description).platform.includes(platform)
|
||||||
} catch (error) { }
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.sort((x, y) => {
|
.sort((x, y) => {
|
||||||
if (y.updated_at > x.updated_at) return 1
|
if (y.updated_at > x.updated_at) return 1
|
||||||
@ -1377,6 +1422,12 @@
|
|||||||
"match": rule,
|
"match": rule,
|
||||||
"minNum": 1
|
"minNum": 1
|
||||||
}];
|
}];
|
||||||
|
} else if (type == 'professional') {
|
||||||
|
try {
|
||||||
|
cmds = JSON.parse(rule)
|
||||||
|
} catch (error) {
|
||||||
|
return quickcommand.showMessageBox(`配置的格式有误,请核查!`, 'error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 需要子输入框
|
// 需要子输入框
|
||||||
if (cmd.includes('{{subinput')) {
|
if (cmd.includes('{{subinput')) {
|
||||||
|
@ -224,6 +224,7 @@ body {
|
|||||||
|
|
||||||
#options .logo {
|
#options .logo {
|
||||||
max-width: 40px;
|
max-width: 40px;
|
||||||
|
max-height: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .info {
|
#options .info {
|
||||||
@ -538,7 +539,8 @@ input::-webkit-input-placeholder {
|
|||||||
|
|
||||||
#options #customize #icon {
|
#options #customize #icon {
|
||||||
float: right;
|
float: right;
|
||||||
width: 40px;
|
max-width: 40px;
|
||||||
|
max-height: 40px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +732,7 @@ li.CodeMirror-hint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .select2-results>.select2-results__options {
|
#options #customize .select2-results>.select2-results__options {
|
||||||
max-height: 300px;
|
max-height: 360px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .select2-selection--single:hover,
|
#options #customize .select2-selection--single:hover,
|
||||||
|
1
src/img/professional.svg
Normal file
1
src/img/professional.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path fill="#ffe57f" d="M44,24c0,11.045-8.955,20-20,20S4,35.045,4,24S12.955,4,24,4S44,12.955,44,24"/><path fill="#546e7a" d="M28.941,26.801c0,0-2.582,0-5.164-2.582s-2.582-5.164-2.582-5.164l8.66-8.656c-4.875-1.223-10.762,0.434-14.363,4.035c-5.363,5.367-0.563,12.266-2.039,13.742c-2.24,2.24-4.472,4.326-6.535,6.186c1.668,2.744,3.972,5.049,6.716,6.718c1.932-2.151,4.09-4.472,6.374-6.756c1.398-1.398,8.02,3.719,13.559-1.816c3.602-3.602,5.258-9.488,4.035-14.363L28.941,26.801z"/></svg>
|
After Width: | Height: | Size: 540 B |
Loading…
x
Reference in New Issue
Block a user