User:Oshwah/AFLog-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/AFLog-UserLinks.
mw.loader.using("mediawiki.util", function () {
const action = mw.config.get("wgAction"); // e.g., 'view', 'edit', 'history'
/* gets you the name of the current special page, e.g. 'AbuseLog';
if we're not on a special page, this returns null */
const special_pagename = mw.config.get("wgCanonicalSpecialPageName");
if (special_pagename === "AbuseLog") {
// good to go, now we loop through <li>s that have '.mw-userlink' AND '.mw-usertoollinks' inside them
$("li:has(.mw-userlink):has(.mw-usertoollinks)").each(function () {
// pick the first '.mw-userlink';
const user_tool_links = $(this).find("span.mw-usertoollinks").html();
const relevant_user = $(this).find(".mw-userlink").first().text();
const encoded_username = encodeURIComponent(relevant_user);
// generate all the links we want to append
const usertalk_link = user_tool_links.match("^(.*)>talk</a>");
const contribs_link = user_tool_links.match("<a href=\"/wiki/Special:Contributions(.*)>contribs</a>");
const contribs_link2 = ((contribs_link == null)?(`<a href="https://en.wikipedia.org/wiki/Special:Contributions/${relevant_user}">contribs</a>`):(contribs_link[0]));
const block_link = `<a href="https://en.wikipedia.org/wiki/Special:Block/${relevant_user}">block</a>`;
// encoding IPs is a-okay
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 new_links = [usertalk_link[0]];
new_links.push(
contribs_link2,
publiclog_link
);
if (mw.util.isIPAddress(relevant_user)) {
const whois_link = `<a href="https://tools.wmflabs.org/whois-referral/gateway.py?lookup=true&ip=${encoded_username}">WHOIS</a>`;
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
);
}
new_links.push(checkuser_link, checklog_link, block_link); // these are appended after IP-related links
// turn the array of links into "link1 | link2..."
const new_links_str = new_links.join(" | ") + ")";
$(this).find("span.mw-usertoollinks").html(new_links_str);
});
}});//TESTED WORKING AS OF THIS REVISION.