[英]Add a custom key shortcut within Javascript in Confluence
在我的工作中,我們使用 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感謝這篇文章:
Confluence.KeyboardShortcuts
中的快捷鍵列表PPS Browser-ready 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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.