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:41, 30 April 2025 (Optimizing code is fun (I don't like it) also removed the addTemplate function because It will be too annoying to upgrade). 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 features by setting to '1' or '0'
const enableMissingCoordinates = '1'; 
const enableUnreferenced = '1'; 
const enableMissingInfo = '1'; 

// Function to enter edit mode by modifying the URL
function enterEditMode() {
    let url = window.location.href;
    if (!url.endsWith("&action=edit")) {
        window.history.pushState({}, '', url + "&action=edit");
    }
}

// Function to add a template based on user input
function addTemplate(template, summary) {
    if (document.editform) {
        const userInput = prompt("What is the general location of the missing coordinates?") || prompt("What information is this page missing?");
        if (userInput !== null) {
            document.editform.wpTextbox1.value = `${template}|${userInput}}\n` + document.editform.wpTextbox1.value; 
            document.editform.wpSummary.value = summary; 
            document.editform.submit(); 
        }
    }
}

// Add links for missing coordinates, information, and unreferenced content if enabled
if (enableMissingCoordinates === '1') {
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () {
            const link = mw.util.addPortletLink('p-cactions', '#', 'Missing Coordinates', 'Missing Coordinates', 'Mark as missing coordinates.');
            $(link).click(function (event) {
                event.preventDefault();
                enterEditMode();
                addTemplate("{{coord missing", "Added Missing Coordinates Template with [[User:Macaw*/NBE|Not Bad Edits]]");
            });
        });
    });
}

if (enableMissingInfo === '1') {
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () {
            const link = mw.util.addPortletLink('p-cactions', '#', 'Missing Information', 'Missing Information', 'Mark as missing information.');
            $(link).click(function (event) {
                event.preventDefault();
                enterEditMode();
                addTemplate("{{Missing information", "Added Missing Information Template with [[User:Macaw*/NBE|Not Bad Edits]]");
            });
        });
    });
}

if (enableUnreferenced === '1') {
    mw.loader.using('mediawiki.util', function () {
        mw.hook('wikipage.content').add(function () {
            const link = mw.util.addPortletLink('p-cactions', '#', 'Unreferenced', 'Unreferenced', 'Mark as unreferenced.');
            $(link).click(function (event) {
                event.preventDefault();
                enterEditMode();
                addTemplate("{{Unreferenced|date=" + new Date().toLocaleString('en-US', { year: 'numeric', month: 'long' }) + "}", "Added Unreferenced Template with [[User:Macaw*/NBE|Not Bad Edits]]");
            });
        });
    });
}