User:9t5/common.js
Appearance
< User:9t5
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:9t5/common.css. |
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 = '<tr><td>' + username + '</td><td> </td><td> </td></tr>';
var newContent = content.replace('</tbody>', newRow + '</tbody>');
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.');
}
});
}
});