MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
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.config.set('wgRawHtml', true); | 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); | |||
}); | |||
Revision as of 19:00, 17 December 2025
/* 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);
});