mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
新增设置命令支持的平台,新增文件匹配
This commit is contained in:
parent
94a29caa58
commit
6252920efc
@ -185,6 +185,10 @@ let showOptions = (tag = "默认") => {
|
||||
var app = features.cmds[0].match.app
|
||||
if (app.length > 10) app = app.slice(0, 10) + '...';
|
||||
cmds = `<span class="keyword win">窗口: ${app}</span>`;
|
||||
} else if (features.cmds[0].type == 'files') {
|
||||
var app = features.cmds[0].match
|
||||
if (app.length > 10) app = app.slice(0, 10) + '...';
|
||||
cmds = `<span class="keyword fil">文件: ${app}</span>`;
|
||||
} else {
|
||||
features.cmds.forEach(cmd => {
|
||||
cmds += `<span class="keyword">${cmd}</span>`;
|
||||
@ -239,9 +243,10 @@ let showCustomize = () => {
|
||||
<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>
|
||||
<option value="key">通过关键字进入插件</option>
|
||||
<option value="regex">正则匹配主输入框文本</option>
|
||||
<option value="window">窗口匹配</option>
|
||||
<option value="files">文件匹配</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="命令功能的描述">
|
||||
@ -260,15 +265,16 @@ let showCustomize = () => {
|
||||
<span class="word">变 量</span>
|
||||
<select id="vars">
|
||||
<option value="" style="display:none">插入特殊变量</option>
|
||||
<option value="{{isWin}}">是否Window系统</option>
|
||||
<option value="{{isWin}}">是否Window系统, 返回1或0</option>
|
||||
<option value="{{LocalId}}">本机唯一ID</option>
|
||||
<option value="{{input}}" class="var regex">主输入框的文本</option>
|
||||
<option value="{{subinput}}">子输入框的文本</option>
|
||||
<option value="{{pwd}}" class="var window">文件管理器当前目录</option>
|
||||
<option value="{{WindowInfo}}" class="var window">当前窗口信息(JSON格式)</option>
|
||||
<option value="{{WindowInfo}}" class="var window">当前窗口信息,返回JSON格式字符串</option>
|
||||
<option value="{{BrowserUrl}}">浏览器当前链接</option>
|
||||
<option value="{{ClipText}}">剪切板的文本</option>
|
||||
<option value="{{SelectFile}}" class="var window">选中的文件</option>
|
||||
<option value="{{MatchedFiles}}" class="var files">匹配的文件,返回JSON格式字符串</option>
|
||||
<option value="{{SelectFile}}" class="var window">文件管理器选中的文件,不支持Linux</option>
|
||||
</select>
|
||||
<span class="word">输 出</span>
|
||||
<select id="output">
|
||||
@ -298,6 +304,9 @@ let showCustomize = () => {
|
||||
</p>
|
||||
<textarea id="cmd" placeholder="可以直接拖放脚本文件至此处, 支持VSCode快捷键\nAlt+Enter 全屏\nCtrl+B 运行\nCtrl+F 搜索\nShift+Alt+F 格式化(仅JS/PY)"></textarea>
|
||||
<p>
|
||||
<img id="win32" class="platform" src="./img/windows.svg">
|
||||
<img id="darwin" class="platform" src="./img/macos.svg">
|
||||
<img id="linux" class="platform" src="./img/linux.svg">
|
||||
<button class="cmdBtn save">保存</button>
|
||||
<button class="cmdBtn run">运行</button>
|
||||
<button class="cmdBtn cancel">取消</button>
|
||||
@ -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
|
||||
|
1
src/img/linux.svg
Normal file
1
src/img/linux.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 2 48 48"><path fill="#ECEFF1" d="M20.1 18.2L20.2 20.5 18.6 23.5 16.1 28.4 15.6 32.5 17.4 38.3 21.5 40.6 27.7 40.6 33.5 36.2 36.1 29.3 30.1 22 28.4 17.9z"/><path fill="#263238" d="M34.3,23.9c-1.6-2.3-2.9-3.7-3.6-6.6c-0.7-2.9,0.2-2.1-0.4-4.6c-0.3-1.3-0.8-2.2-1.3-2.9c-0.6-0.7-1.3-1.1-1.7-1.2c-0.9-0.5-3-1.3-5.6,0.1c-2.7,1.4-2.4,4.4-1.9,10.5c0,0.4-0.1,0.9-0.3,1.3c-0.4,0.9-1.1,1.7-1.7,2.4c-0.7,1-1.4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.1.1C20.6 18.7 20.7 18.8 20.9 19zM23.9 16.8c.1.2.3.2.4.3.1.1.2.1.2.1.1-.1 0-.3-.1-.3C24.4 16.7 23.9 16.7 23.9 16.8zM22.3 17c0 .1.2.2.2.1.1-.1.2-.2.3-.2.2-.1.1-.2-.2-.2C22.4 16.8 22.4 16.9 22.3 17z"/></g><path fill="#455A64" d="M32,34.7c0,0.1,0,0.2,0,0.3c0.2,0.4,0.7,0.5,1.1,0.5c0.6,0,1.2-0.4,1.5-0.8c0-0.1,0.1-0.2,0.2-0.3c0.2-0.3,0.3-0.5,0.4-0.6c0,0-0.1-0.1-0.1-0.2c-0.1-0.2-0.4-0.4-0.8-0.5c-0.3-0.1-0.8-0.2-1-0.2c-0.9-0.1-1.4,0.2-1.7,0.5c0,0,0.1,0,0.1,0.1c0.2,0.2,0.3,0.4,0.3,0.7C32.1,34.4,32,34.5,32,34.7z"/></svg>
|
After Width: | Height: | Size: 3.1 KiB |
1
src/img/macos.svg
Normal file
1
src/img/macos.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path fill="#42A5F5" d="M40.084,32.613c-0.848,1.835-1.254,2.655-2.342,4.274c-1.521,2.264-3.67,5.089-6.326,5.109c-2.361,0.018-2.971-1.507-6.176-1.482c-3.204,0.016-3.872,1.51-6.237,1.484c-2.654-0.022-4.688-2.568-6.21-4.826c-4.259-6.34-4.707-13.768-2.076-17.721c1.861-2.803,4.807-4.449,7.572-4.449c2.817,0,4.588,1.514,6.916,1.514c2.262,0,3.638-1.517,6.896-1.517c2.464,0,5.07,1.313,6.931,3.575C32.942,21.836,33.931,30.337,40.084,32.613z"/><path fill="#42A5F5" d="M30.046,12.072c1.269-1.577,2.232-3.804,1.882-6.072c-2.069,0.138-4.491,1.418-5.905,3.075c-1.282,1.51-2.345,3.752-1.931,5.922C26.351,15.066,28.689,13.764,30.046,12.072z"/><path fill="#1E88E5" d="M36.736,20.421C28,30.001,20,21.001,9.228,27.842c0.375,3.027,1.53,6.303,3.565,9.331c1.521,2.258,3.556,4.804,6.21,4.826c2.365,0.025,3.033-1.469,6.237-1.484c3.205-0.024,3.814,1.5,6.176,1.482c2.656-0.021,4.805-2.846,6.326-5.109c1.088-1.619,1.494-2.439,2.342-4.274C34.878,30.688,33.389,24.314,36.736,20.421z"/></svg>
|
After Width: | Height: | Size: 1.0 KiB |
1
src/img/windows.svg
Normal file
1
src/img/windows.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path fill="#03A9F4" d="M20 25L6 25 6 37.073 20 38.994zM20 9.101L6 11.066 6 23 20 23zM22 8.82L22 23 42 23 42 6.012zM22 25L22 39.268 42 42.012 42 25z"/></svg>
|
After Width: | Height: | Size: 240 B |
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
x
Reference in New Issue
Block a user