mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
新增 分享中心
This commit is contained in:
parent
1ec2657798
commit
4cb68bf720
@ -32,7 +32,6 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
console.log(qc);
|
|
||||||
if (isJsonQc(qc)) return { single: true, qc: qc }
|
if (isJsonQc(qc)) return { single: true, qc: qc }
|
||||||
else if (!Object.values(qc).filter(q => !isJsonQc(q)).length) return { single: false, qc: qc }
|
else if (!Object.values(qc).filter(q => !isJsonQc(q)).length) return { single: false, qc: qc }
|
||||||
else return false
|
else return false
|
||||||
@ -77,21 +76,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let clearAll = () => {
|
let clearAll = () => {
|
||||||
Swal.fire({
|
quickcommand.showConfirmBox('将会清空所有命令,请确认!').then(() => {
|
||||||
text: '将会清空所有命令,请确认!',
|
utools.db.remove('customFts');
|
||||||
icon: 'warning',
|
clearAllFeatures();
|
||||||
showCancelButton: true,
|
showOptions();
|
||||||
confirmButtonColor: '#3085d6',
|
})
|
||||||
cancelButtonColor: '#d33',
|
}
|
||||||
confirmButtonText: '确定!',
|
|
||||||
cancelButtonText: '手抖...',
|
let overwriteConfirm = () => {
|
||||||
}).then((result) => {
|
|
||||||
if (result.value) {
|
|
||||||
utools.db.remove('customFts');
|
|
||||||
clearAllFeatures();
|
|
||||||
showOptions();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
programs = {
|
programs = {
|
||||||
@ -273,7 +266,7 @@
|
|||||||
<div class="foot">
|
<div class="foot">
|
||||||
<div id="add" class="footBtn">新建命令</div>
|
<div id="add" class="footBtn">新建命令</div>
|
||||||
<div id="import" class="footBtn">导入命令</div>
|
<div id="import" class="footBtn">导入命令</div>
|
||||||
<div id="getShares" class="footBtn">获取分享</div>
|
<div id="getShares" class="footBtn">分享中心</div>
|
||||||
<div id="viewHelps" class="footBtn">查看帮助</div>
|
<div id="viewHelps" class="footBtn">查看帮助</div>
|
||||||
<div id="exportAll" class="footBtn">全部导出</div>
|
<div id="exportAll" class="footBtn">全部导出</div>
|
||||||
<div id="enableAll" class="footBtn">启用本页</div>
|
<div id="enableAll" class="footBtn">启用本页</div>
|
||||||
@ -354,7 +347,7 @@
|
|||||||
<span id="beautifyCode" class="footBtn robot">格式化</span>
|
<span id="beautifyCode" class="footBtn robot">格式化</span>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<textarea id="cmd" placeholder="◆基础◆\nquickcommand环境下,点击“﹢按键”来执行模拟按键的操作;点击“﹢动作”添加打开软件,访问网址等常\n用动作\n◆进阶◆\nquickcommand:可使用nodejs、electron、uTools、quickCommand的api,详情查看文档\n其他脚本:本机装了相应环境即可执行,可以直接拖放脚本文件至此处,可在脚本参数输入框处填写传递\n给脚本的参数\ncustom:可以手动设置解释器路径、参数、脚本后缀及编码方式\n◆快捷键◆\n支持VSCode快捷键\nAlt+Enter 全屏\nCtrl+B 运行\nCtrl+F 搜索\nShift+Alt+F 格式化(仅JS/PY)"></textarea>
|
<textarea id="cmd" placeholder="◆基础◆\nquickcommand环境下,点击“﹢按键”来执行模拟按键的操作;点击“﹢动作”添加打开软件,访问网址等\n常用动作\n◆进阶◆\nquickcommand:可使用nodejs、electron、uTools、quickCommand的api,详情查看文档\n其他脚本:本机装了相应环境即可执行,可以直接拖放脚本文件至此处,可在脚本参数输入框处填写传递\n给脚本的参数\ncustom:可以手动设置解释器路径、参数、脚本后缀及编码方式\n◆快捷键◆\n支持VSCode快捷键\nAlt+Enter 全屏\nCtrl+B 运行\nCtrl+F 搜索\nShift+Alt+F 格式化(仅JS/PY)"></textarea>
|
||||||
<p class="bottom">
|
<p class="bottom">
|
||||||
<img id="win32" class="platform" src="./img/win32.svg">
|
<img id="win32" class="platform" src="./img/win32.svg">
|
||||||
<img id="darwin" class="platform" src="./img/darwin.svg">
|
<img id="darwin" class="platform" src="./img/darwin.svg">
|
||||||
@ -659,11 +652,11 @@
|
|||||||
let extraInfo = {
|
let extraInfo = {
|
||||||
authorName: data.authorName,
|
authorName: data.authorName,
|
||||||
authorId: data.authorId,
|
authorId: data.authorId,
|
||||||
docId: data.docId
|
fromShare: data.fromShare
|
||||||
}
|
}
|
||||||
$('#options').data('extraInfo', extraInfo)
|
|
||||||
if (data.tags && data.tags.includes("默认")) readonly = true
|
if (data.tags && data.tags.includes("默认")) readonly = true
|
||||||
showCustomize(readonly);
|
showCustomize(readonly);
|
||||||
|
$('#customize').data('extraInfo', extraInfo)
|
||||||
data.tags && $('#tags').val(data.tags).trigger('change')
|
data.tags && $('#tags').val(data.tags).trigger('change')
|
||||||
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
|
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
|
||||||
$('#type').val(cmds.type).trigger("change")
|
$('#type').val(cmds.type).trigger("change")
|
||||||
@ -787,10 +780,11 @@
|
|||||||
let extraInfo = getDB('extraInfo')
|
let extraInfo = getDB('extraInfo')
|
||||||
if (jsonQc.authorId) {
|
if (jsonQc.authorId) {
|
||||||
if (jsonQc.authorId == extraInfo.authorId) menu[2] = '更新分享'
|
if (jsonQc.authorId == extraInfo.authorId) menu[2] = '更新分享'
|
||||||
|
else if (jsonQc.fromShare) menu[2] = '评论'
|
||||||
else menu[2] = '分享自:' + jsonQc.authorName
|
else menu[2] = '分享自:' + jsonQc.authorName
|
||||||
} else {
|
} else {
|
||||||
if (extraInfo.yuQueToken) menu[2] = '分享命令'
|
if (extraInfo.yuQueToken) menu[2] = '分享命令'
|
||||||
else menu[2] = '☛ 分享命令'
|
else menu[2] = '我要分享'
|
||||||
}
|
}
|
||||||
return menu
|
return menu
|
||||||
}
|
}
|
||||||
@ -813,16 +807,16 @@
|
|||||||
}, stringifyQc)
|
}, stringifyQc)
|
||||||
break;
|
break;
|
||||||
case '分享命令':
|
case '分享命令':
|
||||||
var result = await shareQCToYuQue(jsonQc)
|
|
||||||
result && quickcommand.showMessageBox('分享成功')
|
|
||||||
break;
|
|
||||||
case '更新分享':
|
case '更新分享':
|
||||||
var result = await shareQCToYuQue(jsonQc, true)
|
var result = await shareQCToYuQue(jsonQc)
|
||||||
result && quickcommand.showMessageBox('分享成功')
|
result && quickcommand.showMessageBox('分享成功,等待发布后即可在分享中心直接下载')
|
||||||
break;
|
break;
|
||||||
case '☛ 分享命令':
|
case '我要分享':
|
||||||
utools.createBrowserWindow('./helps/HELP.html?#分享命令', {width: 1280, height: 920})
|
utools.createBrowserWindow('./helps/HELP.html?#分享命令', {width: 1280, height: 920})
|
||||||
break;
|
break;
|
||||||
|
case '评论':
|
||||||
|
utools.shellOpenExternal(`https://www.yuque.com/fofolee/qcreleases/${code}`)
|
||||||
|
break;
|
||||||
case '设置 Token':
|
case '设置 Token':
|
||||||
await setYuQueToken()
|
await setYuQueToken()
|
||||||
break;
|
break;
|
||||||
@ -830,7 +824,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 一键分享到语雀
|
// 一键分享到语雀
|
||||||
let shareQCToYuQue = async (jsonQc, update = false) => {
|
let shareQCToYuQue = async jsonQc => {
|
||||||
let extraInfo = getDB('extraInfo')
|
let extraInfo = getDB('extraInfo')
|
||||||
if (!extraInfo.yuQueToken) return quickcommand.showMessageBox("请先设置 Token,点击底部「查看帮助」可查看 Token 设置方法", "error")
|
if (!extraInfo.yuQueToken) return quickcommand.showMessageBox("请先设置 Token,点击底部「查看帮助」可查看 Token 设置方法", "error")
|
||||||
jsonQc.authorId = extraInfo.authorId
|
jsonQc.authorId = extraInfo.authorId
|
||||||
@ -850,42 +844,42 @@
|
|||||||
custom_description: `作者:${jsonQc.authorName} | 环境:${jsonQc.program} | 匹配:${type} | 平台:${platform} | 标签:${tags}`
|
custom_description: `作者:${jsonQc.authorName} | 环境:${jsonQc.program} | 匹配:${type} | 平台:${platform} | 标签:${tags}`
|
||||||
}
|
}
|
||||||
yuQueClient.defaults.headers['X-Auth-Token'] = extraInfo.yuQueToken
|
yuQueClient.defaults.headers['X-Auth-Token'] = extraInfo.yuQueToken
|
||||||
let res
|
let res, repo = extraInfo.authorId == 1496740 ? 'qcreleases' : 'qcshares'
|
||||||
|
console.log(repo);
|
||||||
try {
|
try {
|
||||||
if (update) res = await yuQueClient.put('repos/fofolee/em2rng/docs/' + jsonQc.docId, parameters)
|
res = await yuQueClient.post(`repos/fofolee/${repo}/docs`, parameters)
|
||||||
else res = await yuQueClient.post('repos/fofolee/em2rng/docs', parameters)
|
if (!res.data.data) return quickcommand.showMessageBox("分享失败,不知道为啥", "error")
|
||||||
if (res.data.data) {
|
let docId = res.data.data.id
|
||||||
jsonQc.docId = res.data.data.id
|
res = await yuQueClient.put(`repos/fofolee/${repo}/docs/${docId}`, parameters)
|
||||||
putDB(jsonQc.features.code, jsonQc, 'customFts');
|
if (!res.data.data) return quickcommand.showMessageBox("分享失败,不知道为啥", "error")
|
||||||
return jsonQc
|
putDB(jsonQc.features.code, jsonQc, 'customFts');
|
||||||
} else {
|
return jsonQc
|
||||||
return quickcommand.showMessageBox("分享失败,不知道为啥", "error")
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return quickcommand.showMessageBox(error, "error")
|
return quickcommand.showMessageBox(error, "error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSharedQCFromYuQue = async () => {
|
let getSharedQCFromYuQue = async () => {
|
||||||
$('#options').hide()
|
$('#options').hide()
|
||||||
let extraInfo = getDB('extraInfo')
|
let extraInfo = getDB('extraInfo')
|
||||||
if (extraInfo.yuQueToken) yuQueClient.defaults.headers['X-Auth-Token'] = extraInfo.yuQueToken
|
if (extraInfo.yuQueToken) yuQueClient.defaults.headers['X-Auth-Token'] = extraInfo.yuQueToken
|
||||||
let res = await yuQueClient('repos/fofolee/em2rng/docs')
|
let res = await yuQueClient('repos/fofolee/qcreleases/docs')
|
||||||
let docs = res.data.data.map(d => {
|
let program, docs = res.data.data.map(d => {
|
||||||
|
program = d.custom_description.match(/环境:(.*?) /)
|
||||||
return {
|
return {
|
||||||
title: d.title,
|
title: d.title,
|
||||||
description: d.custom_description,
|
description: d.custom_description,
|
||||||
slug: d.slug,
|
slug: d.slug,
|
||||||
icon: d.last_editor.avatar_url
|
icon: `logo/${program[1]}.png`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
let choise = await quickcommand.showSelectList(docs, { optionType: 'json' })
|
let choise = await quickcommand.showSelectList(docs, { optionType: 'json' })
|
||||||
let doc = await yuQueClient(`repos/fofolee/em2rng/docs/${choise.slug}?raw=1`)
|
let doc = await yuQueClient(`repos/fofolee/qcreleases/docs/${choise.slug}?raw=1`)
|
||||||
let body = doc.data.data.body
|
let body = doc.data.data.body
|
||||||
let stringifyQc = body.match(/```json([\s\S]*)```/)[1]
|
let stringifyQc = body.match(/```json([\s\S]*)```/)[1]
|
||||||
let qc = JSON.parse(stringifyQc)
|
let qc = JSON.parse(stringifyQc)
|
||||||
$('#options').show()
|
$('#options').show()
|
||||||
qc.docId = doc.data.data.id
|
qc.fromShare = true
|
||||||
editCurrentCommand(qc)
|
editCurrentCommand(qc)
|
||||||
utools.setExpendHeight(600)
|
utools.setExpendHeight(600)
|
||||||
}
|
}
|
||||||
@ -899,27 +893,17 @@
|
|||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
$("#options").on('click', '.delBtn', function () {
|
$("#options").on('click', '.delBtn', function () {
|
||||||
Swal.fire({
|
quickcommand.showConfirmBox('删除这个快捷命令').then(() => {
|
||||||
text: '删除这个快捷命令',
|
var code = $(this).parents('tr').attr('id'),
|
||||||
icon: 'warning',
|
db = utools.db.get("customFts"),
|
||||||
showCancelButton: true,
|
data = db.data;
|
||||||
confirmButtonColor: '#3085d6',
|
delete data[code];
|
||||||
cancelButtonColor: '#d33',
|
utools.removeFeature(code);
|
||||||
confirmButtonText: '确定!',
|
utools.db.put({ _id: "customFts", data: data, _rev: db._rev });
|
||||||
cancelButtonText: '手抖...',
|
var currentTag = $('.currentTag').text()
|
||||||
}).then((result) => {
|
if ($('#featureList tr').length == 2) currentTag = "默认"
|
||||||
if (result.value) {
|
showOptions(currentTag);
|
||||||
var code = $(this).parents('tr').attr('id'),
|
})
|
||||||
db = utools.db.get("customFts"),
|
|
||||||
data = db.data;
|
|
||||||
delete data[code];
|
|
||||||
utools.removeFeature(code);
|
|
||||||
utools.db.put({ _id: "customFts", data: data, _rev: db._rev });
|
|
||||||
var currentTag = $('.currentTag').text()
|
|
||||||
if ($('#featureList tr').length == 2) currentTag = "默认"
|
|
||||||
showOptions(currentTag);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 选择图标
|
// 选择图标
|
||||||
@ -967,7 +951,7 @@
|
|||||||
if (iconame) {
|
if (iconame) {
|
||||||
base64ico = window.getBase64Ico(iconpath);
|
base64ico = window.getBase64Ico(iconpath);
|
||||||
icon = "data:image/png;base64," + base64ico;
|
icon = "data:image/png;base64," + base64ico;
|
||||||
// 未自定义使用默认
|
// 未自定义使用默认
|
||||||
} else {
|
} else {
|
||||||
icon = iconpath;
|
icon = iconpath;
|
||||||
}
|
}
|
||||||
@ -1017,9 +1001,9 @@
|
|||||||
}
|
}
|
||||||
// platform
|
// platform
|
||||||
var platform = []
|
var platform = []
|
||||||
$('.platform').not('.disabled').each(function() { platform.push($(this).attr('id')) })
|
$('.platform').not('.disabled').each(function () { platform.push($(this).attr('id')) })
|
||||||
// 添加特性
|
// 添加特性
|
||||||
var extraInfo = $('#options').data('extraInfo')
|
var extraInfo = $('#customize').data('extraInfo')
|
||||||
var pushData = {
|
var pushData = {
|
||||||
features: {
|
features: {
|
||||||
"code": code,
|
"code": code,
|
||||||
@ -1032,11 +1016,9 @@
|
|||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
output: output,
|
output: output,
|
||||||
hasSubInput: hasSubInput,
|
hasSubInput: hasSubInput,
|
||||||
scptarg: scptarg,
|
scptarg: scptarg
|
||||||
authorId: extraInfo.authorId,
|
|
||||||
authorName: extraInfo.authorName,
|
|
||||||
docId: extraInfo.docId
|
|
||||||
}
|
}
|
||||||
|
if (extraInfo) Object.assign(pushData, extraInfo)
|
||||||
if (tags) pushData.tags = tags
|
if (tags) pushData.tags = tags
|
||||||
if (program == 'custom') {
|
if (program == 'custom') {
|
||||||
pushData.customOptions = {
|
pushData.customOptions = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user