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.
console.log("BharatWiki Common.js loaded");
mw.loader.using('mediawiki.util', function () {
if (mw.config.get('wgNamespaceNumber') !== 0) return;
const metaDesc =
document.querySelector('meta[name="description"]')?.content || "";
const pageUrl = location.href;
let schema = null;
function inject(schemaObj) {
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(schemaObj);
document.head.appendChild(script);
}
/* COMPANY / BRAND */
if (document.querySelector('.infobox.company')) {
const name = document.querySelector('.infobox .fn')?.innerText || mw.config.get('wgTitle');
const logo = document.querySelector('.infobox img')?.src || null;
schema = {
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": {
"@type": "Organization",
"name": name,
"url": pageUrl,
"description": metaDesc,
"address": { "@type": "PostalAddress", "addressCountry": "IN" }
}
};
if (logo) schema.mainEntity.logo = logo;
}
/* PERSON / BIRTHDAY */
else if (document.querySelector('.infobox.person')) {
const name = document.querySelector('.infobox .fn')?.innerText || mw.config.get('wgTitle');
const image = document.querySelector('.infobox img')?.src || null;
schema = {
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": {
"@type": "Person",
"name": name,
"url": pageUrl,
"description": metaDesc
}
};
if (image) schema.mainEntity.image = image;
}
/* MOVIE / FILM */
else if (document.querySelector('.infobox.film')) {
const title = document.querySelector('.infobox .summary')?.innerText || mw.config.get('wgTitle');
const poster = document.querySelector('.infobox img')?.src || null;
schema = {
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": {
"@type": "Movie",
"name": title,
"url": pageUrl,
"description": metaDesc
}
};
if (poster) schema.mainEntity.image = poster;
}
/* PLACE */
else if (document.querySelector('.infobox.place')) {
const name = document.querySelector('.infobox .fn')?.innerText || mw.config.get('wgTitle');
schema = {
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": {
"@type": "Place",
"name": name,
"url": pageUrl,
"description": metaDesc
}
};
}
if (schema) inject(schema);
});