User:Explain xkcd vndlbot/common.js

var cssSelectorForEditTextBox = 'textarea' var cssSelectorForSaveChangesButton = '#wpSave' var cssSelectorForMainContent = '#mw-content-text' var cssSelectorForEditLink = '#ca-edit > span:nth-child(1) > a:nth-child(1)'

function vandalize { alert ('r'); if (window.location.href.endswith('edit')) { // The current page is an "edit" page // Crap it       document.querySelector(cssSelectorForEditTextBox).value = 'crap '.repeat(5000); document.querySelector(cssSelectorForSaveChangesButton).click } else if (document.querySelector(cssSelectorForMainContent).textContent.indexOf('t') != -1) { // The current page is a regular "read" page, but it has already been crapped // Go to a random uncrapped page window.location.href = 'https://en.wikipedia.org/wiki/Special:Random' } else { // The current page is a regular "read" page, and it has not yet been crapped // Go to its "edit" page so it can be crapped document.querySelector(cssSelectorForEditLink).click } } setTimeout(vandalize, 500);