Jump to content

User:Joris Darlington Quarshie/Userscript/Missing Infobox Detector: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Created a userscript detector for Missing Infobox
 
m added documentation template
 
Line 1: Line 1:
'''Note:''' After saving, you have to [[w:Wikipedia:Bypass your cache|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.
'''Note:''' After saving, you have to [[w:Wikipedia:Bypass your cache|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.


{{Documentation
| content = Documentation for this [[Special:MyLanguage/Commons:User scripts|user script]] can be found at [[User:Joris Darlington Quarshie/Userscript/Missing Infobox Detector/Documentation]]
}}


<syntaxhighlight lang="javascript" line>
<syntaxhighlight lang="javascript" line>

Latest revision as of 13:05, 25 December 2023

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);
  }
})();