User:Oshwah/CU-Log-Links.js

//Forked from User:ST47/cu-log-links.js if ((window.location.href.indexOf("Special:CheckUserLog")) > -1 || (window.location.href.indexOf("Special%3ACheckUserLog")) > -1) { mw.loader.using('mediawiki.util', function {		$('a.mw-userlink').each(function(i) { var addr = $(this).text; //Place the current user (whether it be a username of an account, an IP address, or IP range) into addr var enc_addr = encodeURIComponent(addr); var ip_pattern = /^((\d{1,3}\.){3}\d{1,3}|([\da-f]{0,4}:){1,7}[\da-f]{0,4})(\/\d{1,3})?$/i; //Regex matching the pattern of an IPv4 or IPv6 address or range var cidr_pattern = /\/\d{1,3}$/; if (i % 2 == 1) { //Only execute on every other item in the list (the users being run in the log are odd numbers, and the even numbers are the CU who ran the user) var user_tool_links = $('span.mw-usertoollinks')[((i - 1) / 2)].innerHTML; //Pull the HTML code of the current user tool links (to be replaced) from the inner HTML. var talk_link = user_tool_links.match("^(.*)>talk<\/a>"); //Grab all text from the start of the HTML string to the end of the talk HTML code. talk_link = ((talk_link == null)?('talk'):(talk_link[0]));//Check if the link to the user talk page was captured from user_tools_link. If the string is null, insert the HTML code ourselves. Otherwise, flatten the array.

var contribs_link = user_tool_links.match("contribs<\/a>"); //Grab all text from the start of the contribs HTML code to the end of the contribs HTML code.				contribs_link = ((contribs_link == null)?('contribs'):(contribs_link[0]));//"contribs" is not in this list if the IP is a CIDR range. We must check for this and insert the HTML code ourselves if we want it to be there. Otherwise, flatten the array (see comment at talk_link var above).

var block_link = user_tool_links.match(" block<\/a><\/span>"); //Grab all text from the start of the block HTML code to the end of the block HTML code.				block_link = ((block_link == null)?('block'):(block_link[0]));//Check if the link to the user talk page was captured from user_tools_link. If the string is null, insert the HTML code ourselves. Otherwise, flatten the array.				//var block_link = 'block'; //This would be the straight-forward way to do this, but I'm capturing instead in case the span style changes in the future.

var publiclog_link = 'logs'; var checkuser_link = 'checkuser'; //Create checkuser and check log links var checklog_link = 'checks';

if (ip_pattern.test(addr)) { //The current user in the checkuser log is an IP address var whois_link = '<a href="https://tools.wmflabs.org/whois-referral/gateway.py?lookup=true&ip='+addr+'">WHOIS</a>'; var geolocate_link = '<a href="https://whatismyipaddress.com/ip/'+addr+'">geolocate</a>'; var proxy_check_link = '<a href="https://ipcheck.toolforge.org/index.php?ip='+addr+'">proxy</a>'; var bullseye_check_link = '<a href="https://bullseye.toolforge.org/ip/'+((ip_pattern.test(addr))?(addr):(enc_addr))+'">bullseye</a>'; if (!cidr_pattern.test(addr)) { //The current user in the checkuser log is an IP address, but without an appended CIDR range new_user_tool_links = talk_link + " | " + contribs_link + " | " + publiclog_link + " | " + whois_link + " | " + geolocate_link + " | " + proxy_check_link + " | " + bullseye_check_link + " | " + checkuser_link + " | " + checklog_link + " | " + block_link + ")"; //Format and set the string that will replace the user tool links inner HTML.					} else { //The current user in the checkuser log is an IP address AND with an appended CIDR range						new_user_tool_links = "(" + contribs_link + " | " + publiclog_link + " | " + whois_link + " | " + geolocate_link + " | " + proxy_check_link + " | " + bullseye_check_link + " | " + checkuser_link + " | " + checklog_link + " | " + block_link + ")"; //Format and set the string that will replace the user tool links inner HTML.					}				} else { //the current user in the checkuser log is an account					new_user_tool_links = talk_link + " | " + contribs_link + " | " + publiclog_link + " | " + checkuser_link + " | " + checklog_link + " | " + block_link + ")"; //Format and set the string that will replace the user tool links inner HTML. }			  $('span.mw-usertoollinks')[((i - 1) / 2)].innerHTML = new_user_tool_links; //write the newly created list of links back to the tool links inner HTML code. //window.console.log("[CU-Log-Links]: Added links for "+addr+"! Data: \""+new_user_tool_links+"\"\."); //FOR DEBUGGING }		});	}); }