mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 06:16:27 +08:00
commit
a891952283
105
assets/index.js
105
assets/index.js
@ -7,8 +7,6 @@ utools.onPluginEnter(({ code, type, payload }) => {
|
|||||||
$("#options").show();
|
$("#options").show();
|
||||||
showOptions();
|
showOptions();
|
||||||
} else {
|
} else {
|
||||||
utools.setExpendHeight(0);
|
|
||||||
utools.hideMainWindow();
|
|
||||||
$("#options").hide();
|
$("#options").hide();
|
||||||
$("#out").show();
|
$("#out").show();
|
||||||
var db = utools.db.get('customFts').data[code],
|
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 (type == 'over') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
|
||||||
// 无输出的批处理
|
// 无输出的批处理
|
||||||
if (db.output == 'ignore' && option.ext == 'bat') option.bin = 'explorer';
|
if (db.output == 'ignore' && option.ext == 'bat') option.bin = 'explorer';
|
||||||
// 运行脚本
|
if (db.hasSubInput) {
|
||||||
window.run(cmd, option, db.codec, (stdout, stderr) => {
|
// 启动子命令输入
|
||||||
// 报错
|
// 清空输出
|
||||||
if (stderr) {
|
$("#out").text('');
|
||||||
window.messageBox({ type: 'error', icon: window.logo, message: stderr, buttons: ['纳尼?!'] })
|
var subinput = '';
|
||||||
utools.outPlugin();
|
var setSubInput = () => {
|
||||||
return;
|
utools.setSubInput(({text}) => {
|
||||||
|
subinput = text;
|
||||||
|
}, '');
|
||||||
}
|
}
|
||||||
// 有输出
|
var handleEnter = (event) => {
|
||||||
if (stdout) {
|
if (event.keyCode == 13) {
|
||||||
switch (db.output) {
|
$("#out").text('');
|
||||||
case "ignore":
|
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
||||||
utools.outPlugin();
|
runCmd(execmd, option, db.codec, db.output);
|
||||||
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 {
|
setSubInput();
|
||||||
utools.outPlugin();
|
document.addEventListener('keydown', handleEnter);
|
||||||
}
|
} else {
|
||||||
})
|
utools.setExpendHeight(0);
|
||||||
|
utools.hideMainWindow();
|
||||||
|
runCmd(cmd, option, db.codec, db.output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ putCustomFts = (code, pushData) => {
|
|||||||
var data = {};
|
var data = {};
|
||||||
data[code] = pushData;
|
data[code] = pushData;
|
||||||
utools.db.put({ _id: "customFts", data: data });
|
utools.db.put({ _id: "customFts", data: data });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
importCommand = () => {
|
importCommand = () => {
|
||||||
@ -38,7 +38,7 @@ importCommand = () => {
|
|||||||
} else {
|
} else {
|
||||||
putCustomFts(code, pushData);
|
putCustomFts(code, pushData);
|
||||||
showOptions();
|
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)){
|
||||||
@ -46,7 +46,7 @@ importCommand = () => {
|
|||||||
putCustomFts(code, pushData[code]);
|
putCustomFts(code, pushData[code]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showOptions();
|
showOptions();
|
||||||
} else {
|
} else {
|
||||||
window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] })
|
window.messageBox({ type: 'error', icon: window.logo, message: "格式错误!", buttons: ['朕知道了'] })
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ clearAll = () => {
|
|||||||
window.messageBox({ type: 'question', icon: window.logo, message: "将会清空所有命令,请确认!", buttons: ['手抖...', '确定!'] }, index => {
|
window.messageBox({ type: 'question', icon: window.logo, message: "将会清空所有命令,请确认!", buttons: ['手抖...', '确定!'] }, index => {
|
||||||
if (index) {
|
if (index) {
|
||||||
utools.db.remove('customFts')
|
utools.db.remove('customFts')
|
||||||
showOptions();
|
showOptions();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -90,47 +90,47 @@ programs = {
|
|||||||
cmd: {
|
cmd: {
|
||||||
bin: '',
|
bin: '',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: 'bat'
|
ext: 'bat'
|
||||||
},
|
},
|
||||||
powershell: {
|
powershell: {
|
||||||
bin: 'powershell',
|
bin: 'powershell',
|
||||||
agrv: '-NoProfile -File',
|
agrv: '-NoProfile -File',
|
||||||
ext: 'ps1'
|
ext: 'ps1'
|
||||||
},
|
},
|
||||||
python: {
|
python: {
|
||||||
bin: 'python',
|
bin: 'python',
|
||||||
agrv: '-u',
|
agrv: '-u',
|
||||||
ext: 'py'
|
ext: 'py'
|
||||||
},
|
},
|
||||||
javascript: {
|
javascript: {
|
||||||
bin: 'node',
|
bin: 'node',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: 'js'
|
ext: 'js'
|
||||||
},
|
},
|
||||||
ruby: {
|
ruby: {
|
||||||
bin: 'ruby',
|
bin: 'ruby',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: 'rb'
|
ext: 'rb'
|
||||||
},
|
},
|
||||||
php: {
|
php: {
|
||||||
bin: 'php',
|
bin: 'php',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: 'php'
|
ext: 'php'
|
||||||
},
|
},
|
||||||
lua: {
|
lua: {
|
||||||
bin: 'lua',
|
bin: 'lua',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: 'lua'
|
ext: 'lua'
|
||||||
},
|
},
|
||||||
perl: {
|
perl: {
|
||||||
bin: 'perl',
|
bin: 'perl',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: 'pl'
|
ext: 'pl'
|
||||||
},
|
},
|
||||||
custom: {
|
custom: {
|
||||||
bin: '',
|
bin: '',
|
||||||
agrv: '',
|
agrv: '',
|
||||||
ext: ''
|
ext: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +204,7 @@ showCustomize = () => {
|
|||||||
<option value="{{isWin}}">是否Window系统</option>
|
<option value="{{isWin}}">是否Window系统</option>
|
||||||
<option value="{{HostName}}">本计算机名</option>
|
<option value="{{HostName}}">本计算机名</option>
|
||||||
<option value="{{input}}">主输入框的文本</option>
|
<option value="{{input}}">主输入框的文本</option>
|
||||||
|
<option value="{{subinput}}">子输入框的文本</option>
|
||||||
<option value="{{pwd}}">文件管理器当前目录</option>
|
<option value="{{pwd}}">文件管理器当前目录</option>
|
||||||
<option value="{{ChromeUrl}}">Chrome当前链接</option>
|
<option value="{{ChromeUrl}}">Chrome当前链接</option>
|
||||||
<option value="{{ClipText}}">剪切板的文本</option>
|
<option value="{{ClipText}}">剪切板的文本</option>
|
||||||
@ -295,7 +296,7 @@ $("#options").on('click', '.editBtn', function () {
|
|||||||
} else {
|
} else {
|
||||||
$('#kw').val(data.features.cmds.toString());
|
$('#kw').val(data.features.cmds.toString());
|
||||||
}
|
}
|
||||||
$('#kw').attr('edit', true);
|
$('#kw').attr('edit', true);
|
||||||
$('#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);
|
||||||
@ -307,7 +308,7 @@ $("#options").on('click', '.editBtn', function () {
|
|||||||
if (mode == 'custom') {
|
if (mode == 'custom') {
|
||||||
$('#custombin').show().val(data.customOptions.bin);
|
$('#custombin').show().val(data.customOptions.bin);
|
||||||
$('#customarg').show().val(data.customOptions.args);
|
$('#customarg').show().val(data.customOptions.args);
|
||||||
$('#customext').show().val(data.customOptions.ext);
|
$('#customext').show().val(data.customOptions.ext);
|
||||||
}
|
}
|
||||||
mode == 'applescript' && (mode = 'shell');
|
mode == 'applescript' && (mode = 'shell');
|
||||||
mode == 'cmd' && (mode = 'powershell');
|
mode == 'cmd' && (mode = 'powershell');
|
||||||
@ -336,7 +337,7 @@ $("#options").on('click', '.delBtn', function () {
|
|||||||
data = db.data;
|
data = db.data;
|
||||||
delete data[code];
|
delete data[code];
|
||||||
utools.removeFeature(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();
|
showOptions();
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -372,7 +373,8 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
iconpath = $("#icon").attr('src'),
|
iconpath = $("#icon").attr('src'),
|
||||||
cmd = window.editor.getValue(),
|
cmd = window.editor.getValue(),
|
||||||
icon,
|
icon,
|
||||||
base64ico;
|
base64ico,
|
||||||
|
hasSubInput;
|
||||||
if (!desc) desc = ' ';
|
if (!desc) desc = ' ';
|
||||||
// 自定义了图标的情况下
|
// 自定义了图标的情况下
|
||||||
if (iconame) {
|
if (iconame) {
|
||||||
@ -381,7 +383,7 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
base64ico = window.getBase64Ico(resolve(dirname, iconpath));
|
base64ico = window.getBase64Ico(resolve(dirname, iconpath));
|
||||||
} else {
|
} else {
|
||||||
base64ico = window.getBase64Ico(iconpath);
|
base64ico = window.getBase64Ico(iconpath);
|
||||||
}
|
}
|
||||||
// 未自定义使用默认
|
// 未自定义使用默认
|
||||||
} else {
|
} else {
|
||||||
icon = iconpath;
|
icon = iconpath;
|
||||||
@ -398,6 +400,12 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
} else {
|
} else {
|
||||||
noKeyword = false;
|
noKeyword = false;
|
||||||
}
|
}
|
||||||
|
// 需要子输入框
|
||||||
|
if (cmd.includes('{{subinput}}')) {
|
||||||
|
hasSubInput = true;
|
||||||
|
} else {
|
||||||
|
hasSubInput = false;
|
||||||
|
}
|
||||||
$("#customize").animate({ top: '100%' });
|
$("#customize").animate({ top: '100%' });
|
||||||
// 添加特性
|
// 添加特性
|
||||||
pushData = {
|
pushData = {
|
||||||
@ -412,7 +420,8 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
output: output,
|
output: output,
|
||||||
codec: codec,
|
codec: codec,
|
||||||
base64Ico: base64ico,
|
base64Ico: base64ico,
|
||||||
noKeyword: noKeyword
|
noKeyword: noKeyword,
|
||||||
|
hasSubInput: hasSubInput
|
||||||
}
|
}
|
||||||
if (program == 'custom') {
|
if (program == 'custom') {
|
||||||
pushData.customOptions = {
|
pushData.customOptions = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user