Jump to content

MediaWiki:Common.js: Difference between revisions

From RiskiPedia
No edit summary
No edit summary
Line 14: Line 14:
}
}


$(document).ready(function() {
    // Check if we are on the main page (e.g., 'Main_Page')
    if (mw.config.get('wgPageName') === 'Main_Page') {


        // Ensure that OOUI is loaded
mw.loader.using('oojs-ui', function () {
        mw.loader.using('oojs-ui', function () {
    // Now OOUI is loaded and we can use it
            // Now OOUI is loaded and we can use it


            // Create an OOUI button
    // Create an OOUI button
            var button = new OO.ui.ButtonWidget({
    var button = new OO.ui.ButtonWidget({
                label: 'Click Me!',  // Text for the button
        label: 'Click Me!',  // Text for the button
                classes: ['oo-ui-primaryButton']  // Optional: apply OOUI primary button style
        classes: ['oo-ui-primaryButton']  // Optional: apply OOUI primary button style
            });
    });


            // Event listener for the button click
    // Event listener for the button click
            button.on('click', function() {
    button.on('click', function() {
                alert('Hello! This is the home page button!');
        alert('Hello! This is the home page button!');
            });
    });


            // Append the button to the content area of the page
    // Append the button to the content area of the page
            $('#content').append(button.$element);
    $('#content').append(button.$element);
        });
    }
});
});

Revision as of 00:21, 31 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */

MMtoHuman(document.getElementsByClassName("micromorts"));

function MMtoHuman ( elementArray ){
    for (let span of elementArray){
        if (span !== null){
            let chance = 1000000 / parseInt(span.textContent);
            let digits = Math.round(chance).toString().length;
            let rounded = Math.round(chance / Math.pow(10, digits - 2)) * Math.pow(10, digits - 2);
            span.textContent = "1 in " + rounded.toLocaleString();
        }
    }
}


mw.loader.using('oojs-ui', function () {
    // Now OOUI is loaded and we can use it

    // Create an OOUI button
    var button = new OO.ui.ButtonWidget({
        label: 'Click Me!',  // Text for the button
        classes: ['oo-ui-primaryButton']  // Optional: apply OOUI primary button style
    });

    // Event listener for the button click
    button.on('click', function() {
        alert('Hello! This is the home page button!');
    });

    // Append the button to the content area of the page
    $('#content').append(button.$element);
});