MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 30: | Line 30: | ||
|| !getCookie('userGender')){ | || !getCookie('userGender')){ | ||
userInfo.innerHTML = ` | userInfo.innerHTML = ` | ||
<wiki> | |||
=== <span style='color: green'>'''Enter your information for more accurate risk data:'''</span> === | === <span style='color: green'>'''Enter your information for more accurate risk data:'''</span> === | ||
---- | ---- | ||
<span class="userInfo"><p>''' I am a {{AgeInput}} year old {{GenderSelect}} living in {{CountryInput}} '''</p></span> | <span class="userInfo"><p>''' I am a {{AgeInput}} year old {{GenderSelect}} living in {{CountryInput}} '''</p></span> | ||
---- | ---- | ||
</wiki> | |||
`; | `; | ||
} | } |
Revision as of 22:14, 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]; if ( !getCookie('userAge') || !getCookie('userCountry') || !getCookie('userGender')){ userInfo.innerHTML = ` <wiki> === <span style='color: green'>'''Enter your information for more accurate risk data:'''</span> === ---- <span class="userInfo"><p>''' I am a {{AgeInput}} year old {{GenderSelect}} living in {{CountryInput}} '''</p></span> ---- </wiki> `; }