User:MonkeysHK/common.js

// Small script to fix article comments links var handlerAdded = false; var inter = setInterval(function {	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 $(".Comment_wrapper__2mxBn, .Reply_reply__3O89M").each(function {			if (!$(this).find(".comment-id-display, .reply-id-display").length) {				var threadID = $(this).attr("data-thread-id") || $(this).attr("data-reply-id");				var isComment = $(this).hasClass("Comment_wrapper__2mxBn");				$(this).append( $(" ", {						text: (isComment? "Comment": "Reply") + " ID : " + threadID,						"class": (isComment? "comment": "reply") + "-id-display",					}) );			}		});	}

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

if (!handlerAdded) { handlerAdded = true; $("[class^=\"ReplyList_view-all-replies\"], [class^=\"LoadMoreButton_load-more\"], [class^=\"ArticleCommentsSingleThread_toolbar-button-back__\"], [class*=\"ViewFilter_view-filter-view-option__\"] *").on("click", function {			var inter1 = setInterval(function { console.log("INNER run"); if ($("#articleComments [class*=\"Comment_wrapper\"]").length) { clearInterval(inter1); changeCommentLinks; addCommentId; }			}, 10);		});	} }, 25);