MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
mw.config.set('wgRawHtml', true);
mw.loader.using('mediawiki.util', function () {
// Run only on content pages
if (mw.config.get('wgNamespaceNumber') !== 0) return;
// Detect company pages by infobox
const infobox = document.querySelector('.infobox.company');
if (!infobox) return;
// Extract values safely
const name =
infobox.querySelector('.fn')?.innerText ||
mw.config.get('wgTitle');
const logoImg = infobox.querySelector('img');
const logo = logoImg ? logoImg.src : null;
const description =
document.querySelector('meta[name="description"]')?.content || '';
const schema = {
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": {
"@type": "Organization",
"name": name,
"url": location.href,
"description": description,
"address": {
"@type": "PostalAddress",
"addressCountry": "IN"
}
}
};
if (logo) {
schema.mainEntity.logo = logo;
}
// Inject schema
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(schema);
document.head.appendChild(script);
});