User:Euphoria/massBlock.js: Difference between revisions
Jump to navigation
Jump to search
(Custom block duration and popup interface.) |
No edit summary |
||
Line 1: | Line 1: | ||
if (mw.config.get('wgUserGroups').includes('sysop')) { | if (mw.config.get('wgUserGroups').includes('sysop')) { | ||
function createBlockingInterface() { | function createBlockingInterface() { | ||
var formHtml = '<div id="massBlockForm" style="background: white; border: 1px solid black; padding: 10px;">' | var formHtml = '<div id="massBlockForm" style="background: white; border: 1px solid black; padding: 10px;">' | ||
+ '<h3>Mass Block</h3>' | + '<h3>Mass Block</h3>' | ||
+ 'Usernames (comma-separated):<br><textarea id="usernamesToBlock" rows="2" cols="20"></textarea><br>' | + 'Usernames (comma-separated):<br><textarea id="usernamesToBlock" rows="2" cols="20"></textarea><br>' | ||
+ 'Block reason:<br><input type="text" id="blockReason"><br>' | + 'Block reason:<br><input type="text" id="blockReason"><br>' | ||
+ 'Block duration:<br> | + 'Block duration:<br><select id="blockDuration">' | ||
+ '<option value="6 hours">6 hours</option>' | + '<option value="6 hours">6 hours</option>' | ||
+ '<option value="24 hours">24 hours</option>' | + '<option value="24 hours">24 hours</option>' | ||
Line 23: | Line 17: | ||
+ '<option value="5 years">5 years</option>' | + '<option value="5 years">5 years</option>' | ||
+ '<option value="indefinite">indefinite</option>' | + '<option value="indefinite">indefinite</option>' | ||
+ '</select><br>' | + '</select><br>' | ||
+ '<button id="executeMassBlock">Block Users</button>' | + '<button id="executeMassBlock">Block Users</button>' | ||
+ '</div>'; | + '</div>'; | ||
// Append the form to a specific part of the Wikipedia interface | |||
$('#someWikipediaContainer').append(formHtml); | |||
$('#executeMassBlock').click(function() { | |||
var users = | var users = $('#usernamesToBlock').val().split(','); | ||
var reason = | var reason = $('#blockReason').val(); | ||
var duration = | var duration = $('#blockDuration').val(); | ||
users.forEach(function(user) { | users.forEach(function(user) { | ||
blockUser(user.trim(), reason, duration); | blockUser(user.trim(), reason, duration); | ||
}); | }); | ||
} | }); | ||
} | } | ||
function blockUser(username, reason, duration) { | function blockUser(username, reason, duration) { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
Line 70: | Line 51: | ||
} | } | ||
$(document).ready(function() { | $(document).ready(function() { | ||
createBlockingInterface(); | |||
}); | }); | ||
} | } |
Revision as of 11:47, 28 December 2023
if (mw.config.get('wgUserGroups').includes('sysop')) {
function createBlockingInterface() {
var formHtml = '<div id="massBlockForm" style="background: white; border: 1px solid black; padding: 10px;">'
+ '<h3>Mass Block</h3>'
+ 'Usernames (comma-separated):<br><textarea id="usernamesToBlock" rows="2" cols="20"></textarea><br>'
+ 'Block reason:<br><input type="text" id="blockReason"><br>'
+ 'Block duration:<br><select id="blockDuration">'
+ '<option value="6 hours">6 hours</option>'
+ '<option value="24 hours">24 hours</option>'
+ '<option value="31 hours">31 hours</option>'
+ '<option value="1 week">1 week</option>'
+ '<option value="2 weeks">2 weeks</option>'
+ '<option value="1 month">1 month</option>'
+ '<option value="3 months">3 months</option>'
+ '<option value="6 months">6 months</option>'
+ '<option value="1 year">1 year</option>'
+ '<option value="5 years">5 years</option>'
+ '<option value="indefinite">indefinite</option>'
+ '</select><br>'
+ '<button id="executeMassBlock">Block Users</button>'
+ '</div>';
// Append the form to a specific part of the Wikipedia interface
$('#someWikipediaContainer').append(formHtml);
$('#executeMassBlock').click(function() {
var users = $('#usernamesToBlock').val().split(',');
var reason = $('#blockReason').val();
var duration = $('#blockDuration').val();
users.forEach(function(user) {
blockUser(user.trim(), reason, duration);
});
});
}
function blockUser(username, reason, duration) {
var api = new mw.Api();
api.postWithToken('csrf', {
action: 'block',
user: username,
expiry: duration,
reason: reason,
nocreate: true,
autoblock: true,
noemail: true
}).done(function(data) {
console.log('User blocked: ' + username);
}).fail(function(error) {
console.log('Error blocking user: ' + username);
});
}
$(document).ready(function() {
createBlockingInterface();
});
}