Jump to content

User:Macaw*/NBE.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Macaw* (talk | contribs) at 13:56, 30 April 2025 (Added Missing Coordinates Template with Not Bad Edits). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
{{coord missing|null}}// NBE or Not Bad Edits was created by Macaw* 
// NBE is not a fork but it uses code from other user scripts because I don’t know how to make Wikipedia bend to my will.

// CONFIGURATION
const enableMissingCoordinates = '1'; // Enable Missing Coordinates Template Injector
const enableUnreferenced = '1'; // Enable Unreferenced Template Injector
const enableMissingInfo = '1'; // Enable Missing Information Template Injector

// Check if the Missing Coordinates feature is enabled
if (enableMissingCoordinates === '1') { 
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () { // Wait for the page to load
            // Add a link to the "Missing Coordinates" functionality
            var link = mw.util.addPortletLink('p-cactions', '#', 'Missing Coordinates', 'Missing Coordinates', 'Mark as missing coordinates.');
            $(link).click(function (event) {
                event.preventDefault(); // Prevent default link action
                AddCoordsNeeded(); // Call function to add missing coordinates template
            });
        });
    });

    // Function to add the missing coordinates template
    function AddCoordsNeeded() {
        if (document.editform) { // Check if the edit form exists
            // Insert the missing coordinates template
            document.editform.wpTextbox1.value = "{{coord missing|" + prompt("Where is the General Location of Missing Coordinates? ") + "}}" + document.editform.wpTextbox1.value; 
            document.editform.wpSummary.value = "Added Missing Coordinates Template with [[User:Macaw*/NBE|Not Bad Edits]]"; // Set edit summary
            document.editform.submit(); // Submit changes
        }
    }
}

// Check if the Missing Information feature is enabled
if (enableMissingInfo === '1') { 
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () { // Wait for the page to load
            // Add a link to the "Missing Information" functionality
            var link = mw.util.addPortletLink('p-cactions', '#', 'Missing Information', 'Missing Information', 'Mark as missing information.');
            $(link).click(function (event) {
                event.preventDefault(); // Prevent default link action
                AddMissingInfo(); // Call function to add missing information template
            });
        });
    });

    // Function to add the missing information template
    function AddMissingInfo() {
        if (document.editform) { // Check if the edit form exists
            const missingInfo = prompt("What Information is this Page Missing?"); // Prompt for missing info
            // Insert the missing information template
            document.editform.wpTextbox1.value = "{{Missing information|" + missingInfo + "}}" + document.editform.wpTextbox1.value; 
            document.editform.wpSummary.value = "Added Missing Information Template with [[User:Macaw*/NBE|Not Bad Edits]]"; // Set edit summary
            document.editform.submit(); // Submit changes
        }
    }
}

// Check if the Unreferenced feature is enabled
if (enableUnreferenced === '1') { 
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () { // Wait for the page to load
            // Add a link to the "Unreferenced" functionality
            var link = mw.util.addPortletLink('p-cactions', '#', 'Unreferenced', 'Unreferenced', 'Mark as unreferenced.');
            $(link).click(function (event) {
                event.preventDefault(); // Prevent default link action
                AddUnref(); // Call function to add unreferenced template
            });
        });
    });

    // Function to tag articles as unreferenced
    function AddUnref() { 
        let date = new Date(); // Get current date
        var MonthYearDate = date.toLocaleString('en-US', { year: 'numeric', month: 'long' }); // Format date

        if (document.editform) { // Check if the edit form exists
            // Insert the unreferenced template
            document.editform.wpTextbox1.value = "{{Unreferenced|date=" + MonthYearDate + "}}" + document.editform.wpTextbox1.value; 
            document.editform.wpSummary.value = "Added Unreferenced Template with [[User:Macaw*/NBE|Not Bad Edits]]"; // Set edit summary
            document.editform.submit(); // Submit changes
        }
    }
}