User:MonkeysHK/common.js

mw.loader.using(["mediawiki.api", "mediawiki.util", "mediawiki.Uri"]).then(function { // Small script to fix article comments links var handlerAdded = false;	var userGroups = mw.config.get("wgUserGroups");	var canBlock = /sysop|util|staff|helper|global-discussions-moderator|wiki-manager|content-team-member|soap|bureaucrat/.test(userGroups.join("\n"));

function changeCommentLinks { // jshint ignore:line $("span[class^=\"EntityHeader_header-details\"] > div[class^=\"wds-avatar EntityHeader_avatar\"] > a").each(function {			var user = decodeURIComponent($(this).attr('href')).replace( new RegExp(mw.util.getUrl("") + mw.config.get("wgFormattedNamespaces")[2] + ":|" + new mw.Title("Contributions", -1).getUrl + "/"), "" ),				$link = $(this).parent.parent.children("a:last-of-type:not(.mw-user-anon-link)"),				$this = $(this);

// Dont reveal IP's if the user is not an admin/bureaucrat/global groups if (!canBlock && mw.util.isIPAddress(user, true)) return;

$link .attr("href", new mw.Title("Contributions/" + user, -1).getUrl) .html(user);

$this.attr("href", new mw.Title("Contributions/" + user, -1).getUrl);

$link.after(				" (", $("", {					href: new mw.Title("Message_wall/" + user, -1).getUrl,					html: "wall",					title: "Message_wall:" + user,					class: "mw-user-anon-link",				}), canBlock ? " &bull; " : "", canBlock ? $("", {					href: new mw.Title("Block/" + user, -1).getUrl,					html: "block",					title: "Special:Block/" + user,					class: "mw-user-anon-link",				}) : "", ")"			);		});	}

function addCommentId { // jshint ignore:line $("[class^=\"Comment_wrapper\"], [class^=\"Reply_reply\"]").each(function {			switch($(this).find(".comment-id-display, .reply-id-display").length) {				case 0:					var threadID = $(this).attr("data-thread-id") || $(this).attr("data-reply-id");					var isComment = $(this).is("[class^=\"Comment_wrapper\"]");					$(this).append( $(" ", {							text: (isComment? "Comment": "Reply") + " ID : " + threadID,							"class": (isComment? "comment": "reply") + "-id-display",						}) );					break;				case 1:					// do nothing					break;				default:					$(this).find(".comment-id-display, .reply-id-display").each(function (i, elem) { if (i) // not zero (i.e. not first element) elem.remove; });					break;			}		}); }

if ($("#articleComments [class*=\"Comment_wrapper\"]").length) { clearInterval(inter); changeCommentLinks; addCommentId; }

window.CommentObserver = new MutationObserver(mutationsList => {		var operate = false;		for(const mutation of mutationsList) {			console.log($(mutation.target).attr("class") + " " + $(mutation.target).is("[class^=\"CommentList_comment-list\"], [class^=\"ReplyList_container\"], [class^=\"ReplyList_list-wrapper\"]"));			if ($(mutation.target).is("[class^=\"CommentList_comment-list\"], [class^=\"ReplyList_container\"], [class^=\"ReplyList_list-wrapper\"]")) {				operate = true;				break;			}		}		if (operate) {			console.log("INNER run");			if ($("#articleComments [class*=\"Comment_wrapper\"]").length) {				changeCommentLinks;				addCommentId;			}		}	});

// observe everything except attributes window.CommentObserver.observe($("#articleComments").get(0), {		childList: true, // observe direct children		subtree: true, // lower descendants too	});

// event delegation that doesn't work for unknown reason // $("#articleComments").on("click", "[class^=\"ReplyList_view-all-replies\"], [class^=\"LoadMoreButton_load-more\"], [class^=\"ArticleCommentsSingleThread_toolbar-button-back__\"], [class*=\"ViewFilter_view-filter-view-option__\"] *", function	/*	window.CommentHandlersTimeout = false;	$("#articleComments").on("click", function { if (!window.CommentHandlersTimeout) { window.CommentHandlersTimeout = true; var timeoutTimer = setInterval(function {				clearInterval(timeoutTimer);				window.CommentHandlersTimeout = false;			}, 250); var inter1 = setInterval(function {				console.log("INNER run");				if ($("#articleComments [class*=\"Comment_wrapper\"]").length) {					clearInterval(inter1);					changeCommentLinks;					addCommentId;				}			}, 250); }	});	*/ });