Jump to content

User:Joris Darlington Quarshie/Userscript/Missing Infobox Detector

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.

// ==UserScript==
// @name         Missing Infobox Detector
// @namespace    https://tampermonkey.net/
// @version      1.0
// @description  Identifies Wikipedia articles lacking infoboxes and suggests information to fill them.
// @author       Joris Darlington Quarshie
// @match        https://en.wikipedia.org/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  const infoboxContainer = document.getElementById('infobox');

  // Check if the article has an infobox.
  if (!infoboxContainer) {
    // Extract article title and topic.
    const titleElement = document.querySelector('#firstHeading');
    const title = titleElement.textContent.trim();
    const topic = title.split(' – ')[0];

    // Generate notification message.
    const message = `This article is missing an infobox. You can find relevant information to fill it on the [Wikipedia infobox page for ${topic}](https://en.wikipedia.org/wiki/Template:${topic.replace(/\s/g, '_')}_infobox)`;

    // Display notification.
    const notification = document.createElement('div');
    notification.classList.add('missing-infobox-notification');
    notification.innerHTML = `<strong>Missing Infobox!</strong> ${message}`;
    document.body.appendChild(notification);
  }
})();