mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 15:04:06 +08:00
feat: 新增 quickpanel
This commit is contained in:
parent
f346fce8b8
commit
128e974b22
@ -62,7 +62,7 @@
|
|||||||
putDB({ cmd: cmd, program: program, scptarg: scptarg, customoptions: customoptions }, CFG_PREFIX + 'codeHistory')
|
putDB({ cmd: cmd, program: program, scptarg: scptarg, customoptions: customoptions }, CFG_PREFIX + 'codeHistory')
|
||||||
}
|
}
|
||||||
// 初始化
|
// 初始化
|
||||||
$("#options, #out").empty()
|
$("#options, #out, #quickpanel").empty()
|
||||||
$('body').children(':not(#wrapper)').remove()
|
$('body').children(':not(#wrapper)').remove()
|
||||||
$('body').css({overflow: 'hidden'})
|
$('body').css({overflow: 'hidden'})
|
||||||
if (handleEnter) document.removeEventListener('keydown', handleEnter)
|
if (handleEnter) document.removeEventListener('keydown', handleEnter)
|
||||||
@ -86,11 +86,15 @@
|
|||||||
if (qcparser.single) qc = qcparser.qc
|
if (qcparser.single) qc = qcparser.qc
|
||||||
}
|
}
|
||||||
editCurrentCommand(qc, false)
|
editCurrentCommand(qc, false)
|
||||||
|
} else if (code.slice(0,6) == 'panel_') {
|
||||||
|
utools.setExpendHeight(600)
|
||||||
|
let features = getPanelFeatures(payload)
|
||||||
|
showPanel(features)
|
||||||
} else {
|
} else {
|
||||||
// console.log(new Date().getTime() - window.startTime);
|
// console.log(new Date().getTime() - window.startTime);
|
||||||
$('body').css({overflow: 'auto'})
|
$('body').css({overflow: 'auto'})
|
||||||
utools.setExpendHeight(0);
|
utools.setExpendHeight(0);
|
||||||
$("#options").hide();
|
$("#options, #quickpanel").hide();
|
||||||
var db = getDB(QC_PREFIX + code),
|
var db = getDB(QC_PREFIX + code),
|
||||||
cmd = db.cmd;
|
cmd = db.cmd;
|
||||||
if (db.program == "custom") {
|
if (db.program == "custom") {
|
||||||
@ -597,11 +601,22 @@
|
|||||||
</td>`
|
</td>`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let getCurrentFts = () => {
|
||||||
|
let features = utools.getFeatures()
|
||||||
|
let currentFts = []
|
||||||
|
let quickpanels = []
|
||||||
|
features.forEach(x => x.code.slice(0, 6) == 'panel_' ? quickpanels.push(decodeURI(x.code.slice(6))) : currentFts.push(x))
|
||||||
|
return {
|
||||||
|
currentFts: currentFts,
|
||||||
|
quickpanels: quickpanels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 显示设置界面
|
// 显示设置界面
|
||||||
let showOptions = (tag = "默认") => {
|
let showOptions = (tag = "默认") => {
|
||||||
$("#options").empty().fadeIn();
|
$("#options").empty().fadeIn();
|
||||||
var currentFts = utools.getFeatures(),
|
var currentFts = getCurrentFts().currentFts
|
||||||
customFts = getAllQuickCommands();
|
var customFts = getAllQuickCommands()
|
||||||
var allTags = ["默认"]
|
var allTags = ["默认"]
|
||||||
var featureList = `
|
var featureList = `
|
||||||
<div id="featureList">
|
<div id="featureList">
|
||||||
@ -616,11 +631,16 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
featureList += `</tr></table></div>`
|
featureList += `</tr></table></div>`
|
||||||
var sidebar = `
|
var quickpanels = getCurrentFts().quickpanels
|
||||||
<div class="sidebar">
|
var sidebar =
|
||||||
${allTags.map(a => (a == tag ? '<li class="currentTag">' : '<li>') + a + '</li>').join('')}
|
`<div class="sidebar">`+
|
||||||
<li ${tag == '未分类' ? 'class="currentTag"' : ''}>未分类</li>
|
allTags.map(x => {
|
||||||
</div>`
|
let cla = []
|
||||||
|
if (x == tag) cla.push("currentTag")
|
||||||
|
if (quickpanels.includes(x)) cla.push("panelTag")
|
||||||
|
return `<li class="${cla.join(' ')}">${x}</li>`
|
||||||
|
}).join("")
|
||||||
|
+`<li ${tag == '未分类' ? 'class="currentTag"' : ''}>未分类</li></div>`
|
||||||
var footer = `
|
var footer = `
|
||||||
<div class="foot">
|
<div class="foot">
|
||||||
<div id="clear" class="footBtn danger"><img src="img/clear.svg"><span>清除数据</span></div>
|
<div id="clear" class="footBtn danger"><img src="img/clear.svg"><span>清除数据</span></div>
|
||||||
@ -629,11 +649,14 @@
|
|||||||
<div id="exportAll" class="footBtn"><img src="img/exportAll.svg"><span>全部导出</span></div>
|
<div id="exportAll" class="footBtn"><img src="img/exportAll.svg"><span>全部导出</span></div>
|
||||||
<div id="viewHelps" class="footBtn"><img src="img/help.svg"><span>查看帮助</span></div>
|
<div id="viewHelps" class="footBtn"><img src="img/help.svg"><span>查看帮助</span></div>
|
||||||
<div id="getShares" class="footBtn"><img src="img/share.svg"><span>分享中心</span></div>
|
<div id="getShares" class="footBtn"><img src="img/share.svg"><span>分享中心</span></div>
|
||||||
<div id="panel" class="footBtn"><img src="img/panel.svg"><span>快捷面板</span></div>
|
<div id="addToPanel" class="footBtn"><img src="img/panel.svg"><span>快捷面板</span></div>
|
||||||
<div id="import" class="footBtn"><img src="img/import.svg"><span>导入命令</span></div>
|
<div id="import" class="footBtn"><img src="img/import.svg"><span>导入命令</span></div>
|
||||||
<div id="add" class="footBtn"><img src="img/add.svg"><span>新建命令</span></div>
|
<div id="add" class="footBtn"><img src="img/add.svg"><span>新建命令</span></div>
|
||||||
</div>`
|
</div>`
|
||||||
$("#options").append(sidebar + featureList + footer)
|
$("#options").append(sidebar + featureList + footer)
|
||||||
|
if (tag != '默认' || tag != '未分类') {
|
||||||
|
if (quickpanels.includes(tag)) $('#addToPanel').css({ "filter": "none" })
|
||||||
|
}
|
||||||
checkSharedQc()
|
checkSharedQc()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,6 +769,33 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let getPanelFeatures = tag => {
|
||||||
|
let activedCode = utools.getFeatures().map(x => x.code)
|
||||||
|
let features = utoolsFull.db.allDocs('qc_key_').filter(x => {
|
||||||
|
if (!x.data.tags) return false
|
||||||
|
if (!x.data.tags.includes(tag)) return false
|
||||||
|
if (x.data.features.platform && !x.data.features.platform.includes(window.processPlatform)) return false
|
||||||
|
if (!activedCode.includes(x.data.features.code)) return false
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return features
|
||||||
|
}
|
||||||
|
|
||||||
|
let showPanel = features => {
|
||||||
|
let panel = '<table>'
|
||||||
|
let n = 0
|
||||||
|
features.forEach(p => {
|
||||||
|
if (n % 6 == 0) panel += '<tr>'
|
||||||
|
panel += `<td>
|
||||||
|
<img src="${p.data.features.icon}" cmd="${p.data.features.cmds[0]}">
|
||||||
|
<div class="title">${p.data.features.explain}</div>
|
||||||
|
</td>`
|
||||||
|
n += 1
|
||||||
|
if (n % 6 == 0) panel +='</tr>'
|
||||||
|
});
|
||||||
|
$('#quickpanel').html(panel + '</table>').show()
|
||||||
|
}
|
||||||
|
|
||||||
let checkSharedQc = async () => {
|
let checkSharedQc = async () => {
|
||||||
let localShares = getDB(CFG_PREFIX + 'sharedQcCounts')[window.processPlatform] || 0
|
let localShares = getDB(CFG_PREFIX + 'sharedQcCounts')[window.processPlatform] || 0
|
||||||
let remoteShares = await getDocsFromYuQue()
|
let remoteShares = await getDocsFromYuQue()
|
||||||
@ -1039,9 +1089,34 @@
|
|||||||
break;
|
break;
|
||||||
case 'clear': clearAll();
|
case 'clear': clearAll();
|
||||||
break;
|
break;
|
||||||
|
case 'addToPanel': addToPanel()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let addToPanel = () => {
|
||||||
|
let tag = $('.currentTag').text()
|
||||||
|
if (tag == '默认' || tag == '未分类') return quickcommand.showMessageBox('当前标签不支持', 'error')
|
||||||
|
let code = `panel_${encodeURI(tag)}`
|
||||||
|
if (!utoolsFull.removeFeature(code)) {
|
||||||
|
let features = getPanelFeatures(tag)
|
||||||
|
if (features.length == 0) return quickcommand.showMessageBox('快捷面板仅支持匹配模式为关键词的命令,当前标签不存在该类型命令或者该命令未启用', 'error', 8000)
|
||||||
|
let feature = {
|
||||||
|
code: code,
|
||||||
|
explain: `${tag}面板`,
|
||||||
|
cmds: [tag],
|
||||||
|
icon: "logo/quickpanel.png"
|
||||||
|
}
|
||||||
|
utoolsFull.setFeature(feature);
|
||||||
|
$('#addToPanel').css({ "filter": "none" })
|
||||||
|
$('.currentTag').addClass('panelTag')
|
||||||
|
quickcommand.showMessageBox(`已为当前标签启动快捷面板<br>utools 中直接输入<b style="color: #b80233;display: contents;">${tag}</b>即可进入`, 'success', 5000)
|
||||||
|
} else {
|
||||||
|
$('#addToPanel').attr("style", "")
|
||||||
|
$('.currentTag').removeClass('panelTag')
|
||||||
|
quickcommand.showMessageBox("已取消当前标签的快捷面板")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let editCurrentCommand = async (data, animate = true) => {
|
let editCurrentCommand = async (data, animate = true) => {
|
||||||
let features = data.features || {}
|
let features = data.features || {}
|
||||||
let code = features.code
|
let code = features.code
|
||||||
@ -1053,6 +1128,7 @@
|
|||||||
fromShare: data.fromShare
|
fromShare: data.fromShare
|
||||||
}
|
}
|
||||||
if (data.tags && data.tags.includes("默认")) readonly = true
|
if (data.tags && data.tags.includes("默认")) readonly = true
|
||||||
|
if($('#options').is(":empty")) showOptions()
|
||||||
showCustomize(readonly);
|
showCustomize(readonly);
|
||||||
$('#customize').data('extraInfo', extraInfo)
|
$('#customize').data('extraInfo', extraInfo)
|
||||||
data.tags && $('#tags').val(data.tags).trigger('change')
|
data.tags && $('#tags').val(data.tags).trigger('change')
|
||||||
@ -1802,14 +1878,14 @@
|
|||||||
<input type="text" id="customarg" placeholder="解释器参数">
|
<input type="text" id="customarg" placeholder="解释器参数">
|
||||||
<input type="text" id="customext" placeholder="后缀,不含.">
|
<input type="text" id="customext" placeholder="后缀,不含.">
|
||||||
</span>
|
</span>
|
||||||
<span id="runCode" class="footBtn robot">运 行</span>
|
<span id="runCode" class="robot">运 行</span>
|
||||||
<span id="charset" class="footBtn robot">编码设置</span>
|
<span id="charset" class="robot">编码设置</span>
|
||||||
<input type="text" id="scptarg" placeholder="脚本参数">
|
<input type="text" id="scptarg" placeholder="脚本参数">
|
||||||
<span class="quickactions">
|
<span class="quickactions">
|
||||||
<span id="beautifyCode" class="footBtn robot">格式化</span>
|
<span id="beautifyCode" class="robot">格式化</span>
|
||||||
<!--<span id="addAction" class="footBtn robot">﹢动作</span>
|
<!--<span id="addAction" class="robot">﹢动作</span>
|
||||||
<span id="addKey" class="footBtn robot">﹢按键</span>-->
|
<span id="addKey" class="robot">﹢按键</span>-->
|
||||||
<span id="showHelp" class="footBtn robot">?文档</span>
|
<span id="showHelp" class="robot">?文档</span>
|
||||||
</span>
|
</span>
|
||||||
<textarea id="cmd" placeholder="可以直接拖放脚本文件至此处, 支持VSCode快捷键\nCtrl+B 运行\nCtrl+F 搜索\nAlt+Enter 全屏\nShift+Alt+F 格式化(仅JS/PY)"></textarea>
|
<textarea id="cmd" placeholder="可以直接拖放脚本文件至此处, 支持VSCode快捷键\nCtrl+B 运行\nCtrl+F 搜索\nAlt+Enter 全屏\nShift+Alt+F 格式化(仅JS/PY)"></textarea>
|
||||||
</div>
|
</div>
|
||||||
@ -1818,7 +1894,7 @@
|
|||||||
createEditor()
|
createEditor()
|
||||||
$(".CodeMirror").addClass('CodeMirror-coderunner')
|
$(".CodeMirror").addClass('CodeMirror-coderunner')
|
||||||
$("#customize").css({ top: '0px', padding: '0px' });
|
$("#customize").css({ top: '0px', padding: '0px' });
|
||||||
$("span.customscript > input").css({"height": "30px"})
|
$("span.customscript > input").css({"height": "26px"})
|
||||||
var history = getDB(CFG_PREFIX + 'codeHistory')
|
var history = getDB(CFG_PREFIX + 'codeHistory')
|
||||||
createProgramSelect2(140, true)
|
createProgramSelect2(140, true)
|
||||||
if (file) {
|
if (file) {
|
||||||
@ -1937,6 +2013,11 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#quickpanel").on('click', 'img', function () {
|
||||||
|
let cmd = $(this).attr('cmd')
|
||||||
|
utools.redirect(cmd)
|
||||||
|
})
|
||||||
|
|
||||||
Mousetrap.bind('ctrl+s', () => {
|
Mousetrap.bind('ctrl+s', () => {
|
||||||
SaveCurrentCommand()
|
SaveCurrentCommand()
|
||||||
return false
|
return false
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<div id="options"></div>
|
<div id="options"></div>
|
||||||
|
<div id="quickpanel"></div>
|
||||||
<pre id="out" class="output"></pre>
|
<pre id="out" class="output"></pre>
|
||||||
<script src="assets/index.js"></script>
|
<script src="assets/index.js"></script>
|
||||||
</div>
|
</div>
|
||||||
|
BIN
src/logo/quickpanel.png
Normal file
BIN
src/logo/quickpanel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
Loading…
x
Reference in New Issue
Block a user