User:OrangeStar/masspatrol.js

/* SPDX-License-Identifier: BSD-2-Clause

Copyright 2022 OrangeStar 

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* A script for quickly patrolling a group of changes using the API.

Sometimes, for example, when translating articles, an user may edit the same page multiple times. If you're sure that the user is not a vandal, you can quickly mark all those changes as patrolled, without having to review each individual diff. The script was developed by "reverse-engineering" Special:RecentChanges using the Firefox element inspector, and reading https://www.mediawiki.org/wiki/API:Patrol Note: If you find yourself using this on a editor that is obviously good-faith, consider giving them autopatrolled, or requesting that an admin give them the group.

You need the (writeapi) and (patrol) rights to use this script, as well as use the "enhanced" recent changes, available on your preferences and activated by default if you have JavaScript enabled in your browser.

const apientrypoint = mw.config.get("wgServer") + mw.config.get("wgScriptPath") + "/api.php";

//First, we need to check if we are in Special:RecentChanges

if (mw.config.get("wgPageName") === "Special:RecentChanges") { let unpatrolledlist = document.getElementsByClassName("unpatrolled"); //On recent changes, the unpatrolled class is added to pages that contain unpatrolled edits. It's also added to an element in the legend, which we'll skip for (i = 0; i < unpatrolledlist.lenght; i++) { //Now we're gonna loop over the list, and check if the parent element indicates the page has multiple edits if (i !== 0) { //Skip the element in the legend /*				First parent is an element containing the date and the unpatrolled element. Second parent is a element containing the entry, which is what we're looking for. On that element, we're looking for a element on it's second child that contains a element on its first child with the class "mw-enhancedchanges-arrow". Simple */			let item = unpatrolledlist[i]; let rcentry = item.parentElement.parentElement; if (rcentry.children[1].children[0].classList.includes("mw-enhancedchanges-arrow")) { //Bingo //TODO: Go through the elements in the edit, retrieve the revisions' ID (oldid GET parameter in the links), then add a callback on the button to a function that will use the API to mark them as patrolled rcentry.innerHTML += " [ masspatrol ] "; //TODO: proper styling }		}//if index !== 0 }//unpatrolledlist loop } //if Special:RecentChanges