Difference between revisions of "User:Vandalbane/common.js"
Vandalbane (talk | contribs) (Undo revision 278462 by Vandalbane (talk)) |
Vandalbane (talk | contribs) |
||
Line 1: | Line 1: | ||
− | mw. | + | 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) { | ||
+ | // 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(); |
Revision as of 19:57, 26 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) { // 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();