MediaWiki:Common.js: Difference between revisions

From Trickster Development Wiki
mNo edit summary
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using('jquery.textSelection', function () {
mw.loader.using([
     mw.hook('wikipage.content').add(function () {
    'ext.visualEditor.core',
     'ext.visualEditor.desktopArticleTarget.init'
], function () {


        $(document).on('keydown', function (e) {
    // Wait until VE is actually ready
            // Ctrl + Shift + C
    mw.hook('ve.activationComplete').add(function () {
            if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'c') {


                // Only trigger if editing
        const target = ve.init.target;
                var $textbox = $('#wpTextbox1');
        const surface = target.getSurface();
                if (!$textbox.length) return;
        if (!surface) return;


        // Register a new command
        surface.commandRegistry.register(
            new ve.ui.Command(
                'customCode',
                'annotation',
                'toggle',
                { type: 'textStyle/code' }
            )
        );
        // Bind shortcut: Ctrl + Alt + C
        surface.getView().getDocument().on('keydown', function (e) {
            if (e.ctrlKey && e.altKey && e.key.toLowerCase() === 'c') {
                 e.preventDefault();
                 e.preventDefault();
 
                 surface.execute('customCode');
                 $textbox.textSelection(
                    'encapsulateSelection',
                    { pre: '<code>', post: '</code>' }
                );
             }
             }
         });
         });


     });
     });
});
});
/*That's to change the shitty Code command to Ctrl+Shift+q*/
/*That's to change the shitty Code command to Ctrl+alt+c*/

Latest revision as of 19:50, 18 April 2026

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using([
    'ext.visualEditor.core',
    'ext.visualEditor.desktopArticleTarget.init'
], function () {

    // Wait until VE is actually ready
    mw.hook('ve.activationComplete').add(function () {

        const target = ve.init.target;
        const surface = target.getSurface();
        if (!surface) return;

        // Register a new command
        surface.commandRegistry.register(
            new ve.ui.Command(
                'customCode',
                'annotation',
                'toggle',
                { type: 'textStyle/code' }
            )
        );

        // Bind shortcut: Ctrl + Alt + C
        surface.getView().getDocument().on('keydown', function (e) {
            if (e.ctrlKey && e.altKey && e.key.toLowerCase() === 'c') {
                e.preventDefault();
                surface.execute('customCode');
            }
        });

    });

});
/*That's to change the shitty Code command to Ctrl+alt+c*/