MediaWiki:Common.js: Difference between revisions
AdminEncyclo (talk | contribs) Created page with "→Any JavaScript here will be loaded for all users on every page load.: mw.loader.using('mediawiki.util').then(function () { // Check if page is in "Verified profiles" category if (mw.config.get('wgCategories').includes('Verified profiles')) { document.body.classList.add('verified-profile'); } });" |
AdminEncyclo (talk | contribs) No edit summary |
||
| 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('mediawiki.util').then(function () { | // mw.loader.using('mediawiki.util').then(function () { | ||
// Check if page is in "Verified profiles" category | // // Check if page is in "Verified profiles" category | ||
// if (mw.config.get('wgCategories').includes('Verified profiles')) { | |||
// document.body.classList.add('verified-profile'); | |||
// } | |||
// }); | |||
mw.loader.using(['mediawiki.util']).then(function () { | |||
// Add verified-profile class if page is in Verified profiles category | |||
if (mw.config.get('wgCategories').includes('Verified profiles')) { | if (mw.config.get('wgCategories').includes('Verified profiles')) { | ||
document.body.classList.add('verified-profile'); | document.body.classList.add('verified-profile'); | ||
} | } | ||
// When DOM is ready, add badge beside page title | |||
$(function () { | |||
if (!document.body.classList.contains('verified-profile')) return; | |||
// DESKTOP (Vector) | |||
var desktopTitle = document.querySelector('.mw-page-title-main'); | |||
if (desktopTitle && !desktopTitle.querySelector('.title-verified-badge')) { | |||
var badge = document.createElement('span'); | |||
badge.className = 'title-verified-badge'; | |||
desktopTitle.appendChild(badge); | |||
} | |||
// MOBILE (MinervaNeue) | |||
var mobileTitle = document.querySelector('.page-heading h1'); | |||
if (mobileTitle && !mobileTitle.querySelector('.title-verified-badge')) { | |||
var badgeMobile = document.createElement('span'); | |||
badgeMobile.className = 'title-verified-badge'; | |||
mobileTitle.appendChild(badgeMobile); | |||
} | |||
}); | |||
}); | }); | ||