在 Confluence 的 Javascript 中添加自定义键快捷键



在我的工作中,我们使用Confluence。我需要编辑页面上等宽格式的快捷方式。 本机快捷方式是 CTRL+SHIFT+M。它是在 Opera by MyFlow 功能中获取的,无法更改。

有没有一个选项可以使用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");

干杯

附言 感谢这篇文章:

  • https://webapps.stackexchange.com/questions/35383/shortcut-key-for-monospaced-character-format-in-confluence(过时,但有助于理解如何传递参数)
  • https://searchcode.com/codesearch/view/37330905/#47,请查看Confluence.KeyboardShortcuts中的快捷方式列表

P.P.S. 浏览器就绪的 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();

最新更新