diff --git a/README.md b/README.md index f3f8cd5..452b77f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# 快捷命令 V2.1.1 +# 快捷命令 V2.2.0 -[](https://github.com/fofolee/uTools-QuickerCommand/stargazers) [](https://github.com/fofolee/uTools-QuickerCommand/network/members) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/LICENSE) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/src/helps/CHANGELOG.md) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) +[](https://github.com/fofolee/uTools-QuickerCommand/stargazers) [](https://github.com/fofolee/uTools-QuickerCommand/network/members) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/LICENSE) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/src/helps/CHANGELOG.md) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) ## 简介 diff --git a/src/README.md b/src/README.md index f3f8cd5..452b77f 100644 --- a/src/README.md +++ b/src/README.md @@ -1,8 +1,8 @@ -# 快捷命令 V2.1.1 +# 快捷命令 V2.2.0 -[](https://github.com/fofolee/uTools-QuickerCommand/stargazers) [](https://github.com/fofolee/uTools-QuickerCommand/network/members) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/LICENSE) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/src/helps/CHANGELOG.md) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) +[](https://github.com/fofolee/uTools-QuickerCommand/stargazers) [](https://github.com/fofolee/uTools-QuickerCommand/network/members) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/LICENSE) [](https://github.com/fofolee/uTools-QuickerCommand/blob/master/src/helps/CHANGELOG.md) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) [](https://yuanliao.info/d/424) ## 简介 diff --git a/src/helps/CHANGELOG.html b/src/helps/CHANGELOG.html index 38dbc42..53fac98 100644 --- a/src/helps/CHANGELOG.html +++ b/src/helps/CHANGELOG.html @@ -2,14 +2,15 @@
-在新建命令支持选择任意文件作为图标
.PNG
.JPG
.ICO
等文件时,则以图片作为图标.EXE
.APP
时,则以程序的图标作为图标新增 quickcommand.enterData
用以获取进入插件时匹配的类型和数据,用法详见文档
提供一个示例,作为专业模式
下配置
的默认值
输出选项添加忽略输出并保留窗口
添加专业模式
的匹配选项
features.cmds
一致quickcommand.showTextAera
新增一个参数可以设置默认文本值
-
MatchedFiles
匹配的文件路径中包含$$
时会被处理成$
的问题本次带来了 海量更新,请仔细看完更新日志~
更新后第一次进入插件会显示空白一段时间,是在对老版本的命令做兼容处理,属于正常现象
可以在线下载分享的命令
全面兼容暗黑模式
内置文本处理
,find GUI
,执行 shell 命令
等多个实用快捷命令,均使用新版本新增功能实现
新增一个脚本编辑器,可以直接进行脚本的编辑及测试
支持通过关键词或文件匹配方式进入
新增一篇帮助文档
分离插件后可以多开
模拟动作
模式改名为quickcommand
C#
,需要安装 .net framework v4.0.30319C
脚本, 需要安装 gcc 并加入环境变量shell
脚本custom
可以自定义解释器的路径、参数、脚本后缀以及输出解码的方式{{MatchedFiles}}
用来获取匹配的文件{{MatchedFiles}}
及{{WindowInfo}}
支持获取特殊的键值,比如通过 {{WindowInfo.id}}
获取匹配的窗口 id ,通过{{MatchedFiles[0].path}}
获取匹配的第一个文件的路径{{subinput:placeholder}}
的格式来自定义占位符{{pwd}}
获取失败时返回桌面路径防误操作
数据库存储结构重构,解决某些情况下数据同步时产生的异常
require
custom
+延时
合并到+动作中
添加模拟操作
的功能,在类型
下拉框内选取
特殊变量
的下拉框,但实际是支持的脚本报错时提供跳转至临时脚本目录的选项
添加一个下载命令
的按钮,可以跳转到样例命令库,如果你不知道怎么去编写一个目录,可以尝试下载导入进行参考
(貌似)修复了执行完命令后,再次呼出uTools会短暂显示命令关键词的bug,该bug可能是由先隐藏uTools再退出插件所引起
主输入框正则匹配
,如果原有命令中使用了{{pwd}}等变量的,请重新编辑该命令,将命令调整为通过uTools呼出前的窗口匹配
通过uTools呼出前的窗口匹配
的模式,现在可以快速编写一个应用到当前活动窗口的脚本关键字
,主输入框正则匹配
,活动窗口匹配
三种方式来调用自定义的脚本当前窗口信息
,输出json
格式的窗口相关信息,将原先的特殊变量用户名
改为本机唯一ID
,方便针对不同电脑编写脚本,两个变量均通过官方API获取发送系统通知
的输出模式 By imxiny在终端显示
的输出模式, 用以解决脚本需要显示动态输出的问题, 如 curl 命令 issueCommandCollections
文件夹,用以作为编写命令的样例,同时大家可以提交PR丰富这个命令库 CommandCollectionsLF
, windows 无法识别 issueNewCommand
功能,方便快速进入新建命令界面运行脚本
功能
在新建命令支持选择任意文件作为图标
.PNG
.JPG
.ICO
等文件时,则以图片作为图标.EXE
.APP
时,则以程序的图标作为图标新增 quickcommand.enterData
用以获取进入插件时匹配的类型和数据,用法详见文档
提供一个示例,作为专业模式
下配置
的默认值
输出选项添加忽略输出并保留窗口
添加专业模式
的匹配选项
features.cmds
一致quickcommand.showTextAera
新增一个参数可以设置默认文本值
+
MatchedFiles
匹配的文件路径中包含$$
时会被处理成$
的问题本次带来了 海量更新,请仔细看完更新日志~
更新后第一次进入插件会显示空白一段时间,是在对老版本的命令做兼容处理,属于正常现象
可以在线下载分享的命令
全面兼容暗黑模式
内置文本处理
,find GUI
,执行 shell 命令
等多个实用快捷命令,均使用新版本新增功能实现
新增一个脚本编辑器,可以直接进行脚本的编辑及测试
支持通过关键词或文件匹配方式进入
新增一篇帮助文档
分离插件后可以多开
模拟动作
模式改名为quickcommand
C#
,需要安装 .net framework v4.0.30319C
脚本, 需要安装 gcc 并加入环境变量shell
脚本custom
可以自定义解释器的路径、参数、脚本后缀以及输出解码的方式{{MatchedFiles}}
用来获取匹配的文件{{MatchedFiles}}
及{{WindowInfo}}
支持获取特殊的键值,比如通过 {{WindowInfo.id}}
获取匹配的窗口 id ,通过{{MatchedFiles[0].path}}
获取匹配的第一个文件的路径{{subinput:placeholder}}
的格式来自定义占位符{{pwd}}
获取失败时返回桌面路径防误操作
数据库存储结构重构,解决某些情况下数据同步时产生的异常
require
custom
+延时
合并到+动作中
添加模拟操作
的功能,在类型
下拉框内选取
特殊变量
的下拉框,但实际是支持的脚本报错时提供跳转至临时脚本目录的选项
添加一个下载命令
的按钮,可以跳转到样例命令库,如果你不知道怎么去编写一个目录,可以尝试下载导入进行参考
(貌似)修复了执行完命令后,再次呼出uTools会短暂显示命令关键词的bug,该bug可能是由先隐藏uTools再退出插件所引起
主输入框正则匹配
,如果原有命令中使用了{{pwd}}等变量的,请重新编辑该命令,将命令调整为通过uTools呼出前的窗口匹配
通过uTools呼出前的窗口匹配
的模式,现在可以快速编写一个应用到当前活动窗口的脚本关键字
,主输入框正则匹配
,活动窗口匹配
三种方式来调用自定义的脚本当前窗口信息
,输出json
格式的窗口相关信息,将原先的特殊变量用户名
改为本机唯一ID
,方便针对不同电脑编写脚本,两个变量均通过官方API获取发送系统通知
的输出模式 By imxiny在终端显示
的输出模式, 用以解决脚本需要显示动态输出的问题, 如 curl 命令 issueCommandCollections
文件夹,用以作为编写命令的样例,同时大家可以提交PR丰富这个命令库 CommandCollectionsLF
, windows 无法识别 issuequickcommand❖ UI 交互showButtonBox(buttons, title)
showInputBox(placeHolders, title)
showSelectList(selects, options)
updateSelectList(opt, id)
showTextAera(placeholder, value)
showMessageBox(message, icon, time)
showConfirmBox(title)
❖ 延时函数sleep(ms)
setTimeout(callback, ms)
❖ 前端封装htmlParse(html)
downloadFile(url, file | options)
uploadFile(url, file | options, name, formData)
❖ nodejs 封装loadRemoteScript(url)
kill(pid, signal)
❖ utools 封装enterData
simulateCopy()
simulatePaste()
其他nodejs❖ 文档❖ 上下文electron❖ 文档❖ 上下文utools❖ 文档❖ 上下文
showButtonBox(buttons, title)
buttons: Array 每一个元素对应一个按钮
title: String | undefined 对话框标题
返回: Promise
显示一个按钮对话框,用来接收用户的输入
示例
xxxxxxxxxx
// then 写法
quickcommand.showButtonBox(["按钮1", "按钮2", "按钮3"]).then(({ id, text }) => {
console.log(`选择了第${id+1}个按钮`)
console.log(`按钮的文本为${text}`)
})
// async 写法
(async () =>{
let button = await quickcommand.showButtonBox(["按钮1", "按钮2", "按钮3"])
console.log(`选择了第${button.id+1}个按钮`)
console.log(`按钮的文本为${button.text}`)
})()
// 捕获错误
quickcommand.showButtonBox().catch(e => {
console.log(e)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: 通过 find 查找文件
quickcommand.showButtonBox(['打开文件', '在文件管理器中定位', '复制文件路径']).then(x => {
switch (x.id) {
case 0:
utools.shellOpenItem(file);
break;
case 1:
utools.shellShowItemInFolder(file);
break;
case 2:
utools.copyText(file);
break;
default:
break;
}
})
showInputBox(placeHolders, title)
placeHolders: Array 每一个占位符对应一个输入框
title: String | undefined 对话框标题
返回: Promise
显示一个输入框界面,用来接用户的输入
示例
xxxxxxxxxx
quickcommand.showInputBox(["输入框1", "输入框2", "输入框3"]).then(values => {
console.log(`输入的内容分别为${values}`)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: 文本替换
quickcommand.showInputBox(["要替换的内容,两边加 / 使用正则", "替换为的内容"]).then(inputs => {
var search = inputs[0]
var repl = inputs[1]
utools.hideMainWindow()
quickcommand.sleep(300)
quickcommand.simulateCopy()
quickcommand.sleep(100)
var source = electron.clipboard.readText()
source = source.replace(search, repl)
})
showSelectList(selects, options)
selects: Array 每一个元素对应一个列表选项
options: Array | undefined 列表的选项
plaintext
、html
、json
三种,默认为plaintext
返回: Promise
optionType
为json
时,对应json
里的每一个属性 显示一个支持搜索的且可以动态更新的选项列表
当指定optionType
为json
时,类似于插件开发的列表模式
,title
、description
和icon
分别表示标题、描述和图标,其中title
为必备属性
示例
xxxxxxxxxx
// plaintext
var opt = []
for (var i = 0; i < 15; i++) {
// 每一个选项为文本格式
opt.push(`选项` + i)
}
quickcommand.showSelectList(opt).then(choise => {
console.log(`选择的选项为${choise.text}`)
})
// json
var opt = []
for (var i = 0; i < 15; i++) {
// 每一个选项为 json 格式
opt.push({title: `选项${i}`, description: `选项${i}的描述`, abcd: `选项${i}的自定义属性`})
}
quickcommand.showSelectList(opt, {optionType: 'json'}).then(choise => {
console.log(`选择的选项为${choise.title}`)
})
// html
var opt = []
for (var i = 0; i < 15; i++) {
// 每一个选项为 html 格式
opt.push(`<div style="color: red">选项${i}</div>`)
}
quickcommand.showSelectList(opt, {optionType: 'html'}).then(choise => {
console.log(`选择的选项为${quickcommand.htmlParse(choise.text).body.innerText}`)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: 文本处理
let textManipulation = [ ]
let text = quickcommand.payload
let options = textManipulation.map(t => {
return {
title: t.name,
description: t.func(text)
}
})
quickcommand.showSelectList(options, { optionType: 'json' })
.then(choise => {
console.log(choise.description)
utools.copyText(choise.description)
})
axios.post('http://fy.iciba.com/ajax.php?a=fy', `f=auto&t=auto&w=${text}`)
.then(res => {
let content = res.data.content
let trans = content.out ? content.out : content.word_mean
let opt = textManipulation[0]
opt.description = trans
quickcommand.updateSelectList(opt, 0)
})
updateSelectList(opt, id)
动态更新当前的选项列表的选项。
示例
xxxxxxxxxx
// 初始状态只有 1、2、3 三个选项
quickcommand.showSelectList(['1','2','3']).then(x=>{
console.log(x)
})
// 1s 后追加一个选项
quickcommand.setTimeout(()=>{
quickcommand.updateSelectList('4')
}, 1000)
// 2s 后更新第二个选项的值
quickcommand.setTimeout(()=>{
quickcommand.updateSelectList('updated', 1)
}, 2000)
showTextAera(placeholder, value)
placeholder: String | undefined 文本框占位符
value: String | undefined 默认的文本值
返回: Promise
显示一个文本框界面,用来接用户的输入
示例
xxxxxxxxxx
quickcommand.showTextAera("请输入文本").then(text=>{
console.log(`输入的文本为${text}`)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: vscode代码片段生成器
var snippet = {}
quickcommand.showTextAera("请输入代码片段").then(code => {
snippet.body = code.split("\n")
quickcommand.showInputBox(["代码片段的描述", "触发代码片段的关键词"])
.then(inputs => {
snippet.prefix = inputs[1]
snippet.description = inputs[0]
var result = `"${inputs[0]}": ` + JSON.stringify(snippet, null, '\t')
console.log(result)
utools.copyText(result)
quickcommand.showMessageBox('已复制')
})
})
showMessageBox(message, icon, time)
success
、error
、warning
、info
、question
,默认为success
3000
显示一个自动消失的提示框
示例
xxxxxxxxxx
quickcommand.showMessageBox("这是一段3s后自动消失的成功提示")
quickcommand.showMessageBox("这是一段3s后自动消失的失败提示", "error")
showConfirmBox(title)
title: String | undefined 提示的标题
返回: Promise
显示一个确认框
xxxxxxxxxx
quickcommand.showConfirmBox().then(confirmed => {
confirmed && console.log('点击了确定')
})
sleep(ms)
由于setTimeout
在electron中存在限制,在隐藏到后台时不会被执行,在vm2中也有bug,所以在quickcommand的环境下被禁用了,但对于模拟按键之类的场景,延迟是不可缺少的,所以提供了sleep
函数来解决这个问题
示例
xxxxxxxxxx
utools.simulateKeyboardTap('d', 'alt')
quickcommand.sleep(200)
utools.simulateKeyboardTap('c', 'ctrl')
setTimeout(callback, ms)
用法和setTimeout
一样,但实现原理不一样,sleep
的异步版本
示例
xxxxxxxxxx
quickcommand.setTimeout(()=>{
console.log('2000毫秒后执行')
}, 2000)
htmlParse(html)
html
文本DOM
对象将给定的html
字符串解析为DOM
对象,用于快速编写爬虫脚本
示例
xxxxxxxxxx
var html = `<a href="https://u.tools/">uTools</a>`
var href = quickcommand.htmlParse(html).querySelector('a').href
console.log(`解析出来的a标签地址为${href}`)
downloadFile(url, file | options)
url: String 地址
file | options :
Object
时,表示弹出对话框的 options
,格式和 utools.showSaveDialog
中的 options
一致返回: Promise
下载文件,可选直接下载到指定路径,或者弹出对话框选择下载路径
xxxxxxxxxx
// 下载文件到D:/
quickcommand.downloadFile('https://res.u-tools.cn/currentversion/uTools-1.1.3.exe', 'D:/')
// 下载文件,并弹出对话框询问保存路径
quickcommand.downloadFile('https://res.u-tools.cn/currentversion/uTools-1.1.3.exe')
uploadFile(url, file | options, name, formData)
url: String 地址
file | options :
Object
时,表示弹出对话框的 options
,格式和 utools.showOpenDialog
中的 options
一致name: String | undefined 文件名,默认为file
formData: Object | undefined 其他需要添加的表单数据
返回: Promise
上传文件,可以直接上传指定文件,或者弹出对话框选择要上传的文件,可以自定义表单数据
xxxxxxxxxx
// 上传图片到图床
quickcommand.uploadFile("https://imgkr.com/api/v2/files/upload", "C:\\test.jpg").then(res=>{
console.log('上传成功,图片地址为:' + res.data.data)
})
// 包含额外表单数据
quickcommand.uploadFile("https://catbox.moe/user/api.php", "C:\\test.jpg", 'fileToUpload', {
"reqtype": "fileupload"
}).then(res=>{
console.log('上传成功,图片地址为:' + res.data)
})
loadRemoteScript(url)
url: String 脚本地址
返回: Promise
加载一个远程脚本文件
xxxxxxxxxx
let remote = 'https://cdn.jsdelivr.net/npm/sweetalert2@9'
quickcommand.loadRemoteScript(remote).then(swal => {
swal.fire('已加载 sweetalert2 并成功弹窗')
})
// async/await
(async () => {
let remote = 'https://cdn.jsdelivr.net/npm/sweetalert2@9'
const swal = await quickcommand.loadRemoteScript(remote)
swal.fire('已加载 sweetalert2 并成功弹窗')
})()
kill(pid, signal)
'SIGTERM'
将 signal
发送给 pid
标识的进程 , 默认为关闭进程,同process.kill
示例
xxxxxxxxxx
quickcommand.kill(16084)
enterData
Object 对应utools.onPluginEnter
的 code
type
和 payload
text
img
files
regex
over
window
关键字
时,返回进入插件的关键字;为正则
时,返回匹配的文本;为窗口
时,返回匹配的窗口信息;为文件
时,返回匹配的文件信息示例
x
// 匹配模式为正则/划词时
if (quickcommand.enterData.type == 'regex'){
var text = quickcommand.enterData.payload
console.log(`主输入框匹配的文本为${text}`)
}
simulateCopy()
模拟复制操作
simulatePaste()
模拟粘贴操作
require: ƒ require(path)
os: {arch: ƒ, cpus: ƒ, endianness: ƒ, freemem: ƒ, getPriority: ƒ, …}
fs: {appendFile: ƒ, appendFileSync: ƒ, access: ƒ, accessSync: ƒ, chown: ƒ, …}
path: {resolve: ƒ, normalize: ƒ, isAbsolute: ƒ, join: ƒ, relative: ƒ, …}
child_process: {_forkChild: ƒ, ChildProcess: ƒ, exec: ƒ, execFile: ƒ, execFileSync: ƒ, …}
util: {_errnoException: ƒ, _exceptionWithHostPort: ƒ, _extend: ƒ, callbackify: ƒ, debuglog: ƒ, …}
Buffer: ƒ Buffer(arg, encodingOrOffset, length)
process: process {version: "v12.14.1", versions: {…}, arch: "x64", …}
TextDecoder: ƒ TextDecoder()
TextEncoder: ƒ TextEncoder()
URL: ƒ URL()
URLSearchParams: ƒ URLSearchParams()
axios: ƒ wrap()
quickcommand❖ UI 交互showButtonBox(buttons, title)
showInputBox(placeHolders, title)
showSelectList(selects, options)
updateSelectList(opt, id)
showTextAera(placeholder, value)
showMessageBox(message, icon, time)
showConfirmBox(title)
❖ 延时函数sleep(ms)
setTimeout(callback, ms)
❖ 前端封装htmlParse(html)
downloadFile(url, file | options)
uploadFile(url, file | options, name, formData)
❖ nodejs 封装loadRemoteScript(url)
kill(pid, signal)
runVbs(script)
❖ utools 封装enterData
simulateCopy()
simulatePaste()
其他nodejs❖ 文档❖ 上下文electron❖ 文档❖ 上下文utools❖ 文档❖ 上下文
showButtonBox(buttons, title)
buttons: Array 每一个元素对应一个按钮
title: String | undefined 对话框标题
返回: Promise
显示一个按钮对话框,用来接收用户的输入
示例
xxxxxxxxxx
// then 写法
quickcommand.showButtonBox(["按钮1", "按钮2", "按钮3"]).then(({ id, text }) => {
console.log(`选择了第${id+1}个按钮`)
console.log(`按钮的文本为${text}`)
})
// async 写法
(async () =>{
let button = await quickcommand.showButtonBox(["按钮1", "按钮2", "按钮3"])
console.log(`选择了第${button.id+1}个按钮`)
console.log(`按钮的文本为${button.text}`)
})()
// 捕获错误
quickcommand.showButtonBox().catch(e => {
console.log(e)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: 通过 find 查找文件
quickcommand.showButtonBox(['打开文件', '在文件管理器中定位', '复制文件路径']).then(x => {
switch (x.id) {
case 0:
utools.shellOpenItem(file);
break;
case 1:
utools.shellShowItemInFolder(file);
break;
case 2:
utools.copyText(file);
break;
default:
break;
}
})
showInputBox(placeHolders, title)
placeHolders: Array 每一个占位符对应一个输入框
title: String | undefined 对话框标题
返回: Promise
显示一个输入框界面,用来接用户的输入
示例
xxxxxxxxxx
quickcommand.showInputBox(["输入框1", "输入框2", "输入框3"]).then(values => {
console.log(`输入的内容分别为${values}`)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: 文本替换
quickcommand.showInputBox(["要替换的内容,两边加 / 使用正则", "替换为的内容"]).then(inputs => {
var search = inputs[0]
var repl = inputs[1]
utools.hideMainWindow()
quickcommand.sleep(300)
quickcommand.simulateCopy()
quickcommand.sleep(100)
var source = electron.clipboard.readText()
source = source.replace(search, repl)
})
showSelectList(selects, options)
selects: Array 每一个元素对应一个列表选项
options: Array | undefined 列表的选项
plaintext
、html
、json
三种,默认为plaintext
返回: Promise
optionType
为json
时,对应json
里的每一个属性 显示一个支持搜索的且可以动态更新的选项列表
当指定optionType
为json
时,类似于插件开发的列表模式
,title
、description
和icon
分别表示标题、描述和图标,其中title
为必备属性
示例
xxxxxxxxxx
// plaintext
var opt = []
for (var i = 0; i < 15; i++) {
// 每一个选项为文本格式
opt.push(`选项` + i)
}
quickcommand.showSelectList(opt).then(choise => {
console.log(`选择的选项为${choise.text}`)
})
// json
var opt = []
for (var i = 0; i < 15; i++) {
// 每一个选项为 json 格式
opt.push({title: `选项${i}`, description: `选项${i}的描述`, abcd: `选项${i}的自定义属性`})
}
quickcommand.showSelectList(opt, {optionType: 'json'}).then(choise => {
console.log(`选择的选项为${choise.title}`)
})
// html
var opt = []
for (var i = 0; i < 15; i++) {
// 每一个选项为 html 格式
opt.push(`<div style="color: red">选项${i}</div>`)
}
quickcommand.showSelectList(opt, {optionType: 'html'}).then(choise => {
console.log(`选择的选项为${quickcommand.htmlParse(choise.text).body.innerText}`)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: 文本处理
let textManipulation = [ ]
let text = quickcommand.payload
let options = textManipulation.map(t => {
return {
title: t.name,
description: t.func(text)
}
})
quickcommand.showSelectList(options, { optionType: 'json' })
.then(choise => {
console.log(choise.description)
utools.copyText(choise.description)
})
axios.post('http://fy.iciba.com/ajax.php?a=fy', `f=auto&t=auto&w=${text}`)
.then(res => {
let content = res.data.content
let trans = content.out ? content.out : content.word_mean
let opt = textManipulation[0]
opt.description = trans
quickcommand.updateSelectList(opt, 0)
})
updateSelectList(opt, id)
动态更新当前的选项列表的选项。
示例
xxxxxxxxxx
// 初始状态只有 1、2、3 三个选项
quickcommand.showSelectList(['1','2','3']).then(x=>{
console.log(x)
})
// 1s 后追加一个选项
quickcommand.setTimeout(()=>{
quickcommand.updateSelectList('4')
}, 1000)
// 2s 后更新第二个选项的值
quickcommand.setTimeout(()=>{
quickcommand.updateSelectList('updated', 1)
}, 2000)
showTextAera(placeholder, value)
placeholder: String | undefined 文本框占位符
value: String | undefined 默认的文本值
返回: Promise
显示一个文本框界面,用来接用户的输入
示例
xxxxxxxxxx
quickcommand.showTextAera("请输入文本").then(text=>{
console.log(`输入的文本为${text}`)
})
实例
xxxxxxxxxx
// 截取自内置快捷命令: vscode代码片段生成器
var snippet = {}
quickcommand.showTextAera("请输入代码片段").then(code => {
snippet.body = code.split("\n")
quickcommand.showInputBox(["代码片段的描述", "触发代码片段的关键词"])
.then(inputs => {
snippet.prefix = inputs[1]
snippet.description = inputs[0]
var result = `"${inputs[0]}": ` + JSON.stringify(snippet, null, '\t')
console.log(result)
utools.copyText(result)
quickcommand.showMessageBox('已复制')
})
})
showMessageBox(message, icon, time)
success
、error
、warning
、info
、question
,默认为success
3000
显示一个自动消失的提示框
示例
xxxxxxxxxx
quickcommand.showMessageBox("这是一段3s后自动消失的成功提示")
quickcommand.showMessageBox("这是一段3s后自动消失的失败提示", "error")
showConfirmBox(title)
title: String | undefined 提示的标题
返回: Promise
显示一个确认框
xxxxxxxxxx
quickcommand.showConfirmBox().then(confirmed => {
confirmed && console.log('点击了确定')
})
sleep(ms)
由于setTimeout
在electron中存在限制,在隐藏到后台时不会被执行,在vm2中也有bug,所以在quickcommand的环境下被禁用了,但对于模拟按键之类的场景,延迟是不可缺少的,所以提供了sleep
函数来解决这个问题
示例
xxxxxxxxxx
utools.simulateKeyboardTap('d', 'alt')
quickcommand.sleep(200)
utools.simulateKeyboardTap('c', 'ctrl')
setTimeout(callback, ms)
用法和setTimeout
一样,但实现原理不一样,sleep
的异步版本
示例
xxxxxxxxxx
quickcommand.setTimeout(()=>{
console.log('2000毫秒后执行')
}, 2000)
htmlParse(html)
html
文本DOM
对象将给定的html
字符串解析为DOM
对象,用于快速编写爬虫脚本
示例
xxxxxxxxxx
var html = `<a href="https://u.tools/">uTools</a>`
var href = quickcommand.htmlParse(html).querySelector('a').href
console.log(`解析出来的a标签地址为${href}`)
downloadFile(url, file | options)
url: String 地址
file | options :
Object
时,表示弹出对话框的 options
,格式和 utools.showSaveDialog
中的 options
一致返回: Promise
下载文件,可选直接下载到指定路径,或者弹出对话框选择下载路径
xxxxxxxxxx
// 下载文件到D:/
quickcommand.downloadFile('https://res.u-tools.cn/currentversion/uTools-1.1.3.exe', 'D:/')
// 下载文件,并弹出对话框询问保存路径
quickcommand.downloadFile('https://res.u-tools.cn/currentversion/uTools-1.1.3.exe')
uploadFile(url, file | options, name, formData)
url: String 地址
file | options :
Object
时,表示弹出对话框的 options
,格式和 utools.showOpenDialog
中的 options
一致name: String | undefined 文件名,默认为file
formData: Object | undefined 其他需要添加的表单数据
返回: Promise
上传文件,可以直接上传指定文件,或者弹出对话框选择要上传的文件,可以自定义表单数据
xxxxxxxxxx
// 上传图片到图床
quickcommand.uploadFile("https://imgkr.com/api/v2/files/upload", "C:\\test.jpg").then(res=>{
console.log('上传成功,图片地址为:' + res.data.data)
})
// 包含额外表单数据
quickcommand.uploadFile("https://catbox.moe/user/api.php", "C:\\test.jpg", 'fileToUpload', {
"reqtype": "fileupload"
}).then(res=>{
console.log('上传成功,图片地址为:' + res.data)
})
loadRemoteScript(url)
url: String 脚本地址
返回: Promise
加载一个远程脚本文件
xxxxxxxxxx
let remote = 'https://cdn.jsdelivr.net/npm/sweetalert2@9'
quickcommand.loadRemoteScript(remote).then(swal => {
swal.fire('已加载 sweetalert2 并成功弹窗')
})
// async/await
(async () => {
let remote = 'https://cdn.jsdelivr.net/npm/sweetalert2@9'
const swal = await quickcommand.loadRemoteScript(remote)
swal.fire('已加载 sweetalert2 并成功弹窗')
})()
kill(pid, signal)
'SIGTERM'
将 signal
发送给 pid
标识的进程 , 默认为关闭进程,同process.kill
示例
xxxxxxxxxx
quickcommand.kill(16084)
runVbs(script)
script: String VBS代码
返回: Promise
windows 下运行 VBS 脚本
示例
xxxxxxxxxx
quickcommand.runVbs(`CreateObject("SAPI.SpVoice").Speak"Hello"`)
enterData
Object 对应utools.onPluginEnter
的 code
type
和 payload
text
img
files
regex
over
window
关键字
时,返回进入插件的关键字;为正则
时,返回匹配的文本;为窗口
时,返回匹配的窗口信息;为文件
时,返回匹配的文件信息示例
xxxxxxxxxx
// 匹配模式为正则/划词时
if (quickcommand.enterData.type == 'regex'){
var text = quickcommand.enterData.payload
console.log(`主输入框匹配的文本为${text}`)
}
simulateCopy()
模拟复制操作
simulatePaste()
模拟粘贴操作
require: ƒ require(path)
os: {arch: ƒ, cpus: ƒ, endianness: ƒ, freemem: ƒ, getPriority: ƒ, …}
fs: {appendFile: ƒ, appendFileSync: ƒ, access: ƒ, accessSync: ƒ, chown: ƒ, …}
path: {resolve: ƒ, normalize: ƒ, isAbsolute: ƒ, join: ƒ, relative: ƒ, …}
child_process: {_forkChild: ƒ, ChildProcess: ƒ, exec: ƒ, execFile: ƒ, execFileSync: ƒ, …}
util: {_errnoException: ƒ, _exceptionWithHostPort: ƒ, _extend: ƒ, callbackify: ƒ, debuglog: ƒ, …}
Buffer: ƒ Buffer(arg, encodingOrOffset, length)
process: process {version: "v12.14.1", versions: {…}, arch: "x64", …}
TextDecoder: ƒ TextDecoder()
TextEncoder: ƒ TextEncoder()
URL: ƒ URL()
URLSearchParams: ƒ URLSearchParams()
axios: ƒ wrap()