🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/User:Oshwah/Undelete-UserLinks.js
Jump to content

User:Oshwah/Undelete-UserLinks.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<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>