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 12:52, 2 May 2025 (test again). 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*

const enableMissingCoordinates = '1'; 
const enableUnreferenced = '1'; 
const enableMissingInfo = '1'; 

function addNBETab() {
    var newTab = document.createElement('li');
    newTab.id = 'nbe-tab';
    newTab.innerHTML = '<a href="#" id="nbe-dropdown">NBE</a><ul class="nbe-dropdown-content" style="display:none;"></ul>';

    var toolsTab = document.getElementById('t-tools');
    if (toolsTab) {
        toolsTab.parentNode.insertBefore(newTab, toolsTab.nextSibling);
    }

    if (enableMissingCoordinates === '1') {
        const link = document.createElement('li');
        link.innerHTML = '<a href="#" id="missing-coordinates">Missing Coordinates</a>';
        link.querySelector('a').onclick = function (event) {
            event.preventDefault();
            const userInput = prompt("What is the general location of the missing coordinates?");
            if (userInput !== null) {
                document.editform.wpTextbox1.value = `{{coord missing|${userInput}}}\n` + document.editform.wpTextbox1.value; 
                document.editform.wpSummary.value = "Added Missing Coordinates Template with [[User:Macaw*/NBE|Not Bad Edits]]"; 
                document.editform.submit();
            }
        };
        newTab.querySelector('.nbe-dropdown-content').appendChild(link);
    }

    if (enableMissingInfo === '1') {
        const link = document.createElement('li');
        link.innerHTML = '<a href="#" id="missing-information">Missing Information</a>';
        link.querySelector('a').onclick = function (event) {
            event.preventDefault();
            const userInput = prompt("What information is this page missing?");
            if (userInput !== null) {
                document.editform.wpTextbox1.value = `{{Missing information|${userInput}}}\n` + document.editform.wpTextbox1.value; 
                document.editform.wpSummary.value = "Added Missing Information Template with [[User:Macaw*/NBE|Not Bad Edits]]"; 
                document.editform.submit();
            }
        };
        newTab.querySelector('.nbe-dropdown-content').appendChild(link);
    }

    if (enableUnreferenced === '1') {
        const link = document.createElement('li');
        link.innerHTML = '<a href="#" id="unreferenced">Unreferenced</a>';
        link.querySelector('a').onclick = function (event) {
            event.preventDefault();
            const currentDate = new Date().toLocaleString('en-US', { year: 'numeric', month: 'long' });
            document.editform.wpTextbox1.value = `{{Unreferenced|date=${currentDate}}}\n` + document.editform.wpTextbox1.value; 
            document.editform.wpSummary.value = "Added Unreferenced Template with [[User:Macaw*/NBE|Not Bad Edits]]"; 
            document.editform.submit();
        };
        newTab.querySelector('.nbe-dropdown-content').appendChild(link);
    }

    document.getElementById('nbe-dropdown').onclick = function (event) {
        event.preventDefault();
        var dropdownContent = newTab.querySelector('.nbe-dropdown-content');
        dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
    };

    document.addEventListener('click', function(event) {
        if (!newTab.contains(event.target)) {
            newTab.querySelector('.nbe-dropdown-content').style.display = 'none';
        }
    });
}

addNBETab();