mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 22:51:25 +08:00
增加模拟按键的功能
This commit is contained in:
parent
01697fb9c3
commit
54a976f112
69
src/assets/index.js
Executable file → Normal file
69
src/assets/index.js
Executable file → Normal file
@ -10,18 +10,14 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
$("#out").show().text('');
|
$("#out").show().text('');
|
||||||
var db = utools.db.get('customFts').data[code],
|
var db = utools.db.get('customFts').data[code],
|
||||||
cmd = db.cmd;
|
cmd = db.cmd;
|
||||||
if (db.robotjs) {
|
|
||||||
utools.setExpendHeight(0);
|
|
||||||
utools.hideMainWindow();
|
|
||||||
eval(cmd);
|
|
||||||
utools.outPlugin();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (db.program == "custom") {
|
if (db.program == "custom") {
|
||||||
option = db.customOptions;
|
option = db.customOptions;
|
||||||
} else {
|
} else if(db.program == "simulation"){
|
||||||
|
option = "simulation";
|
||||||
|
}else{
|
||||||
option = programs[db.program];
|
option = programs[db.program];
|
||||||
}
|
}
|
||||||
|
cmd = await special(cmd);
|
||||||
// 正则
|
// 正则
|
||||||
if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
|
if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
|
||||||
// 窗口
|
// 窗口
|
||||||
@ -58,7 +54,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
$("#out").text('');
|
$("#out").text('');
|
||||||
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
||||||
runCmd(execmd, option, db.codec, db.output);
|
runCmd(execmd, option, db.output);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
setSubInput();
|
setSubInput();
|
||||||
@ -68,40 +64,47 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
document.removeEventListener('keydown', handleEnter);
|
document.removeEventListener('keydown', handleEnter);
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
runCmd(cmd, option, db.codec, db.output);
|
runCmd(cmd, option, db.output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function runCmd(cmd, option, codec, output) {
|
function runCmd(cmd, option, output) {
|
||||||
|
if (option == "simulation") {
|
||||||
|
utools.setExpendHeight(0);
|
||||||
|
// utools.hideMainWindow();
|
||||||
|
eval(`(async () => {
|
||||||
|
${cmd}
|
||||||
|
})()`);
|
||||||
|
utools.outPlugin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 不需要输出的,提前关闭窗口
|
// 不需要输出的,提前关闭窗口
|
||||||
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
||||||
utools.hideMainWindow()
|
utools.setExpendHeight(0);
|
||||||
|
utools.outPlugin();
|
||||||
|
// utools.hideMainWindow();
|
||||||
}
|
}
|
||||||
var terminal = false;
|
var terminal = false;
|
||||||
if(output == 'terminal') terminal = true;
|
if(output == 'terminal') terminal = true;
|
||||||
// 运行脚本
|
// 运行脚本
|
||||||
window.run(cmd, option, codec, terminal, (stdout, stderr) => {
|
window.run(cmd, option, terminal, (stdout, stderr) => {
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
// 报错
|
// 报错
|
||||||
utools.showMainWindow()
|
messageBox({
|
||||||
Swal.fire({
|
type: 'error',
|
||||||
title: '啊嘞?!',
|
title: '啊嘞?!',
|
||||||
text: stderr,
|
icon: window.logo,
|
||||||
icon: 'error',
|
message: stderr,
|
||||||
showCancelButton: true,
|
buttons: ['转至脚本目录', '退出']
|
||||||
confirmButtonColor: '#3085d6',
|
}, index => {
|
||||||
cancelButtonColor: '#d33',
|
if (index == 0) {
|
||||||
confirmButtonText: '转至脚本目录',
|
locate(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
||||||
cancelButtonText: '退出',
|
}
|
||||||
}).then((result) => {
|
copyTo(stderr);
|
||||||
if (result.value) {
|
message("已复制报错信息");
|
||||||
open(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
utools.outPlugin();
|
||||||
}
|
})
|
||||||
copyTo(stderr);
|
|
||||||
utools.showNotification("已复制报错信息");
|
|
||||||
utools.outPlugin();
|
|
||||||
})
|
|
||||||
} else if (stdout) {
|
} else if (stdout) {
|
||||||
// 有输出
|
// 有输出
|
||||||
switch (output) {
|
switch (output) {
|
||||||
@ -113,7 +116,6 @@ function runCmd(cmd, option, codec, output) {
|
|||||||
break;
|
break;
|
||||||
case "clip":
|
case "clip":
|
||||||
copyTo(stdout);
|
copyTo(stdout);
|
||||||
utools.outPlugin();
|
|
||||||
break;
|
break;
|
||||||
case "send":
|
case "send":
|
||||||
// 暂存用户剪贴板
|
// 暂存用户剪贴板
|
||||||
@ -123,15 +125,12 @@ function runCmd(cmd, option, codec, output) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
restoreClip(historyData);
|
restoreClip(historyData);
|
||||||
}, 500);
|
}, 500);
|
||||||
utools.outPlugin();
|
|
||||||
break;
|
break;
|
||||||
case "notice":
|
case "notice":
|
||||||
// 发送系统通知
|
// 发送系统通知
|
||||||
utools.showNotification(stdout);
|
message(stdout);
|
||||||
utools.outPlugin();
|
|
||||||
break;
|
break;
|
||||||
case "ignore":
|
case "ignore":
|
||||||
utools.outPlugin();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
15
src/assets/options.css
Executable file → Normal file
15
src/assets/options.css
Executable file → Normal file
@ -180,18 +180,10 @@
|
|||||||
color: rgb(48, 21, 122);
|
color: rgb(48, 21, 122);
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .keyword.key {
|
|
||||||
color: rgb(122, 115, 21);
|
|
||||||
}
|
|
||||||
|
|
||||||
#options .logo {
|
#options .logo {
|
||||||
width: 32px;
|
width: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .robot{
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#options #customize .keys{
|
#options #customize .keys{
|
||||||
width: 10%;
|
width: 10%;
|
||||||
}
|
}
|
||||||
@ -291,6 +283,7 @@
|
|||||||
|
|
||||||
#options #customize {
|
#options #customize {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
z-index: 999;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
top: 100%;
|
top: 100%;
|
||||||
left: 0;
|
left: 0;
|
||||||
@ -301,6 +294,10 @@
|
|||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#options .varoutput{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
#options #customize p {
|
#options #customize p {
|
||||||
line-height: 1.25rem;
|
line-height: 1.25rem;
|
||||||
}
|
}
|
||||||
@ -399,7 +396,7 @@ input::-webkit-input-placeholder {
|
|||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize select#vars {
|
#options #customize select#vars,#action {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
198
src/assets/options.js
Executable file → Normal file
198
src/assets/options.js
Executable file → Normal file
@ -149,9 +149,10 @@ programs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showOptions = () => {
|
showOptions = () => {
|
||||||
|
$("#featureList").remove();
|
||||||
var currentFts = utools.getFeatures(),
|
var currentFts = utools.getFeatures(),
|
||||||
customFts = getCustomFts();
|
customFts = getCustomFts();
|
||||||
let featureList = '<table><tr><td width="40"></td><td width="240">模式</td><td width="270">说明</td><td>启用</td></tr>';
|
let featureList = '<div id="featureList"><table><tr><td width="40"></td><td width="240">模式</td><td width="270">说明</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 = '';
|
||||||
@ -162,11 +163,7 @@ showOptions = () => {
|
|||||||
} else if (features.cmds[0].type == 'window') {
|
} else if (features.cmds[0].type == 'window') {
|
||||||
var app = features.cmds[0].match.app
|
var app = features.cmds[0].match.app
|
||||||
if (app.length > 15) app = app.slice(0, 15) + '...';
|
if (app.length > 15) app = app.slice(0, 15) + '...';
|
||||||
if (customFts[fts].robotjs) {
|
cmds = `<span class="keyword win">窗口: ${app}</span>`;
|
||||||
cmds = `<span class="keyword key">按键: ${app}</span>`;
|
|
||||||
} else {
|
|
||||||
cmds = `<span class="keyword win">窗口: ${app}</span>`;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
features.cmds.forEach(cmd => {
|
features.cmds.forEach(cmd => {
|
||||||
cmds += `<span class="keyword">${cmd}</span>`;
|
cmds += `<span class="keyword">${cmd}</span>`;
|
||||||
@ -199,8 +196,8 @@ showOptions = () => {
|
|||||||
<div id="disableAll" class="footBtn danger">全部禁用</div>
|
<div id="disableAll" class="footBtn danger">全部禁用</div>
|
||||||
<div id="enableAll" class="footBtn">全部启用</div>
|
<div id="enableAll" class="footBtn">全部启用</div>
|
||||||
<div id="sample" class="footBtn">下载命令</div>
|
<div id="sample" class="footBtn">下载命令</div>
|
||||||
</div>`
|
</div></div>`
|
||||||
$("#options").html(featureList);
|
$("#options").append(featureList);
|
||||||
}
|
}
|
||||||
|
|
||||||
showCustomize = () => {
|
showCustomize = () => {
|
||||||
@ -213,19 +210,19 @@ showCustomize = () => {
|
|||||||
<option value="key">通过输入关键字进入插件</option>
|
<option value="key">通过输入关键字进入插件</option>
|
||||||
<option value="regex">通过正则匹配主输入框文本</option>
|
<option value="regex">通过正则匹配主输入框文本</option>
|
||||||
<option value="window">通过呼出uTools前的活动窗口匹配</option>
|
<option value="window">通过呼出uTools前的活动窗口匹配</option>
|
||||||
<option value="robotjs">匹配窗口后模拟按键</option>
|
|
||||||
</select>
|
</select>
|
||||||
<span class="word" id="ruleWord">关键字</span><input type="text" id="rule" placeholder="多个关键字用逗号隔开"></p>
|
<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>
|
||||||
<select id="program">
|
<select id="program">
|
||||||
|
<option value="simulation">模拟操作</option>
|
||||||
${options}
|
${options}
|
||||||
</select>
|
</select>
|
||||||
<span class="word">图 标</span><input type="text" readonly id="iconame" placeholder="更改图标">
|
<span class="word">图 标</span><input type="text" readonly id="iconame" placeholder="更改图标">
|
||||||
<img id="icon" src="">
|
<img id="icon" src="">
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p class="varoutput">
|
||||||
<span class="word">变 量</span>
|
<span class="word">变 量</span>
|
||||||
<select id="vars">
|
<select id="vars">
|
||||||
<option value="" style="display:none">插入特殊变量</option>
|
<option value="" style="display:none">插入特殊变量</option>
|
||||||
@ -251,9 +248,8 @@ showCustomize = () => {
|
|||||||
<option value="terminal">在终端显示</option>
|
<option value="terminal">在终端显示</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p class="simulation">
|
||||||
<span class="word">脚 本</span>
|
<span class="word">操 作</span>
|
||||||
<span>
|
|
||||||
<select id="modifier1" class="robot keys">
|
<select id="modifier1" class="robot keys">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<option value="control">control</option>
|
<option value="control">control</option>
|
||||||
@ -268,15 +264,28 @@ showCustomize = () => {
|
|||||||
<option value="shift">shift</option>
|
<option value="shift">shift</option>
|
||||||
<option value="command">⌘/win</option>
|
<option value="command">⌘/win</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="text" id="presskey" class="robot keys" placeholder="按键">
|
<input type="text" id="presskey" class="robot keys" placeholder="模拟按键">
|
||||||
<span id="addKey" class="robot footBtn">添加</span>
|
<span id="addKey" class="robot footBtn">﹢按键</span>
|
||||||
<input type="text" id="keydelay" class="robot keys" placeholder="延时">
|
<input type="text" id="keydelay" class="robot keys" placeholder="等待时间">
|
||||||
<span id="addDelay" class="robot footBtn">添加</span>
|
<span id="addDelay" class="robot footBtn">﹢延时</span>
|
||||||
</span>
|
<select id="action" class="robot keys">
|
||||||
|
<option value="" style="display:none">预设动作</option>
|
||||||
|
<option value="open">打开文件</option>
|
||||||
|
<option value="visit">打开网址</option>
|
||||||
|
<option value="locate">定位文件</option>
|
||||||
|
<option value="system">执行命令</option>
|
||||||
|
<option value="copyTo">写剪贴板</option>
|
||||||
|
<option value="message">系统消息</option>
|
||||||
|
<option value="alert">弹窗显示</option>
|
||||||
|
</select>
|
||||||
|
<span id="addAction" class="robot footBtn">﹢动作</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="word">脚 本</span>
|
||||||
<span>
|
<span>
|
||||||
<input type="text" id="custombin" class="customscript" placeholder="解释器绝对路径">
|
<input type="text" id="custombin" class="customscript" placeholder="解释器绝对路径">
|
||||||
<input type="text" id="customarg" class="customscript" placeholder="参数">
|
<input type="text" id="customarg" class="customscript" placeholder="参数">
|
||||||
<input type="text" id="customext" class="customscript" placeholder="脚本后缀,不含.">
|
<input type="text" id="customext" class="customscript" placeholder="脚本后缀,不含.">
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p><textarea id="cmd" placeholder="可以直接拖放脚本文件至此处"></textarea></p>
|
<p><textarea id="cmd" placeholder="可以直接拖放脚本文件至此处"></textarea></p>
|
||||||
@ -285,20 +294,12 @@ showCustomize = () => {
|
|||||||
<button class="cancelBtn">取消</button>
|
<button class="cancelBtn">取消</button>
|
||||||
</p>`
|
</p>`
|
||||||
$("#options").append(customWindow)
|
$("#options").append(customWindow)
|
||||||
if (window.isWin) {
|
$("#icon").attr('src', 'logo/simulation.png');
|
||||||
var shell = 'cmd',
|
|
||||||
mode = 'powershell';
|
|
||||||
} else {
|
|
||||||
var shell = 'shell',
|
|
||||||
mode = 'shell';
|
|
||||||
}
|
|
||||||
$("#program").val(shell);
|
|
||||||
$("#icon").attr('src', `logo/${shell}.png`);
|
|
||||||
window.editor = CodeMirror.fromTextArea(document.getElementById("cmd"), {
|
window.editor = CodeMirror.fromTextArea(document.getElementById("cmd"), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
lineWrapping: true
|
lineWrapping: true
|
||||||
});
|
});
|
||||||
window.editor.setOption("mode", mode);
|
window.editor.setOption("mode", 'javascript');
|
||||||
$("#customize").animate({ top: '0px' });
|
$("#customize").animate({ top: '0px' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +322,10 @@ outputCheck = () => {
|
|||||||
// 检查模式选项
|
// 检查模式选项
|
||||||
typeCheck = () => {
|
typeCheck = () => {
|
||||||
var type = $("#type").val();
|
var type = $("#type").val();
|
||||||
$("#output, #program, #vars").prop("disabled", false);
|
// $("#output, #program, #vars").prop("disabled", false);
|
||||||
$(".robot").hide()
|
// $('.varoutput').show()
|
||||||
|
// $(".simulation").hide()
|
||||||
|
// $("#program").prop("disabled", false)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'key':
|
case 'key':
|
||||||
$("#ruleWord").html("关键字");
|
$("#ruleWord").html("关键字");
|
||||||
@ -336,14 +339,6 @@ typeCheck = () => {
|
|||||||
$(".var.window").hide()
|
$(".var.window").hide()
|
||||||
$("#rule").prop("placeholder", '匹配的正则规则,如/\\w+/i');
|
$("#rule").prop("placeholder", '匹配的正则规则,如/\\w+/i');
|
||||||
break;
|
break;
|
||||||
case 'robotjs':
|
|
||||||
$("#ruleWord").html("进 程");
|
|
||||||
$("#output, #program, #vars").prop("disabled", true).val('');
|
|
||||||
$("#rule").prop("placeholder", '窗口的进程名,支持正则,如explorer.exe');
|
|
||||||
$(".robot").show();
|
|
||||||
$('.customscript').hide();
|
|
||||||
window.editor.setOption("mode", 'javascript');
|
|
||||||
break;
|
|
||||||
case 'window':
|
case 'window':
|
||||||
$("#ruleWord").html("进 程");
|
$("#ruleWord").html("进 程");
|
||||||
$(".var.regex").hide()
|
$(".var.regex").hide()
|
||||||
@ -400,13 +395,12 @@ $("#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 robotjs = data.robotjs;
|
|
||||||
var cmds = data.features.cmds[0]
|
var cmds = data.features.cmds[0]
|
||||||
if (cmds.type == 'regex') {
|
if (cmds.type == 'regex') {
|
||||||
$('#type').val('regex')
|
$('#type').val('regex')
|
||||||
$('#rule').val(cmds.match);
|
$('#rule').val(cmds.match);
|
||||||
} else if (cmds.type == 'window') {
|
} else if (cmds.type == 'window') {
|
||||||
robotjs ? $('#type').val('robotjs') : $('#type').val('window')
|
$('#type').val('window');
|
||||||
$('#rule').val(cmds.match.app);
|
$('#rule').val(cmds.match.app);
|
||||||
} else {
|
} else {
|
||||||
$('#type').val('key')
|
$('#type').val('key')
|
||||||
@ -423,12 +417,13 @@ $("#options").on('click', '.editBtn', function () {
|
|||||||
$('#customarg').show().val(data.customOptions.argv);
|
$('#customarg').show().val(data.customOptions.argv);
|
||||||
$('#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');
|
||||||
window.editor.setOption("mode", mode);
|
// window.editor.setOption("mode", mode);
|
||||||
window.editor.setValue(data.cmd);
|
window.editor.setValue(data.cmd);
|
||||||
resetVars();
|
resetVars();
|
||||||
typeCheck();
|
typeCheck();
|
||||||
|
programCheck();
|
||||||
outputCheck();
|
outputCheck();
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -468,7 +463,7 @@ $("#options").on('click', '#addKey', function () {
|
|||||||
$("#options").on('click', '#addDelay', function () {
|
$("#options").on('click', '#addDelay', function () {
|
||||||
var t = $('#keydelay').val();
|
var t = $('#keydelay').val();
|
||||||
if (/\d+/.test(t)) {
|
if (/\d+/.test(t)) {
|
||||||
window.editor.replaceSelection(`utools.robot.setKeyboardDelay(${t});\n`)
|
window.editor.replaceSelection(`await sleep(${t});\n`)
|
||||||
} else {
|
} else {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
@ -477,6 +472,49 @@ $("#options").on('click', '#addDelay', function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 添加动作
|
||||||
|
$("#options").on('click', '#addAction', async function () {
|
||||||
|
var a = $('#action').val();
|
||||||
|
var text;
|
||||||
|
switch (a) {
|
||||||
|
case 'open':
|
||||||
|
text = '要打开的文件';
|
||||||
|
break;
|
||||||
|
case 'visit':
|
||||||
|
text = '要访问的网址';
|
||||||
|
break;
|
||||||
|
case 'locate':
|
||||||
|
text = '要定位的文件'
|
||||||
|
break;
|
||||||
|
case 'system':
|
||||||
|
text = '要执行的命令'
|
||||||
|
break;
|
||||||
|
case 'message':
|
||||||
|
text = '要发送的消息'
|
||||||
|
break;
|
||||||
|
case 'copyTo':
|
||||||
|
text = '要写入的内容'
|
||||||
|
break;
|
||||||
|
case 'alert':
|
||||||
|
text = '要弹窗的消息'
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'warning',
|
||||||
|
text: '未选中任何动作',
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { value: content } = await Swal.fire({
|
||||||
|
title: text,
|
||||||
|
input: 'text',
|
||||||
|
showCancelButton: true,
|
||||||
|
})
|
||||||
|
if (content) {
|
||||||
|
window.editor.replaceSelection(`${a}("${content.replace(/\\/g, '\\\\')}");\n`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
$("#options").on('click', '.exportBtn', function () {
|
$("#options").on('click', '.exportBtn', function () {
|
||||||
var code = $(this).attr('code'),
|
var code = $(this).attr('code'),
|
||||||
@ -553,18 +591,11 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
title: '啊嘞?!',
|
title: '啊嘞?!',
|
||||||
text: '显示文本或html输出时无法使用{{SelectText}}!',
|
text: '显示文本或html输出时无法使用{{SelectText}}!',
|
||||||
})
|
})
|
||||||
} else if (type == 'robotjs' && /\{\{.*?\}\}/.test(cmd)) {
|
} else {
|
||||||
Swal.fire({
|
|
||||||
icon: 'error',
|
|
||||||
title: '啊嘞?!',
|
|
||||||
text: '模拟按键模式无法使用特殊变量!',
|
|
||||||
})
|
|
||||||
}else {
|
|
||||||
var program = $('#program').val(),
|
var program = $('#program').val(),
|
||||||
desc = $('#desc').val(),
|
desc = $('#desc').val(),
|
||||||
iconame = $("#iconame").val(),
|
iconame = $("#iconame").val(),
|
||||||
iconpath = $("#icon").attr('src'),
|
iconpath = $("#icon").attr('src'),
|
||||||
robotjs = false,
|
|
||||||
icon,
|
icon,
|
||||||
base64ico,
|
base64ico,
|
||||||
hasSubInput;
|
hasSubInput;
|
||||||
@ -589,7 +620,7 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
"minNum": 1
|
"minNum": 1
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
if (type == 'window' || type == 'robotjs') {
|
if (type == 'window') {
|
||||||
cmds = [{
|
cmds = [{
|
||||||
"label": desc,
|
"label": desc,
|
||||||
"type": "window",
|
"type": "window",
|
||||||
@ -605,11 +636,11 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
hasSubInput = false;
|
hasSubInput = false;
|
||||||
}
|
}
|
||||||
$("#customize").animate({ top: '100%' });
|
$("#customize").animate({ top: '100%' });
|
||||||
if (type == "robotjs") {
|
// if (type == "robotjs") {
|
||||||
program = "";
|
// program = "";
|
||||||
output = "";
|
// output = "";
|
||||||
robotjs = true;
|
// robotjs = true;
|
||||||
}
|
// }
|
||||||
// 添加特性
|
// 添加特性
|
||||||
pushData = {
|
pushData = {
|
||||||
features: {
|
features: {
|
||||||
@ -621,8 +652,8 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
program: program,
|
program: program,
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
output: output,
|
output: output,
|
||||||
hasSubInput: hasSubInput,
|
hasSubInput: hasSubInput
|
||||||
robotjs: robotjs
|
// robotjs: robotjs
|
||||||
}
|
}
|
||||||
if (program == 'custom') {
|
if (program == 'custom') {
|
||||||
pushData.customOptions = {
|
pushData.customOptions = {
|
||||||
@ -631,6 +662,9 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
"ext": $('#customext').val()
|
"ext": $('#customext').val()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program == 'simulation') {
|
||||||
|
$('#output').val('');
|
||||||
|
}
|
||||||
putCustomFts(code, pushData);
|
putCustomFts(code, pushData);
|
||||||
showOptions();
|
showOptions();
|
||||||
$(`#${code}`).click();
|
$(`#${code}`).click();
|
||||||
@ -646,18 +680,32 @@ hasCustomIcon = () => {
|
|||||||
return /data:image\/png;base64,/.test(src) || iconame
|
return /data:image\/png;base64,/.test(src) || iconame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
programCheck = () => {
|
||||||
|
let mode = $('#program').val();
|
||||||
|
if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`);
|
||||||
|
switch (mode) {
|
||||||
|
case 'custom':
|
||||||
|
$('.customscript').show();
|
||||||
|
break;
|
||||||
|
case 'simulation':
|
||||||
|
$('.varoutput').hide();
|
||||||
|
$('.simulation').show();
|
||||||
|
mode = 'javascript';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$('.customscript').hide();
|
||||||
|
$('.simulation').hide();
|
||||||
|
$('.varoutput').show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if('applescript') mode = 'shell';
|
||||||
|
if('cmd') mode = 'powershell';
|
||||||
|
window.editor.setOption("mode", mode);
|
||||||
|
}
|
||||||
|
|
||||||
// 语言选项改变时
|
// 语言选项改变时
|
||||||
$("#options").on('change', '#program', function () {
|
$("#options").on('change', '#program', function () {
|
||||||
let mode = $(this).val();
|
programCheck()
|
||||||
if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`);
|
|
||||||
if (mode == 'custom') {
|
|
||||||
$('.customscript').show();
|
|
||||||
} else {
|
|
||||||
$('.customscript').hide();
|
|
||||||
}
|
|
||||||
mode == 'applescript' && (mode = 'shell');
|
|
||||||
mode == 'cmd' && (mode = 'powershell');
|
|
||||||
window.editor.setOption("mode", mode);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 变量选项改变时
|
// 变量选项改变时
|
||||||
@ -666,6 +714,10 @@ $("#options").on('change', '#vars', function () {
|
|||||||
window.editor.replaceSelection($("#vars").val());
|
window.editor.replaceSelection($("#vars").val());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#options").on('change', '#action', function () {
|
||||||
|
$("#action").css({ 'color': 'black' })
|
||||||
|
})
|
||||||
|
|
||||||
// 输出选项改变时
|
// 输出选项改变时
|
||||||
$("#options").on('change', '#output', function () {
|
$("#options").on('change', '#output', function () {
|
||||||
resetVars();
|
resetVars();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user