亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 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 關注
  • 366 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號