mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-07 05:25: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
|
||||
|
||||
## 简介
|
||||
|
||||
自定义可以在`uTools`中快速执行的命令或脚本
|
||||
|
||||
## 功能
|
||||
|
||||
#### 快速启动
|
||||
|
||||
可以配置一些常用的命令,比如`回收站` `查看网络连接`之类
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

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

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

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

|
||||
|
||||

|
||||
|
||||
|
||||
## 下载
|
||||
|
||||
[百度网盘](https://pan.baidu.com/s/1kEEQcQ1p3Rjli2sTtmCcTg) 提取码: `rbek`
|
||||
|
||||
[项目地址](https://github.com/fofolee/uTools-QuickerCommand)
|
||||
|
||||
[插件发布页](https://yuanliao.info/d/356)
|
||||
|
||||
## 安装方法
|
||||
|
||||
将`upx`文件拖入`uTools`输入框中安装即可
|
||||
|
||||
## 关键字
|
||||
|
||||
`快捷命令` `QuickCommand`
|
||||
|
||||
## 鸣谢
|
||||
|
||||
鸣谢`uTools`团队,插件中使用的`robotJS`使用的是`剪贴板`插件中的`robotJS`,省去了自行编译的麻烦,在此感谢!
|
||||
# 快捷命令 V0.0.1
|
||||
|
||||
## 简介
|
||||
|
||||
自定义可以在`uTools`中快速执行的命令或脚本
|
||||
|
||||
## 功能
|
||||
|
||||
#### 快速启动
|
||||
|
||||
可以配置一些常用的命令,比如`回收站` `查看网络连接`之类
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

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

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

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

|
||||
|
||||

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