为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕丝7291255 2022-01-01 20:47:16
在我的工作中,我们使用 Confluence。我需要在编辑页面上进行等宽格式设置的快捷方式。本机快捷键是 CTRL+SHIFT+M。它是由 MyFlow 功能在 Opera 中获取的,无法更改。是否可以选择使用 Javascript 代码来制作它?(我可以在浏览器扩展中进行 JS 注入。)用于快捷方式的常规 JS 代码,它可以正常工作,但不能在 Confluence 编辑页面上使用:// define a handlerfunction 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 功能,它根本不会触发......有什么建议吗?
查看完整描述

1 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

成立。


//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();


查看完整回答
反对 回复 2022-01-01
  • 1 回答
  • 0 关注
  • 368 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号