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.
mw.loader.using(['mediawiki.api','mediawiki.util']).then(function(){if(mw.config.get('wgPageName')!=='Special:Log/block')return;// extract userconstpageParam=mw.util.getParamValue('page');if(!pageParam||!pageParam.startsWith('User:'))return;constIPV4REGEX=/^(?:1?\d\d?|2[0-2]\d)\b(?:\.(?:1?\d\d?|2[0-4]\d|25[0-5])){3}$/;constIPV6REGEX=/^[\dA-Fa-f]{1,4}(?:\:[\dA-Fa-f]{1,4}){7}$/;constuser=pageParam.replace('User:','');// test userconstisIPv6=IPV6REGEX.test(user);if(!IPV4REGEX.test(user)&&!isIPv6){return;}// add buttonconstlink=mw.util.addPortletLink('p-tb','#',"Find range blocks",'ca-find-range-blocks');link.addEventListener('click',function(event){event.preventDefault();findRangeBlocks();});// find range blocksasyncfunctionfindRangeBlocks(){letnetmasks;if(isIPv6){netmasks=Array.from({length:46},(_,i)=>64-i);}else{netmasks=Array.from({length:16},(_,i)=>31-i);}constapi=newmw.Api();constcontentContainer=document.querySelector('.mw-content-container');if(!contentContainer)return;constoutputDiv=document.createElement('div');outputDiv.style.marginTop='1em';conststatusMessage=document.createElement('p');statusMessage.textContent='Querying logs for relevant IP range blocks.';outputDiv.appendChild(statusMessage);constresultsList=document.createElement('ul');outputDiv.appendChild(resultsList);contentContainer.appendChild(outputDiv);mw.hook('wikipage.content').fire($(outputDiv));letfoundBlocks=false;for(constmaskofnetmasks){constrange=isIPv6?maskedIPv6(user,mask):maskedIPv4(user,mask);constblocks=awaitgetBlockLogs(api,range);if(blocks.length){foundBlocks=true;blocks.forEach(block=>{constli=document.createElement('li');li.innerHTML=`<a href="${block.url}">${block.timestamp}</a> <a href="/wiki/User:${encodeURIComponent(block.user)}">${block.user}</a> blocked <a href="/wiki/Special:Contributions/${encodeURIComponent(range)}">${range}</a> (${block.expiry})`;resultsList.appendChild(li);mw.hook('wikipage.content').fire($(resultsList));});}}statusMessage.textContent=foundBlocks?'Blocks affecting this IP:':'No blocks found.';mw.hook('wikipage.content').fire($(statusMessage));}// query API for blocksasyncfunctiongetBlockLogs(api,range){constresponse=awaitapi.get({action:'query',list:'logevents',letype:'block',letitle:`User:${range}`,format:'json'});returnresponse.query.logevents.map(event=>({timestamp:event.timestamp,user:event.user,expiry:event.params.duration||'indefinite',url:mw.util.getUrl('Special:Log',{logid:event.logid})}));}// convert full IPv6 address to BigIntfunctionipv6ToBigInt(ipv6){constsegments=ipv6.split(':');letbigIntValue=0n;constexpanded=expandIPv6(segments);expanded.forEach(segment=>{bigIntValue=(bigIntValue<<16n)+BigInt(parseInt(segment,16));});returnbigIntValue;}// expand shorthand IPv6 (e.g., '::1' to '0:0:0:0:0:0:0:1')functionexpandIPv6(segments){constexpanded=[];lethasEmpty=false;segments.forEach(segment=>{if(segment===''&&!hasEmpty){expanded.push(...Array(8-segments.filter(s=>s).length).fill('0'));hasEmpty=true;}elseif(segment===''){expanded.push('0');}else{expanded.push(segment);}});returnexpanded.map(seg=>seg.padStart(4,'0'));}// apply mask to BigInt for IPv6functionapplyMask(bigIntValue,prefixLength){constmaskBits=128-prefixLength;constmask=(1n<<BigInt(128-maskBits))-1n;returnbigIntValue&(mask<<BigInt(maskBits));}// convert BigInt back to IPv6 stringfunctionbigIntToIPv6(bigIntValue,prefixLength=128){constsegments=[];for(leti=0;i<8;i++){constsegment=(bigIntValue>>BigInt((7-i)*16))&0xffffn;segments.push(segment.toString(16));}constipv6=segments.join(':').replace(/(^|:)0(:0)+(:|$)/,'::');returnipv6+(prefixLength<128?`/${prefixLength}`:'');}// generate masked IPv6 rangefunctionmaskedIPv6(ipv6,prefixLength){constbigIntValue=ipv6ToBigInt(ipv6);constmaskedBigInt=applyMask(bigIntValue,prefixLength);returnbigIntToIPv6(maskedBigInt,prefixLength);}// generate masked IPv4 rangefunctionmaskedIPv4(ipv4,prefixLength){constsegments=ipv4.split('.').map(Number);constipInt=(segments[0]<<24)|(segments[1]<<16)|(segments[2]<<8)|segments[3];constmask=(1<<(32-prefixLength))-1;constmaskedIpInt=ipInt&~mask;return[(maskedIpInt>>>24)&0xff,(maskedIpInt>>>16)&0xff,(maskedIpInt>>>8)&0xff,maskedIpInt&0xff].join('.')+`/${prefixLength}`;}});