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 14:04, 30 April 2025 (Last edit for now. Makes it so tools can work even if not already in edit mode.). 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* 
// 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

// Function to create a new edit form
function createEditForm(content) {
    const editForm = document.createElement('form');
    editForm.method = 'post';
    editForm.action = mw.util.getUrl('Special:Edit');
    
    const textarea = document.createElement('textarea');
    textarea.name = 'wpTextbox1';
    textarea.value = content;
    editForm.appendChild(textarea);
    
    const summary = document.createElement('input');
    summary.type = 'hidden';
    summary.name = 'wpSummary';
    summary.value = "Added Template with [[User:Macaw*/NBE|Not Bad Edits]]";
    editForm.appendChild(summary);
    
    const submit = document.createElement('input');
    submit.type = 'submit';
    submit.value = 'Save Changes';
    editForm.appendChild(submit);
    
    document.body.appendChild(editForm);
    editForm.submit();
}

// 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
                const location = prompt("What is the general location of the missing coordinates?");
                if (location) {
                    createEditForm("{{coord missing|" + location + "}}\n");
                }
            });
        });
    });
}

// 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
                const missingInfo = prompt("What information is this page missing?");
                if (missingInfo) {
                    createEditForm("{{Missing information|" + missingInfo + "}}\n");
                }
            });
        });
    });
}

// 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
                let date = new Date(); // Get current date
                var MonthYearDate = date.toLocaleString('en-US', { year: 'numeric', month: 'long' }); // Format date
                createEditForm("{{Unreferenced|date=" + MonthYearDate + "}}\n");
            });
        });
    });
}