Jump to content

User:Chlod/Scripts/RCP-CV Quicklink.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// RCP-CV Quicklink
// Recent Changes Patrol - Counter-Vandalism Quicklink
// Author: Chlod
// Version: 1.0.0-REL

// Adds a quick link to the RecentChanges page. Defaults to my configuration.

// DO NOT MODIFY UNLESS YOU KNOW WHAT YOU'RE DOING
const rcpcvqlURLRegex = /https:\/\/[a-z]{2,4}\.wikipedia\.org\/wiki\/Special\:RecentChanges[?A-Za-z0-9=%&_\-]*/gi;

if (rcpcvqlTargetLink === undefined)
	var rcpcvqlTargetLink = "https://wiki.riteme.site/wiki/Special:RecentChanges"
		+ "?damaging=likelybad%3Bverylikelybad&goodfaith=likelybad%3Bverylikelybad&hidebots=1&hidecategorization=1"
		+ "&hideWikibase=1&limit=50&days=7&damaging__likelybad_color=c3&damaging__verylikelybad_color=c3&goodfaith"
		+ "__likelybad_color=c4&goodfaith__verylikelybad_color=c5&lastRevision__hidelastrevision_color=c1&urlversion=2";

$(document).ready(() => {
	if (typeof(rcpcvqlTargetLink) !== "string") {
		$("#p-personal #pt-logout").before(`<li id="pt-rcp_cv_ql"><abbr style="color: red; font-weight: bold; cursor: not-allowed;"`
		+ `title="RCP-CV failed to start because the target link is not a string">RCP-CV</span></li>`);
	} else if (!rcpcvqlURLRegex.test(rcpcvqlTargetLink)) {
		$("#p-personal #pt-logout").before(`<li id="pt-rcp_cv_ql"><abbr style="color: red; font-weight: bold; cursor: not-allowed;"`
		+ `title="RCP-CV failed to start because the target link is not a usable URL or does not lead to Wikipedia's Special:RecentChanges. `
		+ `Please correct the target link by modifying 'rcpcvqlTargetLink' in your user script.">RCP-CV</span></li>`);
	} else {
		$("#p-personal #pt-logout").before(`<li id="pt-rcp_cv_ql"><a href=${rcpcvqlTargetLink}">RCP-CV</a></li>`);
	}
});