|
Tags: Blanking Manual revert |
| (17 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| 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);
| |
|
| |
| });
| |