javascript - 在 Confluence 的 Javascript 中添加自定义快捷键
问题描述
在我的工作中,我们使用 Confluence。我需要编辑页面上等宽格式的快捷方式。本机快捷键是 CTRL+SHIFT+M。它是由 MyFlow 功能在 Opera 中获取的,无法更改。
是否可以选择使用 Javascript 代码来实现?
(我可以在浏览器扩展中进行 JS 注入。)
快捷方式的常规 JS 代码可以正常工作,但不能在汇合编辑页面上:
// define a handler
function monospaceKeyTrigger(e) {
// this would test for whichever key is 40 and the ctrl key at the same time
if (e.ctrlKey && e.shiftKey && e.keyCode == 90) {
// trigger click on monospace button
//document.getElementById("rte-monospace").click();
alert('!!monospace!!');
}
}
// register the handler
document.addEventListener('keyup', monospaceKeyTrigger, false);
那么,我错过了什么?
我想,由于编辑器 JS 功能,它根本没有触发......有
什么建议吗?
解决方案
成立。
//Set CTRL+SHIFT+L shortcut for monospace formatting in the editor
window.AJS.Rte.getEditor().shortcuts.add("ctrl+shift+l","monospace","confMonospace");
干杯
PS感谢这篇文章:
- https://webapps.stackexchange.com/questions/35383/shortcut-key-for-monospaced-character-format-in-confluence(已过时,但有助于理解如何传递参数)
- https://searchcode.com/codesearch/view/37330905/ #47,看看中的快捷方式列表
Confluence.KeyboardShortcuts
PPS 浏览器就绪的 Javascript 代码(在 Atlassian Confluence 6.15.2 中测试)
简单的 :
// Set monospace formatting for a key shortcut in confluence
// Use a browser extension for injecting this code snippet
(function () {
window.AJS.Rte.getEditor().shortcuts.add(
'ctrl+shift+l',
"monospace",
"confMonospace"
);
}());
过度保护:
// Set monospace formatting for a key shortcut in confluence
// Use a browser extension for injecting this code snippet
console.log('include CJS');
let confKeyAdd = {
run: function () {
this.key = {
keyCode: 'ctrl+shift+l',
codeType: 'monospace',
codeConfType: 'confMonospace'
};
this.setKey();
},
waiter: function (shouldWaitCall, successCall, repeat = 10, interval = 1000) {
let timerId;
//wait here
timerId = setInterval(
function () {
if (--repeat < 0) {
console.log('confKeyAdd: Have not found an object.');
clearTimeout(timerId);
return;
}
if (shouldWaitCall()) {
console.log('confKeyAdd: Still waiting... [' + repeat + ']');
return;
}
clearTimeout(timerId);
// call me!
successCall();
},
interval
);
},
setKey() {
let _this = this;
// first call: should-wait
// second call: success
this.waiter(
function () {
console.log('confKeyAdd: Checking...');
return typeof window.AJS === 'undefined'
|| window.AJS.Rte.getEditor() === null
|| !window.AJS.Rte.getEditor().shortcuts;
},
function () {
console.log('confKeyAdd: Adding a key shortcut for: ' + _this.key.keyCode);
window.AJS.Rte.getEditor().shortcuts.add(
_this.key.keyCode,
_this.key.codeType,
_this.key.codeConfType
);
},
);
}
};
confKeyAdd.run();
推荐阅读
- html - bootstrap 4 网格 - 带滑块的行
- ios - 具有垂直滚动部分的水平滚动 UICollectionView
- android - 如何检查是否仍连接到 setProcessDefaultNetwork() 设置的网络
- python - 计算熊猫中列的四分位数类别
- python - 为什么军事勋章表情符号在打印时与文本重叠?
- c# - 在编译的 C# 可执行文件中嵌入 DDL
- c# - 反代理调试 WPF
- flutter - Flutter 构建的 App 包无法正常工作
- artifact - 在软件开发过程中提到“工件”这个词是什么意思?它是源代码或文档,还是两者兼而有之?
- python - 如何使用 Trio 进行快速 Web api 调用?