MediaWiki:Common.js: Difference between revisions

From Trickster Development Wiki
mNo edit summary
mNo edit summary
 
(3 intermediate revisions 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. */
$(document).keydown(function (e) {
mw.loader.using([
     // Ctrl+Shift+C
     'ext.visualEditor.core',
     if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'd') {
     'ext.visualEditor.desktopArticleTarget.init'
        // Prevent default browser behavior if any
], function () {
        e.preventDefault();


        // Trigger "Computer code" button
    // Wait until VE is actually ready
        $('#wpTextbox1').textSelection(
    mw.hook('ve.activationComplete').add(function () {
             'encapsulateSelection',
 
            { pre: '<code>', post: '</code>' }
        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+Shift+D*/
/*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*/