Jump to content

MediaWiki:Common.js: Difference between revisions

From RiskiPedia
No edit summary
No edit summary
Line 33: Line 33:
     api.post( {
     api.post( {
         action: 'parse',
         action: 'parse',
         text: "''This is italic'' and '''this is bold'''.",
         text: "{{{UserInfo}}}",
         contentmodel: 'wikitext',  // Specify that input is wikitext
         contentmodel: 'wikitext',  // Specify that input is wikitext
         format: 'json'
         format: 'json'
Line 44: Line 44:
if ( !getCookie('userAge') || !getCookie('userCountry')  
if ( !getCookie('userAge') || !getCookie('userCountry')  
|| !getCookie('userGender')){
|| !getCookie('userGender')){
userInfo.innerHTML = `
console.log('hi');
<div class="mw-parser-output">
    ''This is italic text in wikitext''
</div>
 
`
}
}

Revision as of 22:31, 3 February 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();
        }
    }
}

function getCookie(cookieName) {
    const cookies = document.cookie.split('; ');
    for (const cookie of cookies) {
        const [name, value] = cookie.split('=');
        if (name === cookieName) {
            return decodeURIComponent(value);
        }
    }
    return null;
}

let userInfo = document.getElementsByClassName("userInfo")[0];


mw.loader.using( 'mediawiki.api' ).then( function () {
    var api = new mw.Api();
    
    api.post( {
        action: 'parse',
        text: "{{{UserInfo}}}",
        contentmodel: 'wikitext',  // Specify that input is wikitext
        format: 'json'
    	} ).done( function ( data ) {
        	var parsedHtml = data.parse.text['*']; // Extract converted HTML
        	userInfo.innerHTML = parsedHtml ; // Inject into the page    } );
	} );
} );

if ( !getCookie('userAge') || !getCookie('userCountry') 
	|| !getCookie('userGender')){
		console.log('hi');
	}