User:Oshwah/Undelete-UserLinks.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:Oshwah/Undelete-UserLinks.
//<nowiki>
mw.loader.using("mediawiki.util", function () {
const special_pagename = mw.config.get("wgCanonicalSpecialPageName"); //Get name of the current special page, e.g. 'AbuseLog'; if we're not on a special page, this returns null.
if (special_pagename === "Undelete") { //Only proceed if this is a special page and if the current special page is Special:Log.
$("li:has(.mw-userlink):has(.mw-usertoollinks)").each(function () { //Loop through <li>s that have '.mw-userlink' AND '.mw-usertoollinks' inside them.
const user_tool_links = $(this).find(".mw-usertoollinks").first().html(); //Grab the HTML of the user tool links for the current user.
const relevant_user = $(this).find(".mw-userlink").first().text(); //Grab the username of the relevant user.
const encoded_username = encodeURIComponent(relevant_user);
const usertalk_temp = user_tool_links.match('^(.*)>talk</a>'); //This also captures the opening <span> tag for the entire list of user links.
const usertalk_link = usertalk_temp[0];
const contribs_temp = user_tool_links.match('<a href="/wiki/Special:Contributions(.*)>contribs</a>');
const contribs_link = ((contribs_temp == null)?('<a href="https://en.wikipedia.org/wiki/Special:Contributions/' + relevant_user + '">contribs</a>'):(contribs_temp[0]));
//Create all the links we want to append.
const publiclog_link = '<a href="https://en.wikipedia.org/wiki/Special:Log?user=' + encoded_username + '">logs</a>';
const checkuser_link = '<a href="https://en.wikipedia.org/w/index.php?title=Special:CheckUser&user=' + encoded_username + '">checkuser</a>';
const checklog_link = '<a href="https://en.wikipedia.org/w/index.php?title=Special:CheckUserLog&cuSearchType=target&cuSearch=' + encoded_username + '">checks</a>';
const block_link = '<a href="https://en.wikipedia.org/wiki/Special:Block/' + relevant_user + '">block</a>';
let new_links = [usertalk_link]; //Create array of new tool links, set first element to user talk page link.
new_links.push(contribs_link, publiclog_link); //Add contribs and public log links to the array.
if (mw.util.isIPAddress(relevant_user)) { //If the username is an IP address, we have IP tool links to add as well.
const whois_link = '<a href="https://tools.wmflabs.org/whois-referral/gateway.py?lookup=true&ip=' + encoded_username + '">WHOIS</a>'; //Create IP tool links
const geolocate_link = '<a href="https://whatismyipaddress.com/ip/' + relevant_user + '">geolocate</a>';
const proxy_check_link = '<a href="https://spur.us/context/' + relevant_user + '">proxy</a>';
const bullseye_check_link = '<a href="https://bullseye.toolforge.org/ip/' + relevant_user + '">bullseye</a>';
new_links.push(whois_link, geolocate_link, proxy_check_link, bullseye_check_link); //Add them to the array.
}
new_links.push(checkuser_link, checklog_link, block_link); //Add ending user links to the array.
const new_links_str = new_links.join(' | ') + (user_tool_links.match('</span>')?'</span>':')'); //Join each string element together, separated by ' | ', add a closing </span> tag to the end, and place into to a singular string.
$(this).find(".mw-usertoollinks").first().html(new_links_str); //Write the new HTML string back to the user '.mw-usertoollinks' span object and replace the old HTML.
});
}
});
//</nowiki>