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 16:36, 30 April 2025 (fix some errors and rewrite all comments). 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.
// NBE or Not Bad Edits was created by Macaw*

// CONFIGURATION
// Enable or disable features by setting these variables to '1' (enabled) or '0' (disabled)
const enableMissingCoordinates = '1'; 
const enableUnreferenced = '1'; 
const enableMissingInfo = '1'; 

// Function to enter edit mode by modifying the URL to include the edit action
function enterEditMode() {
    let url = window.location.href;
    // Check if the current URL does not already end with "&action=edit"
    if (!url.endsWith("&action=edit")) {
        // Update the URL to include the edit action
        window.history.pushState({}, '', url + "&action=edit");
    }
}

// Function to add a template to the edit form with user input and a summary
function addTemplate(template, summary) {
    // Check if the edit form is available
    if (document.editform) {
        // Prompt the user for input regarding the missing information or coordinates
        const userInput = prompt("What is the general location of the missing coordinates?") || prompt("What information is this page missing?");
        // If the user provided input, proceed to add the template
        if (userInput !== null) {
            // Prepend the template and user input to the edit textbox
            document.editform.wpTextbox1.value = `${template}|${userInput}}\n` + document.editform.wpTextbox1.value; 
            // Set the edit summary
            document.editform.wpSummary.value = summary; 
            // Submit the edit form
            document.editform.submit(); 
        }
    }
}

// Check if the feature for missing coordinates is enabled
if (enableMissingCoordinates === '1') {
    // Load the MediaWiki utility module
    mw.loader.using('mediawiki.util', function () {
        // Hook into the content of the wikipage
        mw.hook('wikipage.content').add(function () {
            // Add a link to the action portlet for marking missing coordinates
            const link = mw.util.addPortletLink('p-cactions', '#', 'Missing Coordinates', 'Missing Coordinates', 'Mark as missing coordinates.');
            // Set up a click event for the link
            $(link).click(function (event) {
                event.preventDefault(); // Prevent the default link behavior
                enterEditMode(); // Enter edit mode
                // Call addTemplate with the appropriate template and summary
                addTemplate("{{coord missing", "Added Missing Coordinates Template with [[User:Macaw*/NBE|Not Bad Edits]]");
            });
        });
    });
}

// Check if the feature for missing information is enabled
if (enableMissingInfo === '1') {
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () {
            // Add a link to the action portlet for marking missing information
            const link = mw.util.addPortletLink('p-cactions', '#', 'Missing Information', 'Missing Information', 'Mark as missing information.');
            $(link).click(function (event) {
                event.preventDefault(); // Prevent the default link behavior
                enterEditMode(); // Enter edit mode
                // Call addTemplate with the appropriate template and summary
                addTemplate("{{Missing information", "Added Missing Information Template with [[User:Macaw*/NBE|Not Bad Edits]]");
            });
        });
    });
}

// Check if the feature for unreferenced content is enabled
if (enableUnreferenced === '1') {
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () {
            // Add a link to the action portlet for marking unreferenced content
            const link = mw.util.addPortletLink('p-cactions', '#', 'Unreferenced', 'Unreferenced', 'Mark as unreferenced.');
            $(link).click(function (event) {
                event.preventDefault(); // Prevent the default link behavior
                enterEditMode(); // Enter edit mode
                // Call addTemplate with the appropriate template and summary, including the current date
                addTemplate("{{Unreferenced|date=" + new Date().toLocaleString('en-US', { year: 'numeric', month: 'long' }) + "}", "Added Unreferenced Template with [[User:Macaw*/NBE|Not Bad Edits]]");
            });
        });
    });
}