User:4D4850/common.js

Explain xkcd: It's 'cause you're dumb.
Revision as of 21:32, 4 May 2022 by 4D4850 (talk | contribs) (Now detects lack of periods.)
Jump to: navigation, search
var cssSelectorForEditTextBox = 'textarea'
var cssSelectorForSaveChangesButton = '#wpSave'
var cssSelectorForMainContent = '#mw-content-text'
var cssSelectorForEditLink = '#ca-edit > span:nth-child(1) > a:nth-child(1)'
var cssSelectorForHistLink = '#ca-history > span:nth-child(1) > a:nth-child(1)'
var links = document.links

function unvandalize() {
    if (window.location.href.includes('edit')) {
        // The current page is an "edit" page
        // uncrap it
        document.querySelector(cssSelectorForSaveChangesButton).click()
    } else if (window.location.href.includes('history')) {
        // the page is crapped and we are in hist
        undo();
    } else if (document.querySelector(cssSelectorForMainContent).textContent.indexOf('.') !== -1 || window.location.href.includes('common.js')) {
        // The current page is a regular "read" page, but it has already been uncrapped or is common.js
        // Go to a random page
        window.location.href = 'https://www.explainxkcd.com/wiki/index.php/Special:Random'
    } else {
        // The current page is a regular "read" page, and it has been crapped
        // Go to its "hist" page so it can be uncrapped
        document.querySelector(cssSelectorForHistLink).click()
    }
}

function undo() {
    toUndo = links[14]
    toUndo.click()

}
unvandalize();