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.
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>// @ts-check// Extended info on IPs - gives a popup with their range, ASN, and ISP// Parts cribbed from [[User:Krinkle/Scripts/CVNSimpleOverlay_wiki.js]] and [[MediaWiki:Gadget-markblocked.js]]/* global mw, $ */constipExtIcon='https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Gnome-fs-web.svg/20px-Gnome-fs-web.svg.png'/** * Get all userlinks on the page * * @param {JQuery} $content page contents * @return {Map} list of unique users on the page and their corresponding links */functionipExtGetIPs($content){constuserLinks=newMap()// Get all aliases for user: (taken from markblocked)constuserNS=[]for(constnsinmw.config.get('wgNamespaceIds')){if(mw.config.get('wgNamespaceIds')[ns]===2){userNS.push(mw.util.escapeRegExp(ns.replace(/_/g,' '))+':')}}// RegExp for all titles that are User:constuserTitleRX=newRegExp('^('+userNS.join('|')+'Special:Block/|Special:Contribs/|Special:Contributions/)+([^\\/#]+)$','i')constarticleRX=newRegExp(mw.config.get('wgArticlePath').replace('$1','')+'([^#]+)')$('a',$content).each(function(){if(!$(this).attr('href')){// Ignore if the <a> doesn't have a hrefreturn}constarticleTitleReMatch=articleRX.exec($(this).attr('href').toString())if(!articleTitleReMatch){return}letpgTitletry{pgTitle=decodeURIComponent(articleTitleReMatch[1]).replace(/_/g,' ')}catch(error){return}constuserTitleReMatch=userTitleRX.exec(pgTitle)if(!userTitleReMatch){return}constusername=userTitleReMatch[2]if(mw.util.isIPAddress(username,true)){if(!userLinks.get(username)){userLinks.set(username,[])}userLinks.get(username).push($(this))}})returnuserLinks}/** * Get the WHOIS summary for an IP * * @param {string} ip IP address to check * * @return {Promise<string>} Summary of interesting parts of the IP's WHOIS */asyncfunctionipExtWHOISInline(ip){constwhoisResult=awaitfetch(`https://whois.toolforge.org/w/${ip}/lookup/json`)constwhoisJson=awaitwhoisResult.json()// Why is json() async?letproviders=''whoisJson.nets.forEach((net)=>{providers+=net.name+' '})return`${ip}:\n ASN: ${whoisJson.asn}\n ASN range: ${whoisJson.asn_cidr}\n ASN country: ${whoisJson.asn_country_code}\n ISP: ${providers}`}asyncfunctionannotate(ipsOnPage){// Swiped from [[User:Suffusion_of_Yellow/batchtest-plus.js]]constpending=[]constMAX_CONCURRENT_REQUESTS=5for(const[ip,val]ofipsOnPage){constidx=pending.length<MAX_CONCURRENT_REQUESTS?pending.length:awaitPromise.race(pending)if(idx===undefined){break// Something went wrong with the last request}pending[idx]=ipExtWHOISInline(ip).then((whoisText)=>{val.forEach(($link)=>{$link.after($('<a>').attr('href',`https://bullseye.toolforge.org/ip/${ip}`).attr('target','blank').attr('rel','noopener noreferrer').append($('<img>').attr('src',ipExtIcon).attr('title',mw.html.escape(whoisText))))})returnidx})}awaitPromise.all(pending)}// On window load, get all the IPs on the page and WHOIS them asynchronously$.when($.ready,mw.loader.using(['mediawiki.util'])).then(function(){mw.hook('wikipage.content').add(function($content){constipsOnPage=ipExtGetIPs($content)annotate(ipsOnPage)})})