Content deleted Content added
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...' |
Polygnotus (talk | contribs) No edit summary |
||
Line 1:
// Wikipedia User Block Checker for common.js
// Checks if users are blocked and categorizes them
// Features: maxlag support, HTTP error handling, exponential backoff retry (1min, 3min, 5min)
async function checkUserBlocks() {
//
showInputDialog();
}
function showInputDialog() {
const inputHtml = `
<div>
<p><strong>Enter usernames (one per line):</strong></p>
<p>Supported formats:</p>
<ul style="margin: 10px 0; padding-left: 20px;">
<li>[[User:Username]]</li>
<li>[[User talk:Username]]</li>
<li>User:Username</li>
<li>User talk:Username</li>
</ul>
<textarea id="user-input" style="width: 100%; height: 200px; font-family: monospace;"
placeholder="Paste your usernames here..."></textarea>
<div id="status-area" style="margin-top: 10px; font-family: monospace; background: #f8f9fa; padding: 10px; border: 1px solid #ddd; height: 100px; overflow-y: auto; display: none;">
<div id="status-text"></div>
</div>
</div>
`;
const dialog = $('<div>').html(inputHtml).dialog({
height: 450,
modal: false,
resizable: true,
buttons: {
'Check Users': function() {
const input = $('#user-input').val().trim();
if (!input) {
alert('Please enter some usernames to check.');
return;
}
processUsers(input, dialog);
},
'Clear': function() {
$('#user-input').val('');
$('#status-area').hide();
$('#status-text').empty();
},
'Close': function() {
$(this).dialog('close');
}
}
});
// Focus the textarea
setTimeout(() => $('#user-input').focus(), 100);
}
async function processUsers(input, dialog) {
const users = parseUsers(input);
if (users.length === 0) {
return;
}
// Show status area and start processing
$('#status-area').show();
const statusDiv = $('#status-text');
statusDiv.html(`<div>Checking ${users.length} users for blocks...</div>`);
console.log(`Checking ${users.length} users for blocks...`);
Line 23 ⟶ 75:
const blockedUsers = [];
// Disable the Check Users button during processing
const checkButton = dialog.parent().find('.ui-dialog-buttonset button:contains("Check Users")');
checkButton.prop('disabled', true).text('Checking...');
for (let i = 0; i < users.length; i++) {
const userInfo = users[i];
const progress = `[${i + 1}/${users.length}]`;
statusDiv.append(`<div>${progress} Checking ${userInfo.username}...</div>`);
statusDiv.scrollTop(statusDiv[0].scrollHeight);
console.log(`${progress} Checking user: ${userInfo.username} ...`);
try {
Line 31 ⟶ 93:
if (isBlocked) {
blockedUsers.push(userInfo.original);
statusDiv.append(`<div style="color: #d33;">${progress} ✗ ${userInfo.username} is blocked</div>`);
console.log(`✗ ${userInfo.username} is blocked`);
} else {
activeUsers.push(userInfo.original);
statusDiv.append(`<div style="color: #00af89;">${progress} ✓ ${userInfo.username} is active</div>`);
console.log(`✓ ${userInfo.username} is active`);
}
Line 39 ⟶ 103:
} catch (error) {
console.error(`Failed to check ${userInfo.username} after all retries:`, error);
activeUsers.push(userInfo.original);
statusDiv.append(`<div style="color: #fc3;">${progress} ? ${userInfo.username} - check failed, assuming active</div>`);
console.log(`? ${userInfo.username} - check failed, assuming active`);
}
statusDiv.scrollTop(statusDiv[0].scrollHeight);
// Add base delay between requests to avoid hammering the API
await sleep(1000);
}
}
// Re-enable button and show completion
checkButton.prop('disabled', false).text('Check Users');
statusDiv.append(`<div style="font-weight: bold; margin-top: 10px;">✓ Completed! ${activeUsers.length} active, ${blockedUsers.length} blocked</div>`);
statusDiv.scrollTop(statusDiv[0].scrollHeight);
// Display results
Line 56 ⟶ 129:
blockedUsers.forEach(user => console.log(user));
//
displayResults(activeUsers, blockedUsers);
}
Line 180 ⟶ 253:
<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; margin-bottom: 10px;">
${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 results dialog (non-modal)
title: 'User Block Check Results',
width: 600,
height: 500,
modal:
resizable: true,
buttons: {
'Copy Active Users': function() {
navigator.clipboard.writeText(activeUsers.join('\n')).then(() => {
mw.notify('Active users copied to clipboard!', { type: 'success' });
}).catch(() => {
mw.notify('Failed to copy to clipboard', { type: 'error' });
});
},
'Copy Blocked Users': function() {
navigator.clipboard.writeText(blockedUsers.join('\n')).then(() => {
mw.notify('Blocked users copied to clipboard!', { type: 'success' });
}).catch(() => {
mw.notify('Failed to copy to clipboard', { type: 'error' });
});
},
'Close': function() {
$(this).dialog('close');
|