User:9t5/common.js

document.addEventListener('DOMContentLoaded', function {   var inputBox = document.querySelector('#mw-inputbox-form input[type="text"]');    var submitButton = document.querySelector('#mw-inputbox-form input[type="submit"]');

if (inputBox && submitButton) { submitButton.addEventListener('click', function(event) {           event.preventDefault; // Prevent the default form submission

var username = inputBox.value.trim; if (username) { var pageTitle = 'User:9t5/contestants'; var api = new mw.Api;

api.get({                   action: 'query',                    prop: 'revisions',                    rvprop: 'content',                    titles: pageTitle,                    formatversion: 2                }).done(function(data) {                    var content = data.query.pages[0].revisions[0].content;

// Find the position to insert the new row var newRow = ' ' + username + '      '; var newContent = content.replace(' ', newRow + ' ');

api.postWithEditToken({                       action: 'edit',                        title: pageTitle,                        text: newContent,                        summary: 'Adding contestant to the chart'                    }).done(function {                        alert('Username added successfully!');                        location.reload; // Reload the page to reflect the change                    }).fail(function(error) {                        console.error(error);                        alert('An error occurred while adding the username.');                    }); }).fail(function(error) { console.error(error); alert('An error occurred while retrieving the page content.'); });           } else {                alert('Please enter a valid username.');            }        }); } });