MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
mw.loader.using('mediawiki.util', function () { | |||
window.addEventListener('load', function () { | window.addEventListener('load', function () { | ||
if (mw.config.get('wgNamespaceNumber') !== 0) return; | |||
// Prevent duplicates | |||
if (document.getElementById('bw-entity-schema')) return; | |||
const infobox = document.querySelector('table.infobox'); | |||
if (!infobox) return; | |||
const metaDesc = | |||
document.querySelector('meta[name="description"]')?.content || ""; | |||
const pageTitle = mw.config.get('wgTitle'); | |||
const pageUrl = location.href; | |||
const text = infobox.innerText.toLowerCase(); | |||
let schema = null; | |||
/* ---------- COMPANY ---------- */ | |||
if (text.includes('industry') || text.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 (text.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.id = 'bw-entity-schema'; | |||
script.text = JSON.stringify(schema); | |||
document.body.appendChild(script); | |||
}); | }); | ||
}); | }); | ||
Revision as of 19:30, 17 December 2025
mw.loader.using('mediawiki.util', function () {
window.addEventListener('load', function () {
if (mw.config.get('wgNamespaceNumber') !== 0) return;
// Prevent duplicates
if (document.getElementById('bw-entity-schema')) return;
const infobox = document.querySelector('table.infobox');
if (!infobox) return;
const metaDesc =
document.querySelector('meta[name="description"]')?.content || "";
const pageTitle = mw.config.get('wgTitle');
const pageUrl = location.href;
const text = infobox.innerText.toLowerCase();
let schema = null;
/* ---------- COMPANY ---------- */
if (text.includes('industry') || text.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 (text.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.id = 'bw-entity-schema';
script.text = JSON.stringify(schema);
document.body.appendChild(script);
});
});