mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-08-12 00:19:39 +08:00
v0.0.1
This commit is contained in:
parent
a07dd6f344
commit
821413e775
172
README.md
172
README.md
@ -1,84 +1,88 @@
|
|||||||
# 快捷命令 V0.0.1
|
# 快捷命令 V0.0.1
|
||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
自定义可以在`uTools`中快速执行的命令或脚本
|
自定义可以在`uTools`中快速执行的命令或脚本
|
||||||
|
|
||||||
## 功能
|
## 功能
|
||||||
|
|
||||||
#### 快速启动
|
#### 快速启动
|
||||||
|
|
||||||
可以配置一些常用的命令,比如`回收站` `查看网络连接`之类
|
可以配置一些常用的命令,比如`回收站` `查看网络连接`之类
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
配合`uTools`的全局功能快捷键,可以达到一键启动的功能
|
配合`uTools`的全局功能快捷键,可以达到一键启动的功能
|
||||||
|
|
||||||
#### 常用脚本
|
#### 常用脚本
|
||||||
|
|
||||||
如果为了一个小功能,就去编写一个插件,成本太高,本插件可以利用本地的脚本环境快速实现一些小功能。比如`base64转图片`等
|
如果为了一个小功能,就去编写一个插件,成本太高,本插件可以利用本地的脚本环境快速实现一些小功能。比如`base64转图片`等
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
目前可以添加以下类型的脚本,但要注意的是**本插件未封装任何运行环境,需要本机安装了环境才能执行相应的脚本**
|
目前可以添加以下类型的脚本,但要注意的是**本插件未封装任何运行环境,需要本机安装了环境才能执行相应的脚本**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
同时,本插件可以作为一个便捷的脚本仓库,因为所有的脚本都是多设备自动同步的,无须另外存储在硬盘中
|
同时,本插件可以作为一个便捷的脚本仓库,因为所有的脚本都是多设备自动同步的,无须另外存储在硬盘中
|
||||||
|
|
||||||
#### 输出处理
|
#### 输出处理
|
||||||
|
|
||||||
如果脚本有输出,则可以对输出内容做如下处理
|
如果脚本有输出,则可以对输出内容做如下处理
|
||||||
|
|
||||||
- 忽略输出
|
- 忽略输出
|
||||||
- 显示纯文本输出 (不解析 html 内容)
|
- 显示纯文本输出 (不解析 html 内容)
|
||||||
- 显示html格式的输出 (可以进一步编写简单的 GUI 界面)
|
- 显示html格式的输出 (可以进一步编写简单的 GUI 界面)
|
||||||
- 复制到剪贴板
|
- 复制到剪贴板
|
||||||
- 发送到活动窗口
|
- 发送到活动窗口
|
||||||
|
|
||||||
#### 插值变量
|
#### 插值变量
|
||||||
|
|
||||||
如果你仔细看了上面例子中的脚本,一定会发现很多脚本里都有`{{}}`格式的变量
|
如果你仔细看了上面例子中的脚本,一定会发现很多脚本里都有`{{}}`格式的变量
|
||||||
|
|
||||||
本插件内置了一些特殊的插值变量,可以获取一些特殊的值,能够加入到插件里的任意脚本中
|
本插件内置了一些特殊的插值变量,可以获取一些特殊的值,能够加入到插件里的任意脚本中
|
||||||
|
|
||||||
- `{{isWin}}` 是否是window系统
|
- `{{isWin}}` 是否是window系统
|
||||||
- `{{pwd}}` 资源管理器或访达的当前目录
|
- `{{pwd}}` 资源管理器或访达的当前目录
|
||||||
- `{{ChromeUrl}}` 谷歌浏览器的当前链接
|
- `{{ChromeUrl}}` 谷歌浏览器的当前链接
|
||||||
- `{{ClipText}}` 获取剪贴板的文本
|
- `{{ClipText}}` 获取剪贴板的文本
|
||||||
- `{{SelectText}}` 获取选中的文本
|
- `{{SelectText}}` 获取选中的文本
|
||||||
- `{{SelectFile}}` 获取选中的文件 (单文件)
|
- `{{SelectFile}}` 获取选中的文件 (单文件)
|
||||||
- `{{input}} ` 获取uTools主输入框的文本,当启用此变量时,将直接从主输入框匹配文本
|
- `{{input}} ` 获取uTools主输入框的文本,当启用此变量时,将直接从主输入框匹配文本
|
||||||
|
|
||||||
插值使用示例
|
插值使用示例
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## 下载
|
||||||
## 下载
|
|
||||||
|
[百度网盘](https://pan.baidu.com/s/1kEEQcQ1p3Rjli2sTtmCcTg) 提取码: `rbek`
|
||||||
[百度网盘](https://pan.baidu.com/s/1kEEQcQ1p3Rjli2sTtmCcTg) 提取码: `rbek`
|
|
||||||
|
[项目地址](https://github.com/fofolee/uTools-QuickerCommand)
|
||||||
[项目地址](https://github.com/fofolee/uTools-QuickerCommand)
|
|
||||||
|
[插件发布页](https://yuanliao.info/d/424)
|
||||||
[插件发布页](https://yuanliao.info/d/356)
|
|
||||||
|
## 安装方法
|
||||||
## 安装方法
|
|
||||||
|
将`upx`文件拖入`uTools`输入框中安装即可
|
||||||
将`upx`文件拖入`uTools`输入框中安装即可
|
|
||||||
|
## 关键字
|
||||||
## 关键字
|
|
||||||
|
`快捷命令` `QuickCommand`
|
||||||
`快捷命令` `QuickCommand`
|
|
||||||
|
## 鸣谢
|
||||||
## 鸣谢
|
|
||||||
|
鸣谢`uTools`团队,插件中使用的`robotJS`使用的是`剪贴板`插件中的`robotJS`,省去了自行编译的麻烦,在此感谢!
|
||||||
鸣谢`uTools`团队,插件中使用的`robotJS`使用的是`剪贴板`插件中的`robotJS`,省去了自行编译的麻烦,在此感谢!
|
|
||||||
|
## 另:两个小需求
|
||||||
|
|
||||||
|
希望插件的`Features`能够支持以`base64`作为图标,好实现多设备的图标同步,目前的实现方案有点麻烦~
|
||||||
|
另外可以根据使用的操作系统动态启用或禁用某些`Feature`,即给`Feature`添加类似`platform`的功能
|
BIN
assets/.DS_Store
vendored
Normal file
BIN
assets/.DS_Store
vendored
Normal file
Binary file not shown.
@ -22,6 +22,8 @@ checkUpdate = () => {
|
|||||||
utools.db.put({ _id: p.version, data: "pass" })
|
utools.db.put({ _id: p.version, data: "pass" })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
console.log('当前已是最新版本!');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
4
assets/jquery-3.3.1.min.js
vendored
4
assets/jquery-3.3.1.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,402 +1,402 @@
|
|||||||
#out {
|
#out {
|
||||||
padding: 0px 10px;
|
padding: 0px 10px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
line-height: 26px;
|
line-height: 26px;
|
||||||
font-family: Monaco, consolas;
|
font-family: Monaco, consolas;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options {
|
#options {
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
color: #595959;
|
color: #595959;
|
||||||
font-family: consolas, monaco, "微软雅黑";
|
font-family: consolas, monaco, "微软雅黑";
|
||||||
padding-bottom: 30px;
|
padding-bottom: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options * {
|
#options * {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .switch-btn {
|
#options .switch-btn {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
width: 80px;
|
width: 80px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
zoom: 0.7;
|
zoom: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch {
|
#options .checked-switch {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .text-switch {
|
#options .text-switch {
|
||||||
background-color: #cccccc;
|
background-color: #cccccc;
|
||||||
border: 1px solid #dddddd;
|
border: 1px solid #dddddd;
|
||||||
border-radius: inherit;
|
border-radius: inherit;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
width: 60px;
|
width: 60px;
|
||||||
height: inherit;
|
height: inherit;
|
||||||
position: relative;
|
position: relative;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .text-switch:before,
|
#options .text-switch:before,
|
||||||
#options .text-switch:after {
|
#options .text-switch:after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
margin-top: -.5em;
|
margin-top: -.5em;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
-webkit-transition: inherit;
|
-webkit-transition: inherit;
|
||||||
-moz-transition: inherit;
|
-moz-transition: inherit;
|
||||||
-o-transition: inherit;
|
-o-transition: inherit;
|
||||||
transition: inherit;
|
transition: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .text-switch:before {
|
#options .text-switch:before {
|
||||||
content: 'OF';
|
content: 'OF';
|
||||||
right: 6px;
|
right: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .text-switch:after {
|
#options .text-switch:after {
|
||||||
content: 'ON';
|
content: 'ON';
|
||||||
left: 6px;
|
left: 6px;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:checked~.text-switch {
|
#options .checked-switch:checked~.text-switch {
|
||||||
background-color: #00af2c;
|
background-color: #00af2c;
|
||||||
border: 1px solid #068506;
|
border: 1px solid #068506;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:disabled~.text-switch {
|
#options .checked-switch:disabled~.text-switch {
|
||||||
cursor: no-drop;
|
cursor: no-drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:disabled~.text-switch~.toggle-btn {
|
#options .checked-switch:disabled~.text-switch~.toggle-btn {
|
||||||
cursor: no-drop;
|
cursor: no-drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:disabled~.text-switch:before {
|
#options .checked-switch:disabled~.text-switch:before {
|
||||||
content: '▬';
|
content: '▬';
|
||||||
right: 11px;
|
right: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:checked~.text-switch:before {
|
#options .checked-switch:checked~.text-switch:before {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:checked~.text-switch:after {
|
#options .checked-switch:checked~.text-switch:after {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .toggle-btn {
|
#options .toggle-btn {
|
||||||
background: linear-gradient(#eee, #fafafa);
|
background: linear-gradient(#eee, #fafafa);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
left: 1px;
|
left: 1px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 1px;
|
top: 1px;
|
||||||
width: 28px;
|
width: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .checked-switch:checked~.toggle-btn {
|
#options .checked-switch:checked~.toggle-btn {
|
||||||
left: 30px;
|
left: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .text-switch,
|
#options .text-switch,
|
||||||
#options .toggle-btn {
|
#options .toggle-btn {
|
||||||
transition: All 0.3s ease;
|
transition: All 0.3s ease;
|
||||||
-webkit-transition: All 0.3s ease;
|
-webkit-transition: All 0.3s ease;
|
||||||
-moz-transition: All 0.3s ease;
|
-moz-transition: All 0.3s ease;
|
||||||
-o-transition: All 0.3s ease;
|
-o-transition: All 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .no-radius,
|
#options .no-radius,
|
||||||
#options .no-radius .toggle-btn {
|
#options .no-radius .toggle-btn {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .circle-style .toggle-btn::before {
|
#options .circle-style .toggle-btn::before {
|
||||||
background: linear-gradient(#dedede, #cacaca);
|
background: linear-gradient(#dedede, #cacaca);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
content: "";
|
content: "";
|
||||||
height: 14px;
|
height: 14px;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: 14px;
|
width: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options table {
|
#options table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options table td {
|
#options table td {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options table tr:nth-child(odd) {
|
#options table tr:nth-child(odd) {
|
||||||
background-color: #fff !important;
|
background-color: #fff !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options table tr:nth-child(even) {
|
#options table tr:nth-child(even) {
|
||||||
background-color: #f8f8f8 !important;
|
background-color: #f8f8f8 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .keyword {
|
#options .keyword {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #333;
|
color: #333;
|
||||||
border: 1px solid #eee;
|
border: 1px solid #eee;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
line-height: 22px;
|
line-height: 22px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
background-color: #f3f3f3;
|
background-color: #f3f3f3;
|
||||||
margin-right: 5px
|
margin-right: 5px
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .logo {
|
#options .logo {
|
||||||
width: 32px;
|
width: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .footBtn {
|
#options .footBtn {
|
||||||
float: right;
|
float: right;
|
||||||
/* right: 5px;
|
/* right: 5px;
|
||||||
bottom: 2px; */
|
bottom: 2px; */
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background: #00af2c;
|
background: #00af2c;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
margin: 0px 5px;
|
margin: 0px 5px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .footBtn:hover {
|
#options .footBtn:hover {
|
||||||
background: #068506;
|
background: #068506;
|
||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options .foot {
|
#options .foot {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
right: 0px;
|
right: 0px;
|
||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
background: #f3f3f3;
|
background: #f3f3f3;
|
||||||
box-shadow: 0px 0px 9px 0px #00000030;
|
box-shadow: 0px 0px 9px 0px #00000030;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options td span {
|
#options td span {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options span.editBtn {
|
#options span.editBtn {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #00af2c;
|
color: #00af2c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options span.delBtn {
|
#options span.delBtn {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #ed5b49
|
color: #ed5b49
|
||||||
}
|
}
|
||||||
|
|
||||||
#options span.editBtn:hover {
|
#options span.editBtn:hover {
|
||||||
color: #057205;
|
color: #057205;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options span.delBtn:hover {
|
#options span.delBtn:hover {
|
||||||
color: #bd3523;
|
color: #bd3523;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize {
|
#options #customize {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
top: 100%;
|
top: 100%;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
padding: 0px 30px;
|
padding: 0px 30px;
|
||||||
box-shadow: 0px 0px 9px 0px #00000030;
|
box-shadow: 0px 0px 9px 0px #00000030;
|
||||||
color: black;
|
color: black;
|
||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize p {
|
#options #customize p {
|
||||||
line-height: 1.25rem;
|
line-height: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .word {
|
#options #customize .word {
|
||||||
color: #2196F3;
|
color: #2196F3;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
border: 1px solid #1E88E5;
|
border: 1px solid #1E88E5;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
line-height: 22px;
|
line-height: 22px;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
background-color: #E3F2FD;
|
background-color: #E3F2FD;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize input {
|
#options #customize input {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
border-bottom: 1px solid #dbdbdb;
|
border-bottom: 1px solid #dbdbdb;
|
||||||
border-top: 0px;
|
border-top: 0px;
|
||||||
border-left: 0px;
|
border-left: 0px;
|
||||||
border-right: 0px;
|
border-right: 0px;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
margin-left: 15px
|
margin-left: 15px
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize input:hover {
|
#options #customize input:hover {
|
||||||
border-bottom-color: #9e9e9ec7;
|
border-bottom-color: #9e9e9ec7;
|
||||||
transition: 0.25s;
|
transition: 0.25s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize input:focus {
|
#options #customize input:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
border-bottom-color: #0277BD;
|
border-bottom-color: #0277BD;
|
||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
input::-webkit-input-placeholder {
|
input::-webkit-input-placeholder {
|
||||||
color: #999;
|
color: #999;
|
||||||
font-size: 15px
|
font-size: 15px
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .CodeMirror {
|
#options #customize .CodeMirror {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-family: "Monaco", "consolas";
|
font-family: "Monaco", "consolas";
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 23rem;
|
height: 23rem;
|
||||||
border: 1px solid #dbdbdb;
|
border: 1px solid #dbdbdb;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#options #customize .CodeMirror:hover {
|
#options #customize .CodeMirror:hover {
|
||||||
border: 1px solid #9e9e9ec7;
|
border: 1px solid #9e9e9ec7;
|
||||||
transition: 0.25s;
|
transition: 0.25s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .CodeMirror-focused {
|
#options #customize .CodeMirror-focused {
|
||||||
border: 1px solid #0277BD !important;
|
border: 1px solid #0277BD !important;
|
||||||
box-shadow: 0px 0px 2px 0px #0277BD;
|
box-shadow: 0px 0px 2px 0px #0277BD;
|
||||||
transition: 0.25s;
|
transition: 0.25s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .CodeMirror-placeholder {
|
#options #customize .CodeMirror-placeholder {
|
||||||
color: #999;
|
color: #999;
|
||||||
font-size: 15px
|
font-size: 15px
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize select {
|
#options #customize select {
|
||||||
width: 40%;
|
width: 40%;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
border-bottom: 1px solid #dbdbdb;
|
border-bottom: 1px solid #dbdbdb;
|
||||||
border-top: 0px;
|
border-top: 0px;
|
||||||
border-left: 0px;
|
border-left: 0px;
|
||||||
border-right: 0px;
|
border-right: 0px;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
outline: none;
|
outline: none;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAJAgMAAAB71iXHAAAADFBMVEUAAAAqPz8rN0csOEgGlpD7AAAAA3RSTlMABvwYJ91vAAAAGklEQVQI12OAgQNAaMDMwMAjw8DAVAAWgAEAPFADDsXseo4AAAAASUVORK5CYII=") no-repeat scroll right center transparent;
|
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAJAgMAAAB71iXHAAAADFBMVEUAAAAqPz8rN0csOEgGlpD7AAAAA3RSTlMABvwYJ91vAAAAGklEQVQI12OAgQNAaMDMwMAjw8DAVAAWgAEAPFADDsXseo4AAAAASUVORK5CYII=") no-repeat scroll right center transparent;
|
||||||
-webkit-appearance: button
|
-webkit-appearance: button
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize select:hover {
|
#options #customize select:hover {
|
||||||
border-bottom-color: #9e9e9ec7;
|
border-bottom-color: #9e9e9ec7;
|
||||||
transition: 0.25s;
|
transition: 0.25s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize select:focus {
|
#options #customize select:focus {
|
||||||
border-bottom-color: #0277BD;
|
border-bottom-color: #0277BD;
|
||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize select#vars {
|
#options #customize select#vars {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize select option {
|
#options #customize select option {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#options #customize input#iconame {
|
#options #customize input#iconame {
|
||||||
width: 35%;
|
width: 35%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize #icon {
|
#options #customize #icon {
|
||||||
float: right;
|
float: right;
|
||||||
width: 28px;
|
width: 28px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .selectBtn {
|
#options #customize .selectBtn {
|
||||||
padding: 4px 10px;
|
padding: 4px 10px;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
color: #1E88C7;
|
color: #1E88C7;
|
||||||
background: #D0EEFF;
|
background: #D0EEFF;
|
||||||
border: 1px solid #99D3F5;
|
border: 1px solid #99D3F5;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize .selectBtn:hover {
|
#options #customize .selectBtn:hover {
|
||||||
background: #AADFFD;
|
background: #AADFFD;
|
||||||
border-color: #78C3F3;
|
border-color: #78C3F3;
|
||||||
color: #004974;
|
color: #004974;
|
||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize button {
|
#options #customize button {
|
||||||
width: 150px;
|
width: 150px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
border-width: 0px;
|
border-width: 0px;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
outline: none;
|
outline: none;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize button.cancelBtn {
|
#options #customize button.cancelBtn {
|
||||||
float: right;
|
float: right;
|
||||||
margin-right: 30px;
|
margin-right: 30px;
|
||||||
background: #808080c9;
|
background: #808080c9;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize button.saveBtn {
|
#options #customize button.saveBtn {
|
||||||
float: right;
|
float: right;
|
||||||
background: #1E90FF;
|
background: #1E90FF;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize button.saveBtn:hover {
|
#options #customize button.saveBtn:hover {
|
||||||
background: #5599FF;
|
background: #5599FF;
|
||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options #customize button.cancelBtn:hover {
|
#options #customize button.cancelBtn:hover {
|
||||||
background: #a5a2a2c9;
|
background: #a5a2a2c9;
|
||||||
transition: 0.5s;
|
transition: 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
@ -1,326 +1,326 @@
|
|||||||
getCustomFts = () => {
|
getCustomFts = () => {
|
||||||
var db = utools.db.get("customFts"),
|
var db = utools.db.get("customFts"),
|
||||||
customFts = db ? db.data : {};
|
customFts = db ? db.data : {};
|
||||||
return customFts;
|
return customFts;
|
||||||
}
|
}
|
||||||
|
|
||||||
programs = {
|
programs = {
|
||||||
shell: {
|
shell: {
|
||||||
bin: 'bash',
|
bin: 'bash',
|
||||||
argv: '',
|
argv: '',
|
||||||
ext: 'sh'
|
ext: 'sh'
|
||||||
},
|
},
|
||||||
applescript: {
|
applescript: {
|
||||||
bin: 'osascript',
|
bin: 'osascript',
|
||||||
argv: '',
|
argv: '',
|
||||||
ext: 'scpt'
|
ext: 'scpt'
|
||||||
},
|
},
|
||||||
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'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (customFts[fts].noKeyword) {
|
||||||
cmds = '<span class="keyword">匹配主输入框文本进入</span>';
|
cmds = '<span class="keyword">匹配主输入框文本进入</span>';
|
||||||
} else {
|
} else {
|
||||||
features.cmds.forEach(cmd => {
|
features.cmds.forEach(cmd => {
|
||||||
cmds += `<span class="keyword">${cmd}</span>`;
|
cmds += `<span class="keyword">${cmd}</span>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var isChecked = '';
|
var isChecked = '';
|
||||||
for(var c of currentFts){
|
for(var c of currentFts){
|
||||||
if (c.code == features.code) {
|
if (c.code == features.code) {
|
||||||
isChecked = 'checked';
|
isChecked = 'checked';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var iconpath = pjoin(dirname, features.icon),
|
var iconpath = pjoin(dirname, features.icon),
|
||||||
base64Ico = customFts[fts].base64Ico;
|
base64Ico = customFts[fts].base64Ico;
|
||||||
if (!exists(iconpath) && base64Ico) saveBase64Ico(iconpath, base64Ico);
|
if (!exists(iconpath) && base64Ico) saveBase64Ico(iconpath, base64Ico);
|
||||||
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>${cmds}</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>
|
||||||
<span class="toggle-btn"></span>
|
<span class="toggle-btn"></span>
|
||||||
</label>
|
</label>
|
||||||
<span class="editBtn" code="${features.code}">✎</span>
|
<span class="editBtn" code="${features.code}">✎</span>
|
||||||
<span class="delBtn" code="${features.code}">✘</span>
|
<span class="delBtn" code="${features.code}">✘</span>
|
||||||
</td>`
|
</td>`
|
||||||
};
|
};
|
||||||
featureList += `</tr></table><div class="foot">
|
featureList += `</tr></table><div class="foot">
|
||||||
<div id="add" class="footBtn">添加命令</div>
|
<div id="add" class="footBtn">添加命令</div>
|
||||||
<div id="disableAll" class="footBtn">全部禁用</div>
|
<div id="disableAll" class="footBtn">全部禁用</div>
|
||||||
<div id="enableAll" class="footBtn">全部启用</div>
|
<div id="enableAll" class="footBtn">全部启用</div>
|
||||||
</div>`
|
</div>`
|
||||||
$("#options").html(featureList);
|
$("#options").html(featureList);
|
||||||
}
|
}
|
||||||
|
|
||||||
showCustomize = () => {
|
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><span class="word">关键字</span><input type="text" id="kw" 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">
|
||||||
${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>
|
||||||
<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>
|
||||||
<option value="{{isWin}}">是否Window系统</option>
|
<option value="{{isWin}}">是否Window系统</option>
|
||||||
<option value="{{input}}">主输入框的文本</option>
|
<option value="{{input}}">主输入框的文本</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>
|
||||||
<option value="{{SelectText}}">选中的文本</option>
|
<option value="{{SelectText}}">选中的文本</option>
|
||||||
<option value="{{SelectFile}}">选中的文件</option>
|
<option value="{{SelectFile}}">选中的文件</option>
|
||||||
</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="text">显示纯文本输出</option>
|
<option value="text">显示纯文本输出</option>
|
||||||
<option value="html">显示html格式的输出</option>
|
<option value="html">显示html格式的输出</option>
|
||||||
<option value="clip">复制到剪贴板</option>
|
<option value="clip">复制到剪贴板</option>
|
||||||
<option value="send">发送到活动窗口</option>
|
<option value="send">发送到活动窗口</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span class="word">脚 本</span>
|
<span class="word">脚 本</span>
|
||||||
<select id="codec">
|
<select id="codec">
|
||||||
<option value="gbk">GBK 编码</option>
|
<option value="gbk">GBK 编码</option>
|
||||||
<option value="utf8">UTF8 编码</option>
|
<option value="utf8">UTF8 编码</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<p><textarea id="cmd" placeholder="可以直接拖放脚本文件至此处"></textarea></p>
|
<p><textarea id="cmd" placeholder="可以直接拖放脚本文件至此处"></textarea></p>
|
||||||
<p>
|
<p>
|
||||||
<button class="saveBtn">保存</button>
|
<button class="saveBtn">保存</button>
|
||||||
<button class="cancelBtn">取消</button>
|
<button class="cancelBtn">取消</button>
|
||||||
</p>`
|
</p>`
|
||||||
$("#options").append(customWindow)
|
$("#options").append(customWindow)
|
||||||
if (window.isWin) {
|
if (window.isWin) {
|
||||||
var shell = 'cmd',
|
var shell = 'cmd',
|
||||||
mode = 'powershell';
|
mode = 'powershell';
|
||||||
} else {
|
} else {
|
||||||
var shell = 'shell',
|
var shell = 'shell',
|
||||||
mode = 'shell';
|
mode = 'shell';
|
||||||
$("#codec").hide();
|
$("#codec").hide();
|
||||||
}
|
}
|
||||||
$("#program").val(shell);
|
$("#program").val(shell);
|
||||||
$("#icon").attr('src', `logo/${shell}.png`);
|
$("#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", mode);
|
||||||
$("#customize").animate({ top: '0px' });
|
$("#customize").animate({ top: '0px' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开关
|
// 开关
|
||||||
$("#options").on('change', 'input[type=checkbox]', function () {
|
$("#options").on('change', 'input[type=checkbox]', function () {
|
||||||
var customFts = getCustomFts(),
|
var customFts = getCustomFts(),
|
||||||
code = $(this).attr('id');
|
code = $(this).attr('id');
|
||||||
if (!utools.removeFeature(code)) {
|
if (!utools.removeFeature(code)) {
|
||||||
utools.setFeature(customFts[code].features);
|
utools.setFeature(customFts[code].features);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 底部功能按钮
|
// 底部功能按钮
|
||||||
$("#options").on('click', '.footBtn', function () {
|
$("#options").on('click', '.footBtn', function () {
|
||||||
switch ($(this).attr('id')) {
|
switch ($(this).attr('id')) {
|
||||||
case 'add': showCustomize();
|
case 'add': showCustomize();
|
||||||
break;
|
break;
|
||||||
case 'enableAll': $(".checked-switch:not(:checked)").click();
|
case 'enableAll': $(".checked-switch:not(:checked)").click();
|
||||||
break;
|
break;
|
||||||
case 'disableAll': $(".checked-switch:checked").click();
|
case 'disableAll': $(".checked-switch:checked").click();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 取消
|
// 取消
|
||||||
$("#options").on('click', '.cancelBtn', function () {
|
$("#options").on('click', '.cancelBtn', function () {
|
||||||
$("#customize").animate({ top: '100%'});
|
$("#customize").animate({ top: '100%'});
|
||||||
})
|
})
|
||||||
|
|
||||||
// 编辑
|
// 编辑
|
||||||
$("#options").on('click', '.editBtn', function () {
|
$("#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();
|
||||||
// 判断是通过关键词进入还是主输入框进入
|
// 判断是通过关键词进入还是主输入框进入
|
||||||
if (data.noKeyword) {
|
if (data.noKeyword) {
|
||||||
$('#kw').val(data.features.code);
|
$('#kw').val(data.features.code);
|
||||||
$('#kw').prop('disabled', true);
|
$('#kw').prop('disabled', true);
|
||||||
} 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);
|
||||||
$('#codec').val(data.codec);
|
$('#codec').val(data.codec);
|
||||||
$("#icon").attr('src', data.features.icon);
|
$("#icon").attr('src', data.features.icon);
|
||||||
let mode = data.program;
|
let mode = data.program;
|
||||||
let iconame = basename(data.features.icon);
|
let iconame = basename(data.features.icon);
|
||||||
if (iconame != `${mode}.png`) $('#iconame').val(iconame);
|
if (iconame != `${mode}.png`) $('#iconame').val(iconame);
|
||||||
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);
|
||||||
})
|
})
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
$("#options").on('click', '.delBtn', function () {
|
$("#options").on('click', '.delBtn', function () {
|
||||||
var code = $(this).attr('code'),
|
var code = $(this).attr('code'),
|
||||||
db = utools.db.get("customFts"),
|
db = utools.db.get("customFts"),
|
||||||
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();
|
||||||
})
|
})
|
||||||
|
|
||||||
// 选择图标
|
// 选择图标
|
||||||
$("#options").on('click', '#icon, #iconame', function () {
|
$("#options").on('click', '#icon, #iconame', function () {
|
||||||
let iconpath = window.openFolder()[0];
|
let iconpath = window.openFolder()[0];
|
||||||
$("#iconame").val(basename(iconpath));
|
$("#iconame").val(basename(iconpath));
|
||||||
$("#icon").attr('src', iconpath);
|
$("#icon").attr('src', iconpath);
|
||||||
})
|
})
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
$("#options").on('click', '.saveBtn', function () {
|
$("#options").on('click', '.saveBtn', function () {
|
||||||
var code = $('#kw').val().split(',')[0].trim()
|
var code = $('#kw').val().split(',')[0].trim()
|
||||||
var customFts = getCustomFts();
|
var customFts = getCustomFts();
|
||||||
// 如果 code 重复, 编辑状态下不检测
|
// 如果 code 重复, 编辑状态下不检测
|
||||||
if (code in customFts && !$('#kw').attr('edit')) {
|
if (code in customFts && !$('#kw').attr('edit')) {
|
||||||
$('#kw').css({ 'border-bottom-color': '#ec1212' })
|
$('#kw').css({ 'border-bottom-color': '#ec1212' })
|
||||||
window.messageBox({ type: 'error', icon: window.logo, message: "命令名称与现有的重复!", buttons: ['朕知道了'] })
|
window.messageBox({ type: 'error', icon: window.logo, message: "命令名称与现有的重复!", buttons: ['朕知道了'] })
|
||||||
} else {
|
} else {
|
||||||
var kw = $('#kw').val().split(','),
|
var kw = $('#kw').val().split(','),
|
||||||
program = $('#program').val(),
|
program = $('#program').val(),
|
||||||
desc = $('#desc').val(),
|
desc = $('#desc').val(),
|
||||||
output = $('#output').val(),
|
output = $('#output').val(),
|
||||||
codec = $('#codec').val(),
|
codec = $('#codec').val(),
|
||||||
iconame = $("#iconame").val(),
|
iconame = $("#iconame").val(),
|
||||||
iconpath = $("#icon").attr('src'),
|
iconpath = $("#icon").attr('src'),
|
||||||
cmd = window.editor.getValue(),
|
cmd = window.editor.getValue(),
|
||||||
icon,
|
icon,
|
||||||
base64ico;
|
base64ico;
|
||||||
// 自定义了图标的情况下
|
// 自定义了图标的情况下
|
||||||
if (iconame) {
|
if (iconame) {
|
||||||
icon = window.getIconPath(iconame);
|
icon = window.getIconPath(iconame);
|
||||||
if (iconpath == icon) {
|
if (iconpath == icon) {
|
||||||
base64ico = window.getBase64Ico(pjoin(dirname, iconpath));
|
base64ico = window.getBase64Ico(pjoin(dirname, iconpath));
|
||||||
} else {
|
} else {
|
||||||
base64ico = window.getBase64Ico(iconpath);
|
base64ico = window.getBase64Ico(iconpath);
|
||||||
}
|
}
|
||||||
// 未自定义使用默认
|
// 未自定义使用默认
|
||||||
} else {
|
} else {
|
||||||
icon = iconpath;
|
icon = iconpath;
|
||||||
base64ico = '';
|
base64ico = '';
|
||||||
}
|
}
|
||||||
// 通过主输入框直接进入
|
// 通过主输入框直接进入
|
||||||
if (cmd.includes('{{input}}')) {
|
if (cmd.includes('{{input}}')) {
|
||||||
kw = [{
|
kw = [{
|
||||||
"label": desc,
|
"label": desc,
|
||||||
"type": "over",
|
"type": "over",
|
||||||
"minNum": 1
|
"minNum": 1
|
||||||
}];
|
}];
|
||||||
noKeyword = true;
|
noKeyword = true;
|
||||||
} else {
|
} else {
|
||||||
noKeyword = false;
|
noKeyword = false;
|
||||||
}
|
}
|
||||||
$("#customize").animate({ top: '100%' });
|
$("#customize").animate({ top: '100%' });
|
||||||
var pushData = {};
|
var pushData = {};
|
||||||
// 添加特性
|
// 添加特性
|
||||||
pushData[code] = {
|
pushData[code] = {
|
||||||
features: {
|
features: {
|
||||||
"code": code,
|
"code": code,
|
||||||
"explain": desc,
|
"explain": desc,
|
||||||
"cmds": kw,
|
"cmds": kw,
|
||||||
"icon": icon
|
"icon": icon
|
||||||
},
|
},
|
||||||
program: program,
|
program: program,
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
output: output,
|
output: output,
|
||||||
codec: codec,
|
codec: codec,
|
||||||
base64Ico: base64ico,
|
base64Ico: base64ico,
|
||||||
noKeyword: noKeyword
|
noKeyword: noKeyword
|
||||||
}
|
}
|
||||||
var db = utools.db.get("customFts");
|
var db = utools.db.get("customFts");
|
||||||
if (db) {
|
if (db) {
|
||||||
var rev = db._rev
|
var rev = db._rev
|
||||||
var data = db.data
|
var data = db.data
|
||||||
data[code] = pushData[code];
|
data[code] = pushData[code];
|
||||||
utools.db.put({ _id: "customFts", data: data, _rev: rev });
|
utools.db.put({ _id: "customFts", data: data, _rev: rev });
|
||||||
} else {
|
} else {
|
||||||
utools.db.put({ _id: "customFts", data: pushData });
|
utools.db.put({ _id: "customFts", data: pushData });
|
||||||
}
|
}
|
||||||
showOptions();
|
showOptions();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 语言选项改变时
|
// 语言选项改变时
|
||||||
$("#options").on('change', '#program', function () {
|
$("#options").on('change', '#program', function () {
|
||||||
let mode = $(this).val();
|
let mode = $(this).val();
|
||||||
if (!$("#iconame").val()) $("#icon").attr('src', `logo/${mode}.png`);
|
if (!$("#iconame").val()) $("#icon").attr('src', `logo/${mode}.png`);
|
||||||
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);
|
||||||
})
|
})
|
||||||
|
|
||||||
// 变量选项改变时
|
// 变量选项改变时
|
||||||
$("#options").on('change', '#vars', function () {
|
$("#options").on('change', '#vars', function () {
|
||||||
$("#vars").css({'color':'black'})
|
$("#vars").css({'color':'black'})
|
||||||
window.editor.replaceSelection($("#vars").val());
|
window.editor.replaceSelection($("#vars").val());
|
||||||
})
|
})
|
||||||
|
62
index.html
62
index.html
@ -1,32 +1,32 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh">
|
<html lang="zh">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf8">
|
<meta charset="utf8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<link rel="stylesheet" href="assets/options.css">
|
<link rel="stylesheet" href="assets/options.css">
|
||||||
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
|
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
|
||||||
<script src="assets/jquery-3.3.1.min.js"></script>
|
<script src="assets/jquery-3.3.1.min.js"></script>
|
||||||
<script src="codemirror/lib/codemirror.js"></script>
|
<script src="codemirror/lib/codemirror.js"></script>
|
||||||
<script src="codemirror/addon/display/placeholder.js"></script>
|
<script src="codemirror/addon/display/placeholder.js"></script>
|
||||||
<script src="codemirror/mode/shell/shell.js"></script>
|
<script src="codemirror/mode/shell/shell.js"></script>
|
||||||
<script src="codemirror/mode/powershell/powershell.js"></script>
|
<script src="codemirror/mode/powershell/powershell.js"></script>
|
||||||
<script src="codemirror/mode/python/python.js"></script>
|
<script src="codemirror/mode/python/python.js"></script>
|
||||||
<script src="codemirror/mode/javascript/javascript.js"></script>
|
<script src="codemirror/mode/javascript/javascript.js"></script>
|
||||||
<script src="codemirror/mode/ruby/ruby.js"></script>
|
<script src="codemirror/mode/ruby/ruby.js"></script>
|
||||||
<script src="codemirror/mode/php/php.js"></script>
|
<script src="codemirror/mode/php/php.js"></script>
|
||||||
<script src="codemirror/mode/perl/perl.js"></script>
|
<script src="codemirror/mode/perl/perl.js"></script>
|
||||||
<script src="codemirror/mode/lua/lua.js"></script>
|
<script src="codemirror/mode/lua/lua.js"></script>
|
||||||
<script src="assets/checkUpdate.js"></script>
|
<script src="assets/checkUpdate.js"></script>
|
||||||
<title>快捷命令</title>
|
<title>快捷命令</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="options"></div>
|
<div id="options"></div>
|
||||||
<pre id="out"></pre>
|
<pre id="out"></pre>
|
||||||
<script src="assets/options.js"></script>
|
<script src="assets/options.js"></script>
|
||||||
<script src="assets/index.js"></script>
|
<script src="assets/index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
36
plugin.json
36
plugin.json
@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"pluginName": "快捷命令",
|
"pluginName": "快捷命令",
|
||||||
"description": "自定义在 uTools 中快速执行的命令或脚本",
|
"description": "自定义在 uTools 中快速执行的命令或脚本",
|
||||||
"main": "index.html",
|
"main": "index.html",
|
||||||
"homepage": "https://github.com/fofolee/uTools-QuickerCommand",
|
"homepage": "https://github.com/fofolee/uTools-QuickerCommand",
|
||||||
"publishPage": "https://yuanliao.info/d/296",
|
"publishPage": "https://yuanliao.info/d/424",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"author": "云之轩",
|
"author": "云之轩",
|
||||||
"logo": "logo.png",
|
"logo": "logo.png",
|
||||||
"platform": [ "win32", "darwin" ],
|
"platform": [ "win32", "darwin" ],
|
||||||
"preload": "preload.js",
|
"preload": "preload.js",
|
||||||
"features": [
|
"features": [
|
||||||
{
|
{
|
||||||
"code": "options",
|
"code": "options",
|
||||||
"explain": "自定义在 uTools 中快速执行的命令或脚本",
|
"explain": "自定义在 uTools 中快速执行的命令或脚本",
|
||||||
"cmds": [ "快捷命令", "QuickCommand" ]
|
"cmds": [ "快捷命令", "QuickCommand" ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
412
preload.js
412
preload.js
@ -1,207 +1,207 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const { spawn, exec } = require("child_process")
|
const { spawn, exec } = require("child_process")
|
||||||
const iconv = require('iconv-lite')
|
const iconv = require('iconv-lite')
|
||||||
const { clipboard } = require('electron')
|
const { clipboard } = require('electron')
|
||||||
const robot = require('./robotjs')
|
const robot = require('./robotjs')
|
||||||
|
|
||||||
//-------checkUpdate------
|
//-------checkUpdate------
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
||||||
const { shell } = require('electron');
|
const { shell } = require('electron');
|
||||||
|
|
||||||
pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')));
|
pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')));
|
||||||
logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
|
logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
|
||||||
|
|
||||||
messageBox = (options, callback) => {
|
messageBox = (options, callback) => {
|
||||||
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
||||||
callback(index);
|
callback(index);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
open = url => {
|
open = url => {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
}
|
}
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
||||||
isWin = os.platform() == 'win32' ? true : false;
|
isWin = os.platform() == 'win32' ? true : false;
|
||||||
|
|
||||||
isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true
|
isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true
|
||||||
|
|
||||||
basename = path.basename;
|
basename = path.basename;
|
||||||
|
|
||||||
dirname = __dirname;
|
dirname = __dirname;
|
||||||
|
|
||||||
pjoin = path.join;
|
pjoin = path.join;
|
||||||
|
|
||||||
exists = fs.existsSync;
|
exists = fs.existsSync;
|
||||||
|
|
||||||
getIconPath = name => {
|
getIconPath = name => {
|
||||||
let dir = path.resolve(__dirname, '..', 'QuickCommandIcons')
|
let dir = path.resolve(__dirname, '..', 'QuickCommandIcons')
|
||||||
if (!exists(dir)) fs.mkdirSync(dir);
|
if (!exists(dir)) fs.mkdirSync(dir);
|
||||||
return `../QuickCommandIcons/${name}`
|
return `../QuickCommandIcons/${name}`
|
||||||
}
|
}
|
||||||
|
|
||||||
getBase64Ico = path => {
|
getBase64Ico = path => {
|
||||||
return fs.readFileSync(path, 'base64');
|
return fs.readFileSync(path, 'base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBase64Ico = (path, b64) => {
|
saveBase64Ico = (path, b64) => {
|
||||||
fs.writeFileSync(path, b64, 'base64');
|
fs.writeFileSync(path, b64, 'base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
openFolder = () => {
|
openFolder = () => {
|
||||||
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
||||||
buttonLabel: '选择',
|
buttonLabel: '选择',
|
||||||
filters: [
|
filters: [
|
||||||
{name: 'Images', extensions: ['jpg', 'jpeg', 'png']},
|
{name: 'Images', extensions: ['jpg', 'jpeg', 'png']},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
copy = () => {
|
copy = () => {
|
||||||
var ctlKey = isWin ? 'control' : 'command';
|
var ctlKey = isWin ? 'control' : 'command';
|
||||||
robot.keyTap('c', ctlKey);
|
robot.keyTap('c', ctlKey);
|
||||||
robot.setKeyboardDelay(20);
|
robot.setKeyboardDelay(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
copyTo = text => {
|
copyTo = text => {
|
||||||
clipboard.writeText(text)
|
clipboard.writeText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
paste = () => {
|
paste = () => {
|
||||||
var ctlKey = isWin ? 'control' : 'command';
|
var ctlKey = isWin ? 'control' : 'command';
|
||||||
robot.keyTap('v', ctlKey);
|
robot.keyTap('v', ctlKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectText = () => {
|
getSelectText = () => {
|
||||||
copy();
|
copy();
|
||||||
return clipboard.readText()
|
return clipboard.readText()
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectFile = () => {
|
getSelectFile = () => {
|
||||||
copy();
|
copy();
|
||||||
var filePath;
|
var filePath;
|
||||||
if (isWin) {
|
if (isWin) {
|
||||||
filePath = clipboard.readBuffer('FileNameW').toString('ucs2');
|
filePath = clipboard.readBuffer('FileNameW').toString('ucs2');
|
||||||
filePath = filePath.replace(new RegExp(String.fromCharCode(0), 'g'), '');
|
filePath = filePath.replace(new RegExp(String.fromCharCode(0), 'g'), '');
|
||||||
} else {
|
} else {
|
||||||
filePath = clipboard.read('public.file-url').replace('file://', '');
|
filePath = clipboard.read('public.file-url').replace('file://', '');
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAddr = () => {
|
getAddr = () => {
|
||||||
robot.keyTap('d', 'alt');
|
robot.keyTap('d', 'alt');
|
||||||
robot.setKeyboardDelay(10);
|
robot.setKeyboardDelay(10);
|
||||||
return getSelectText().replace(/\\/g, '/');
|
return getSelectText().replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd = () =>
|
pwd = () =>
|
||||||
new Promise((reslove, reject) => {
|
new Promise((reslove, reject) => {
|
||||||
if (isWin) {
|
if (isWin) {
|
||||||
var addr = getAddr();
|
var addr = getAddr();
|
||||||
if (!exists(addr)) addr = `${os.homedir().replace(/\\/g, '/')}/Desktop`;
|
if (!exists(addr)) addr = `${os.homedir().replace(/\\/g, '/')}/Desktop`;
|
||||||
reslove(addr);
|
reslove(addr);
|
||||||
} else {
|
} else {
|
||||||
var cmd = `osascript -l JavaScript -e '
|
var cmd = `osascript -l JavaScript -e '
|
||||||
const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0]
|
const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0]
|
||||||
if (frontmost_app_name === "Finder") {
|
if (frontmost_app_name === "Finder") {
|
||||||
unescape(Application("Finder").insertionLocation().url()).slice(7).slice(0, -1)
|
unescape(Application("Finder").insertionLocation().url()).slice(7).slice(0, -1)
|
||||||
} else if(frontmost_app_name === "Path Finder") {
|
} else if(frontmost_app_name === "Path Finder") {
|
||||||
unescape(Application("Path Finder").finderWindows[0].target.url()).slice(7).slice(0, -1)
|
unescape(Application("Path Finder").finderWindows[0].target.url()).slice(7).slice(0, -1)
|
||||||
} else {
|
} else {
|
||||||
unescape(Application("Finder").desktop.url()).slice(7).slice(0, -1)
|
unescape(Application("Finder").desktop.url()).slice(7).slice(0, -1)
|
||||||
}
|
}
|
||||||
'`
|
'`
|
||||||
exec(cmd, (err, stdout, stderr) => {
|
exec(cmd, (err, stdout, stderr) => {
|
||||||
if (err) reject(stderr)
|
if (err) reject(stderr)
|
||||||
reslove(stdout.trim());
|
reslove(stdout.trim());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chromeUrl = () =>
|
chromeUrl = () =>
|
||||||
new Promise((reslove, reject) => {
|
new Promise((reslove, reject) => {
|
||||||
if (isWin) {
|
if (isWin) {
|
||||||
reslove(getAddr());
|
reslove(getAddr());
|
||||||
} else {
|
} else {
|
||||||
var cmd = `osascript -e 'tell application "Google Chrome"
|
var cmd = `osascript -e 'tell application "Google Chrome"
|
||||||
get URL of active tab of window 1
|
get URL of active tab of window 1
|
||||||
end tell'`
|
end tell'`
|
||||||
exec(cmd, (err, stdout, stderr) => {
|
exec(cmd, (err, stdout, stderr) => {
|
||||||
if (err) reject(stderr)
|
if (err) reject(stderr)
|
||||||
reslove(stdout.trim());
|
reslove(stdout.trim());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
special = async cmd => {
|
special = async cmd => {
|
||||||
// 判断是否 windows 系统
|
// 判断是否 windows 系统
|
||||||
if (cmd.includes('{{isWin}}')) {
|
if (cmd.includes('{{isWin}}')) {
|
||||||
let repl = isWin ? 1 : 0;
|
let repl = isWin ? 1 : 0;
|
||||||
cmd = cmd.replace(/\{\{isWin\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{isWin\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取资源管理器或访达当前目录
|
// 获取资源管理器或访达当前目录
|
||||||
if (cmd.includes('{{pwd}}')) {
|
if (cmd.includes('{{pwd}}')) {
|
||||||
let repl = await pwd();
|
let repl = await pwd();
|
||||||
cmd = cmd.replace(/\{\{pwd\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{pwd\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
// 获取 Chrome 当前链接
|
// 获取 Chrome 当前链接
|
||||||
if (cmd.includes('{{ChromeUrl}}')) {
|
if (cmd.includes('{{ChromeUrl}}')) {
|
||||||
let repl = await chromeUrl();
|
let repl = await chromeUrl();
|
||||||
cmd = cmd.replace(/\{\{ChromeUrl\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{ChromeUrl\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
// 获取剪切板的文本
|
// 获取剪切板的文本
|
||||||
if (cmd.includes('{{ClipText}}')) {
|
if (cmd.includes('{{ClipText}}')) {
|
||||||
let repl = clipboard.readText();
|
let repl = clipboard.readText();
|
||||||
cmd = cmd.replace(/\{\{ClipText\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{ClipText\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
// 获取选中的文本
|
// 获取选中的文本
|
||||||
if (cmd.includes('{{SelectText}}')) {
|
if (cmd.includes('{{SelectText}}')) {
|
||||||
let repl = getSelectText();
|
let repl = getSelectText();
|
||||||
cmd = cmd.replace(/\{\{SelectText\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{SelectText\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
// 获取选中的文件
|
// 获取选中的文件
|
||||||
if (cmd.includes('{{SelectFile}}')) {
|
if (cmd.includes('{{SelectFile}}')) {
|
||||||
let repl = getSelectFile();
|
let repl = getSelectFile();
|
||||||
cmd = cmd.replace(/\{\{SelectFile\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{SelectFile\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
run = async (cmd, option, codec, callback) => {
|
run = async (cmd, option, codec, callback) => {
|
||||||
var tmp = os.tmpdir(),
|
var tmp = os.tmpdir(),
|
||||||
bin = option.bin,
|
bin = option.bin,
|
||||||
argv = option.argv,
|
argv = option.argv,
|
||||||
ext = option.ext;
|
ext = option.ext;
|
||||||
cmd = await special(cmd);
|
cmd = await special(cmd);
|
||||||
let script = path.join(tmp, `QuickCommandTempScript.${ext}`)
|
let script = path.join(tmp, `QuickCommandTempScript.${ext}`)
|
||||||
if (ext == 'bat' || ext == 'ps1') cmd = iconv.encode(cmd, 'cp936');
|
if (ext == 'bat' || ext == 'ps1') cmd = iconv.encode(cmd, 'cp936');
|
||||||
fs.writeFileSync(script, cmd);
|
fs.writeFileSync(script, cmd);
|
||||||
var argvs = [script]
|
var argvs = [script]
|
||||||
if (argv) {
|
if (argv) {
|
||||||
argvs = argv.split(' ')
|
argvs = argv.split(' ')
|
||||||
argvs.push(script);
|
argvs.push(script);
|
||||||
}
|
}
|
||||||
if (bin) {
|
if (bin) {
|
||||||
var child = spawn(bin, argvs, { encoding: 'buffer' })
|
var child = spawn(bin, argvs, { encoding: 'buffer' })
|
||||||
} else {
|
} else {
|
||||||
var child = spawn(script, { encoding: 'buffer' })
|
var child = spawn(script, { encoding: 'buffer' })
|
||||||
}
|
}
|
||||||
var chunks = [],
|
var chunks = [],
|
||||||
err_chunks = [];
|
err_chunks = [];
|
||||||
codec = isWin ? codec : 'utf8';
|
codec = isWin ? codec : 'utf8';
|
||||||
child.stdout.on('data', chunk => {
|
child.stdout.on('data', chunk => {
|
||||||
chunks.push(iconv.decode(chunk, codec))
|
chunks.push(iconv.decode(chunk, codec))
|
||||||
})
|
})
|
||||||
child.stderr.on('data', err_chunk => {
|
child.stderr.on('data', err_chunk => {
|
||||||
err_chunks.push(iconv.decode(err_chunk, codec))
|
err_chunks.push(iconv.decode(err_chunk, codec))
|
||||||
})
|
})
|
||||||
child.on('close', code => {
|
child.on('close', code => {
|
||||||
let stdout = chunks.join("");
|
let stdout = chunks.join("");
|
||||||
let stderr = err_chunks.join("");
|
let stderr = err_chunks.join("");
|
||||||
callback(stdout, stderr)
|
callback(stdout, stderr)
|
||||||
})
|
})
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user