Difference between revisions of "User:4D4850/common.js"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(Now detects lack of periods.)
Line 14: Line 14:
 
         // the page is crapped and we are in hist
 
         // the page is crapped and we are in hist
 
         undo();
 
         undo();
     } else if (document.querySelector(cssSelectorForMainContent).textContent.indexOf('.') !== -1 || window.location.href.includes('common.js')) {
+
     } 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
 
         // The current page is a regular "read" page, but it has already been uncrapped or is common.js
 
         // Go to a random page
 
         // Go to a random page

Revision as of 22:20, 4 May 2022

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();