MediaWiki:Common.js
Appearance
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.
mw.loader.using('mediawiki.util', function () {
// Wait until page HTML is fully ready
document.addEventListener('DOMContentLoaded', function () {
if (mw.config.get('wgNamespaceNumber') !== 0) return;
const infobox = document.querySelector('table.infobox');
if (!infobox) return;
const metaDesc =
document.querySelector('meta[name="description"]')?.content || "";
const pageUrl = location.href;
const pageTitle = mw.config.get('wgTitle');
let schema = null;
const infoboxText = infobox.innerText.toLowerCase();
// COMPANY
if (infoboxText.includes('industry') || infoboxText.includes('founded')) {
schema = {
"@context": "https://schema.org",
"@type": "Organization",
"name": pageTitle,
"url": pageUrl,
"description": metaDesc
};
const logo = infobox.querySelector('img')?.src;
if (logo) schema.logo = logo;
}
// PERSON
else if (infoboxText.includes('born')) {
schema = {
"@context": "https://schema.org",
"@type": "Person",
"name": pageTitle,
"url": pageUrl,
"description": metaDesc
};
const image = infobox.querySelector('img')?.src;
if (image) schema.image = image;
}
if (!schema) return;
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(schema);
document.head.appendChild(script);
});
});