User:Oshwah/History-Log-Links.js

//Forked from User:ST47/cu-log-links.js if (((window.location.href.indexOf("&action=history") > -1) || (window.location.href.indexOf("Special:Log") > -1) || (window.location.href.indexOf("Special%3ALog") > -1) || (window.location.href.indexOf("Special:ListUsers") > -1)) && !(window.location.href.indexOf("Special:RevisionDelete") > -1)) { mw.loader.using('mediawiki.util', function {		$('a.mw-userlink').each(function(i) { var addr = $(this).text; 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; var cidr_pattern = /\/\d{1,3}$/;

var new_user_tool_links = ""; var user_tool_links = $('span.mw-usertoollinks')[i].innerHTML;

var talk_link = user_tool_links.match("^(.*)>talk<\/a><\/span>"); //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><\/span>"); //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]));

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'; var checklog_link = 'checks';

if (ip_pattern.test(addr)) { //The current user 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/'+addr+'">bullseye</a>'; if (!cidr_pattern.test(addr)) { //The IP address does not contain a CIDR range at the end 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; //set the string to be added to the user tool links } else { //The IP address contains a CIDR range at the end new_user_tool_links += contribs_link + " | " + publiclog_link + " | " + whois_link + " | " + geolocate_link + " | " + proxy_check_link + " | " + bullseye_check_link + " | " + checkuser_link + " | " + checklog_link + " " + block_link; //set the string to be added to the user tool links }}			else { //It's not an IP address, so it must be an account $('a.mw-userlink')[i].href = 'https://en.wikipedia.org/wiki/User:'+enc_addr+''; //set the link to the user page new_user_tool_links += talk_link + " " + contribs_link + " | " + publiclog_link + " | " + checkuser_link + " | " + checklog_link + " " + block_link; //set the string to be added to the user tool links }			$('span.mw-usertoollinks')[i].innerHTML = new_user_tool_links; //After all is done, set the HTML for the user tool links to the value set in "append" //window.console.log("[History-Log-Links]: Added links for "+addr+"! Data: \""+new_user_tool_links+"\"\."); //FOR DEBUGGING });	}); }