猿问

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

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


是否可以选择使用 Javascript 代码来制作它?

(我可以在浏览器扩展中进行 JS 注入。)


用于快捷方式的常规 JS 代码,它可以正常工作,但不能在 Confluence 编辑页面上使用:


// 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 功能,它根本不会触发......有

什么建议吗?


慕丝7291255
浏览 369回答 1
1回答

HUWWW

成立。//Set CTRL+SHIFT+L shortcut for monospace formatting in the editorwindow.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.KeyboardShortcutsPPS 浏览器就绪 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 () {&nbsp; &nbsp; window.AJS.Rte.getEditor().shortcuts.add(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ctrl+shift+l',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "monospace",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "confMonospace"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );}());过度保护😀 :// Set monospace formatting for a key shortcut in confluence// Use a browser extension for injecting this code snippetconsole.log('include CJS');let confKeyAdd = {run: function () {&nbsp; &nbsp; this.key = {&nbsp; &nbsp; &nbsp; &nbsp; keyCode: 'ctrl+shift+l',&nbsp; &nbsp; &nbsp; &nbsp; codeType: 'monospace',&nbsp; &nbsp; &nbsp; &nbsp; codeConfType: 'confMonospace'&nbsp; &nbsp; };&nbsp; &nbsp; this.setKey();},waiter: function (shouldWaitCall, successCall, repeat = 10, interval = 1000) {&nbsp; &nbsp; let timerId;&nbsp; &nbsp; //wait here&nbsp; &nbsp; timerId = setInterval(&nbsp; &nbsp; &nbsp; &nbsp; function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (--repeat < 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('confKeyAdd: Have not found an object.');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearTimeout(timerId);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (shouldWaitCall()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('confKeyAdd: Still waiting... [' + repeat + ']');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearTimeout(timerId);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // call me!&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; successCall();&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; interval&nbsp; &nbsp; );},setKey() {&nbsp; &nbsp; let _this = this;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // first call: should-wait&nbsp; &nbsp; // second call: success&nbsp; &nbsp; this.waiter(&nbsp; &nbsp; &nbsp; &nbsp; function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('confKeyAdd: Checking...');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return typeof window.AJS === 'undefined'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || window.AJS.Rte.getEditor() === null&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || !window.AJS.Rte.getEditor().shortcuts;&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('confKeyAdd: Adding a key shortcut for: ' + _this.key.keyCode);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.AJS.Rte.getEditor().shortcuts.add(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this.key.keyCode,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this.key.codeType,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _this.key.codeConfType&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; );}};confKeyAdd.run();
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答