diff --git a/plugin/helps/CHANGELOG.html b/plugin/helps/CHANGELOG.html deleted file mode 100644 index 904bc0e..0000000 --- a/plugin/helps/CHANGELOG.html +++ /dev/null @@ -1,697 +0,0 @@ - - -
- -新增快捷面板 beta
收藏网址
、收藏文件
使用新增 quickcommand.runInTermial
导入命令式会弹出选择窗口,而不是直接导入
代码格式调整
修复一个样式 bug
NewCommand
功能,方便快速进入新建命令界面运行脚本
功能收藏网址
,朗读
, 和新版的运行脚本
在新建命令支持选择任意文件作为图标
.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 无法识别 issue一、更新日志二、添加命令基础常用动作模拟按键进阶匹配关键字正则/划词窗口/进程复制/选中文件专业模式环境quickcommandpython、cmd、shell 、php 等环境插值变量全模式可用匹配窗口/进程时可用匹配正则/划词时可用匹配复制/选中文件时可用输出三、导出/分享/导入导出命令分享命令导入命令获取分享四、关于作者赞赏码所有插件
通过点击+动作
①按钮进行添加
通过点击+按键
③按钮进行添加
决定通过何种方式进入插件,不同的匹配模式也会影响插值变量的使用
features.cmds
本插件内置了一些特殊的插值变量,可以获取一些特殊的值,能够加入到插件里的任意脚本中
{{isWin}}
是否Window系统, 返回1或0
{{LocalId}}
本机唯一ID
{{BrowserUrl}}
浏览器的当前链接
{{ClipText}}
获取剪贴板的文本
{{SelectText}}
获取选中的文本 (已弃用)
{{subinput}}
获取子输入框的文本,具有此变量时会在进入插件时自动启动子输入框
{{subinput:placeholder}}
的格式来自定义占位符 {{pwd}}
资源管理器或访达的当前目录
{{SelectFile}}
文件管理器选中的文件,不支持 Linux
{{WindowInfo}}
当前窗口信息,返回 JSON 格式字符串
{{WindowInfo.id}}
的格式来直接读取相应的值{{input}}
获取主输入框的文本{{MatchedFiles}}
匹配的文件,返回 JSON 格式字符串
{{MatchedFiles[0].path}}
的格式来直接读取相应的值如果脚本有输出,则可以对输出内容做如下处理
特殊符号大全
)点击命令旁的蓝色小箭头①即可导出命令,支持
点击分享命令即可一键分享当前的命令,初次分享命令,需要按照以下步骤设置 token:
1.通过 https://www.yuque.com/g/fofolee/qcshares/collaborator/join?token=6LZn2vc34dqfIQdC 成为知识库成员,如果没有语雀账号,需要先注册一个
2.生成一个具有编辑权限的 token
3.点击命令旁的蓝色小箭头①,填入生成的 token ② ,之后就可以尽情地分享命令啦
注意:
基于信任和一起共建的基础上
的,目前加入成为成员不需要通过审批确认,后期如果出现捣乱的情况会踢出成员并开启加入审批。先在此约定:命令的分享请通过插件实现,不要在 web 端(即语雀知识库内)直接修改编辑分享的命令,否则可能会导致一些不可预知的错误。发布
后才能出现在分享中心
当中。所有已发布的命令在 https://www.yuque.com/fofolee/qcreleases 可以查看到。导入命令
来导入命令可以通过以下两种方式来获取分享:
分享中心
①即可获取并导入在线分享的命令鉴于之前某位可爱的同学捐赠的时候捐错了对象,此处献上我的捐赠码~
所有由我制作的插件如下表所示,有兴趣的童鞋可以试一试~
![]() | 快捷命令 | |
![]() | 程序员手册 | |
![]() | bilibili | |
![]() | 关闭进程 | |
![]() | 插件面板 | |
![]() | 随机壁纸 | |
![]() | Github助手 | |
![]() | 文件夹助手 | |
![]() | emoji搜索 | |
![]() | 😩能不能好好说话 | |
![]() | winget | |
![]() | icons8搜索 | |
![]() | kali 工具介绍 | |
![]() | png转icon |
![]() | 快捷命令 | |
![]() | 程序员手册 | |
![]() | bilibili | |
![]() | 关闭进程 | |
![]() | 插件面板 | |
![]() | 随机壁纸 | |
![]() | Github助手 | |
![]() | 文件夹助手 | |
![]() | emoji搜索 | |
![]() | 😩能不能好好说话 | |
![]() | winget | |
![]() | icons8搜索 | |
![]() | kali 工具介绍 | |
![]() | png转icon |
axios特性浏览器支持安装案例axios APIaxios(config)axios(url[, config])请求方法的别名axios.request(config)axios.get(url[, config])axios.delete(url[, config])axios.head(url[, config])axios.options(url[, config])axios.post(url[, data[, config]])axios.put(url[, data[, config]])axios.patch(url[, data[, config]])注意并发axios.all(iterable)axios.spread(callback)创建实例axios.create([config])实例方法axios#request(config)axios#get(url[, config])axios#delete(url[, config])axios#head(url[, config])axios#options(url[, config])axios#post(url[, data[, config]])axios#put(url[, data[, config]])axios#patch(url[, data[, config]])请求配置响应结构配置默认值全局的 axios 默认值自定义实例默认值配置的优先顺序拦截器错误处理取消使用 application/x-www-form-urlencoded format浏览器Node.jsSemverPromisesTypeScript资源Credits协议
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |
---|---|---|---|---|---|---|
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 8+ ✔ |
使用 npm:
$ npm install axios
使用 bower:
xxxxxxxxxx
$ bower install axios
使用 cdn:
xxxxxxxxxx
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
执行 GET
请求
x// 为给定 ID 的 user 创建请求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// 上面的请求也可以这样做
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
执行 POST
请求
xxxxxxxxxx
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
执行多个并发请求
xxxxxxxxxx
function getUserAccount() {
return axios.get('/user/12345');
}
function getUserPermissions() {
return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
// 两个请求现在都执行完成
}));
可以通过向 axios
传递相关配置来创建请求
xxxxxxxxxx
// 发送 POST 请求
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
xxxxxxxxxx
// 获取远端图片
axios({
method:'get',
url:'http://bit.ly/2mTM3nY',
responseType:'stream'
})
.then(function(response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
xxxxxxxxxx
// 发送 GET 请求(默认的方法)
axios('/user/12345');
为方便起见,为所有支持的请求方法提供了别名
在使用别名方法时, url
、method
、data
这些属性都不必在配置中指定。
处理并发请求的助手函数
可以使用自定义配置新建一个 axios 实例
xxxxxxxxxx
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
以下是可用的实例方法。指定的配置将与实例的配置合并。
这些是创建请求时可以用的配置选项。只有 url
是必需的。如果没有指定 method
,请求将默认使用 get
方法。
xxxxxxxxxx
{
// `url` 是用于请求的服务器 URL
url: '/user',
// `method` 是创建请求时使用的方法
method: 'get', // default
// `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
// 它可以通过设置一个 `baseURL` 便于为 axios 实例的方法传递相对 URL
baseURL: 'https://some-domain.com/api/',
// `transformRequest` 允许在向服务器发送前,修改请求数据
// 只能用在 'PUT', 'POST' 和 'PATCH' 这几个请求方法
// 后面数组中的函数必须返回一个字符串,或 ArrayBuffer,或 Stream
transformRequest: [function (data, headers) {
// 对 data 进行任意转换处理
return data;
}],
// `transformResponse` 在传递给 then/catch 前,允许修改响应数据
transformResponse: [function (data) {
// 对 data 进行任意转换处理
return data;
}],
// `headers` 是即将被发送的自定义请求头
headers: {'X-Requested-With': 'XMLHttpRequest'},
// `params` 是即将与请求一起发送的 URL 参数
// 必须是一个无格式对象(plain object)或 URLSearchParams 对象
params: {
ID: 12345
},
// `paramsSerializer` 是一个负责 `params` 序列化的函数
// (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
paramsSerializer: function(params) {
return Qs.stringify(params, {arrayFormat: 'brackets'})
},
// `data` 是作为请求主体被发送的数据
// 只适用于这些请求方法 'PUT', 'POST', 和 'PATCH'
// 在没有设置 `transformRequest` 时,必须是以下类型之一:
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
// - 浏览器专属:FormData, File, Blob
// - Node 专属: Stream
data: {
firstName: 'Fred'
},
// `timeout` 指定请求超时的毫秒数(0 表示无超时时间)
// 如果请求话费了超过 `timeout` 的时间,请求将被中断
timeout: 1000,
// `withCredentials` 表示跨域请求时是否需要使用凭证
withCredentials: false, // default
// `adapter` 允许自定义处理请求,以使测试更轻松
// 返回一个 promise 并应用一个有效的响应 (查阅 [response docs](#response-api)).
adapter: function (config) {
/* ... */
},
// `auth` 表示应该使用 HTTP 基础验证,并提供凭据
// 这将设置一个 `Authorization` 头,覆写掉现有的任意使用 `headers` 设置的自定义 `Authorization`头
auth: {
username: 'janedoe',
password: 's00pers3cret'
},
// `responseType` 表示服务器响应的数据类型,可以是 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
responseType: 'json', // default
// `responseEncoding` indicates encoding to use for decoding responses
// Note: Ignored for `responseType` of 'stream' or client-side requests
responseEncoding: 'utf8', // default
// `xsrfCookieName` 是用作 xsrf token 的值的cookie的名称
xsrfCookieName: 'XSRF-TOKEN', // default
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
xsrfHeaderName: 'X-XSRF-TOKEN', // default
// `onUploadProgress` 允许为上传处理进度事件
onUploadProgress: function (progressEvent) {
// Do whatever you want with the native progress event
},
// `onDownloadProgress` 允许为下载处理进度事件
onDownloadProgress: function (progressEvent) {
// 对原生进度事件的处理
},
// `maxContentLength` 定义允许的响应内容的最大尺寸
maxContentLength: 2000,
// `validateStatus` 定义对于给定的HTTP 响应状态码是 resolve 或 reject promise 。如果 `validateStatus` 返回 `true` (或者设置为 `null` 或 `undefined`),promise 将被 resolve; 否则,promise 将被 rejecte
validateStatus: function (status) {
return status >= 200 && status < 300; // default
},
// `maxRedirects` 定义在 node.js 中 follow 的最大重定向数目
// 如果设置为0,将不会 follow 任何重定向
maxRedirects: 5, // default
// `socketPath` defines a UNIX Socket to be used in node.js.
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
// Only either `socketPath` or `proxy` can be specified.
// If both are specified, `socketPath` is used.
socketPath: null, // default
// `httpAgent` 和 `httpsAgent` 分别在 node.js 中用于定义在执行 http 和 https 时使用的自定义代理。允许像这样配置选项:
// `keepAlive` 默认没有启用
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
// 'proxy' 定义代理服务器的主机名称和端口
// `auth` 表示 HTTP 基础验证应当用于连接代理,并提供凭据
// 这将会设置一个 `Proxy-Authorization` 头,覆写掉已有的通过使用 `header` 设置的自定义 `Proxy-Authorization` 头。
proxy: {
host: '127.0.0.1',
port: 9000,
auth: {
username: 'mikeymike',
password: 'rapunz3l'
}
},
// `cancelToken` 指定用于取消请求的 cancel token
// (查看后面的 Cancellation 这节了解更多)
cancelToken: new CancelToken(function (cancel) {
})
}
某个请求的响应包含以下信息
xxxxxxxxxx
{
// `data` 由服务器提供的响应
data: {},
// `status` 来自服务器响应的 HTTP 状态码
status: 200,
// `statusText` 来自服务器响应的 HTTP 状态信息
statusText: 'OK',
// `headers` 服务器响应的头
headers: {},
// `config` 是为请求提供的配置信息
config: {},
// 'request'
// `request` is the request that generated this response
// It is the last ClientRequest instance in node.js (in redirects)
// and an XMLHttpRequest instance the browser
request: {}
}
使用 then
时,你将接收下面这样的响应 :
xxxxxxxxxx
axios.get('/user/12345')
.then(function(response) {
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
});
在使用 catch
时,或传递 rejection callback 作为 then
的第二个参数时,响应可以通过 error
对象可被使用,正如在错误处理这一节所讲。
你可以指定将被用在各个请求的配置默认值
xxxxxxxxxx
axios.defaults.baseURL = 'https://api.example.com';
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
xxxxxxxxxx
// Set config defaults when creating the instance
const instance = axios.create({
baseURL: 'https://api.example.com'
});
// Alter defaults after instance has been created
instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
配置会以一个优先顺序进行合并。这个顺序是:在 lib/defaults.js
找到的库的默认值,然后是实例的 defaults
属性,最后是请求的 config
参数。后者将优先于前者。这里是一个例子:
xxxxxxxxxx
// 使用由库提供的配置的默认值来创建实例
// 此时超时配置的默认值是 `0`
var instance = axios.create();
// 覆写库的超时默认值
// 现在,在超时前,所有请求都会等待 2.5 秒
instance.defaults.timeout = 2500;
// 为已知需要花费很长时间的请求覆写超时设置
instance.get('/longRequest', {
timeout: 5000
});
在请求或响应被 then
或 catch
处理前拦截它们。
xxxxxxxxxx
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
// 在发送请求之前做些什么
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
// 对响应数据做点什么
return response;
}, function (error) {
// 对响应错误做点什么
return Promise.reject(error);
});
如果你想在稍后移除拦截器,可以这样:
xxxxxxxxxx
const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
axios.interceptors.request.eject(myInterceptor);
可以为自定义 axios 实例添加拦截器
xxxxxxxxxx
const instance = axios.create();
instance.interceptors.request.use(function () {/*...*/});
xxxxxxxxxx
axios.get('/user/12345')
.catch(function (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
console.log(error.config);
});
Y可以使用 validateStatus
配置选项定义一个自定义 HTTP 状态码的错误范围。
xxxxxxxxxx
axios.get('/user/12345', {
validateStatus: function (status) {
return status < 500; // Reject only if the status code is greater than or equal to 500
}
})
使用 cancel token 取消请求
Axios 的 cancel token API 基于cancelable promises proposal,它还处于第一阶段。
可以使用 CancelToken.source
工厂方法创建 cancel token,像这样:
xxxxxxxxxx
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
axios.get('/user/12345', {
cancelToken: source.token
}).catch(function(thrown) {
if (axios.isCancel(thrown)) {
console.log('Request canceled', thrown.message);
} else {
// 处理错误
}
});
axios.post('/user/12345', {
name: 'new name'
}, {
cancelToken: source.token
})
// 取消请求(message 参数是可选的)
source.cancel('Operation canceled by the user.');
还可以通过传递一个 executor 函数到 CancelToken
的构造函数来创建 cancel token:
xxxxxxxxxx
const CancelToken = axios.CancelToken;
let cancel;
axios.get('/user/12345', {
cancelToken: new CancelToken(function executor(c) {
// executor 函数接收一个 cancel 函数作为参数
cancel = c;
})
});
// cancel the request
cancel();
注意: 可以使用同一个 cancel token 取消多个请求
默认情况下,axios将JavaScript对象序列化为JSON。 要以application / x-www-form-urlencoded格式发送数据,您可以使用以下选项之一。
在浏览器中,您可以使用URLSearchParams API,如下所示:
xxxxxxxxxx
const params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
axios.post('/foo', params);
请注意,所有浏览器都不支持URLSearchParams(请参阅caniuse.com),但可以使用polyfill(确保填充全局环境)。
或者,您可以使用qs库编码数据:
xxxxxxxxxx
const qs = require('qs');
axios.post('/foo', qs.stringify({ 'bar': 123 }));
或者以另一种方式(ES6),
xxxxxxxxxx
import qs from 'qs';
const data = { 'bar': 123 };
const options = {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(data),
url,
};
axios(options);
在node.js中,您可以使用querystring模块,如下所示:
xxxxxxxxxx
const querystring = require('querystring');
axios.post('http://something.com/', querystring.stringify({ foo: 'bar' }));
您也可以使用qs库。
在axios达到1.0版本之前,破坏性更改将以新的次要版本发布。 例如0.5.1和0.5.4将具有相同的API,但0.6.0将具有重大变化。
axios 依赖原生的 ES6 Promise 实现而被支持. 如果你的环境不支持 ES6 Promise,你可以使用 polyfill.
axios包括TypeScript定义。
xxxxxxxxxx
import axios from 'axios';
axios.get('/user?ID=12345');
axios深受Angular提供的、$http服务的启发。 最终,axios是为了在Angular之外使用而提供独立的类似$http服的务。
MIT
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
显示一个按钮对话框,用来接收用户的输入
示例
x// 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: Object | 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()