This is an old revision of this page, as edited by Polygnotus(talk | contribs) at 16:53, 21 June 2025(←Created page with '// Wikipedia User Block Checker for common.js // Checks if users are blocked and categorizes them async function checkUserBlocks() { // Get input from user const input = prompt("Enter usernames (one per line):\nSupported formats:\nUser:Username\nUser talk:Username\nUser:Username\nUser talk:Username"); if (!input) { console.log("No input provided"); return; } const users = parseUsers(input); if (use...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 16:53, 21 June 2025 by Polygnotus(talk | contribs)(←Created page with '// Wikipedia User Block Checker for common.js // Checks if users are blocked and categorizes them async function checkUserBlocks() { // Get input from user const input = prompt("Enter usernames (one per line):\nSupported formats:\nUser:Username\nUser talk:Username\nUser:Username\nUser talk:Username"); if (!input) { console.log("No input provided"); return; } const users = parseUsers(input); if (use...')
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.
// Wikipedia User Block Checker for common.js// Checks if users are blocked and categorizes themasyncfunctioncheckUserBlocks(){// Get input from userconstinput=prompt("Enter usernames (one per line):\nSupported formats:\n[[User:Username]]\n[[User talk:Username]]\nUser:Username\nUser talk:Username");if(!input){console.log("No input provided");return;}constusers=parseUsers(input);if(users.length===0){console.log("No valid usernames found");return;}console.log(`Checking ${users.length} users for blocks...`);constactiveUsers=[];constblockedUsers=[];for(constuserInfoofusers){console.log(`Checking user: ${userInfo.username} ...`);try{constisBlocked=awaitisUserBlocked(userInfo.username);if(isBlocked){blockedUsers.push(userInfo.original);console.log(`✗ ${userInfo.username} is blocked`);}else{activeUsers.push(userInfo.original);console.log(`✓ ${userInfo.username} is active`);}}catch(error){console.error(`Failed to check ${userInfo.username} after all retries:`,error);// Assume active if we can't check after all retriesactiveUsers.push(userInfo.original);console.log(`? ${userInfo.username} - check failed, assuming active`);}// Add base delay between requests to avoid hammering the APIawaitsleep(1000);// 1 second between requests}// Display resultsconsole.log("\n=== RESULTS ===");console.log(`\nActive/Non-blocked users (${activeUsers.length}):`);activeUsers.forEach(user=>console.log(user));console.log(`\nBlocked/Inactive users (${blockedUsers.length}):`);blockedUsers.forEach(user=>console.log(user));// Also display in a more user-friendly formatdisplayResults(activeUsers,blockedUsers);}functionparseUsers(input){constlines=input.split('\n');constusers=[];// Regex patterns for different input formatsconstpatterns=[/\[\[User:([^\]]+)\]\]/i,// [[User:Username]]/\[\[User talk:([^\]]+)\]\]/i,// [[User talk:Username]]/User:([^\s\]]+)/i,// User:Username/User talk:([^\s\]]+)/i// User talk:Username];for(constlineoflines){consttrimmedLine=line.trim();if(!trimmedLine)continue;for(constpatternofpatterns){constmatch=trimmedLine.match(pattern);if(match){users.push({username:match[1].trim(),original:trimmedLine});break;}}}returnusers;}asyncfunctionisUserBlocked(username){constmaxRetries=3;constretryDelays=[60000,180000,300000];// 1min, 3min, 5min in millisecondsfor(letattempt=0;attempt<=maxRetries;attempt++){try{constapi=newmw.Api();constresponse=awaitapi.get({action:'query',format:'json',list:'blocks',bkusers:username,bklimit:1,maxlag:5// Wait if server lag is more than 5 seconds});// If blocks array exists and has entries, user is blockedreturnresponse.query.blocks&&response.query.blocks.length>0;}catch(error){console.warn(`Attempt ${attempt+1} failed for ${username}:`,error);// Check if this is a maxlag errorif(error.code==='maxlag'){constlagTime=error.lag||5;console.log(`Server lag detected (${lagTime}s). Waiting before retry...`);awaitsleep((lagTime+1)*1000);// Wait lag time + 1 secondcontinue;}// Check for HTTP error codes that warrant retryif(isRetryableError(error)){if(attempt<maxRetries){constdelay=retryDelays[attempt];console.log(`Retryable error for ${username}. Waiting ${delay/1000}s before retry ${attempt+2}...`);awaitsleep(delay);continue;}else{console.error(`Max retries exceeded for ${username}. Final error:`,error);thrownewError(`Failed after ${maxRetries+1} attempts: ${error.message}`);}}else{// Non-retryable error, fail immediatelyconsole.error(`Non-retryable error for ${username}:`,error);throwerror;}}}}functionisRetryableError(error){// Check for HTTP status codes that warrant retryif(error.xhr&&error.xhr.status){conststatus=error.xhr.status;// Retry on server errors (5xx) and some client errorsreturnstatus>=500||status===429||status===408||status===502||status===503||status===504;}// Check for specific MediaWiki API error codes that warrant retryif(error.code){constretryableCodes=['maxlag',// Server lag'readonly',// Database in read-only mode'internal_api_error_DBConnectionError','internal_api_error_DBQueryError','ratelimited'// Rate limiting];returnretryableCodes.includes(error.code);}// Check for network-related errorsif(error.textStatus){constretryableStatus=['timeout','error','abort'];returnretryableStatus.includes(error.textStatus);}returnfalse;}functionsleep(ms){returnnewPromise(resolve=>setTimeout(resolve,ms));}functiondisplayResults(activeUsers,blockedUsers){// Create a results dialogconstresultsHtml=` <div style="max-height: 400px; overflow-y: auto;"> <h3>Active/Non-blocked Users (${activeUsers.length})</h3> <textarea readonly style="width: 100%; height: 150px; font-family: monospace;">${activeUsers.join('\n')} </textarea> <h3>Blocked/Inactive Users (${blockedUsers.length})</h3> <textarea readonly style="width: 100%; height: 150px; font-family: monospace;">${blockedUsers.join('\n')} </textarea> </div> `;// Create and show dialogconstdialog=$('<div>').html(resultsHtml).dialog({title:'User Block Check Results',width:600,height:500,modal:true,buttons:{'Close':function(){$(this).dialog('close');}}});}// Add a button to the page for easy accessfunctionaddBlockCheckerButton(){if(mw.config.get('wgNamespaceNumber')===-1)return;// Don't add on special pagesconstportletId=mw.config.get('skin')==='vector'?'p-cactions':'p-tb';mw.util.addPortletLink(portletId,'#','Check User Blocks','t-check-blocks','Check if users are blocked');$('#t-check-blocks').on('click',function(e){e.preventDefault();checkUserBlocks();});}// Initialize when page loads$(document).ready(function(){addBlockCheckerButton();});// Also make the function available globallywindow.checkUserBlocks=checkUserBlocks;