User:Oshwah/Undelete-Log-Links.js

if (((window.location.href.indexOf("Special:Undelete") > -1) || (window.location.href.indexOf("Special%3AUndelete") > -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>'; 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 { //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 if (!user_tool_links.includes("(")) { //If the left parenthesis already exists in the string, we don't need to add the or first and last | characters					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				}				else {					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("[Undelete-Log-Links]: Added links for "+addr+"! Data: \""+new_user_tool_links+"\"\."+" Output: \""+user_tool_links.includes("(")+"\"\."); //FOR DEBUGGING		}); }); }