User:Vanished user 1929210/js/sandbox/jessechi.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
'use strict';
$('#mw-content-text').prepend(`
<input type="text" id="continue">
<p><a href="javascript:;" id="sandbox_fetch">FETCH</a></p>
<textarea id="sandbox" style="width:500px; height: 300px;"></textarea>
<p><a href="javascript:;" id="sandbox_ok">CHECK</a></p>
<textarea id="sandbox2" style="width:500px; height: 300px;"></textarea>`);
const query = (site, list, callback) => {
let result = [];
let promises = [];
const mark = (q) => {
if (q.query.users) {
for (let u of q.query.users) {
let e = { name: u.name, editcount: u.editcount };
if (u.blockreason) {
e.blockreason = u.blockreason;
e.blockedtimestamp = u.blockedtimestamp;
}
result.push(e);
}
}
};
for (var i=0; i<(list.length+50)/50; i++) {
promises.push($.ajax({
url: site,
data: {
format: 'json',
action: 'query',
list: 'users',
usprop: 'blockinfo|editcount',
ususers: list.slice(i*50, (i+1)*50).join('|')
},
dataType: 'jsonp',
type: 'POST',
}).done(mark));
}
$.when.apply($, promises).done(() => {
callback(result);
});
};
$('#sandbox_ok').click(() => {
let txt = $('#sandbox').val();
let obj = JSON.parse(txt);
let names = [];
let names2 = [];
$('#sandbox_ok').css('color', 'red');
for (let u of obj.query.logevents) {
names.push(u.user);
}
query('https://zh-yue.wikipedia.org/w/api.php', names, r => {
names2 = r.filter(u => u.editcount > 0).map(u => u.name);
query(mw.util.wikiScript('api'), names2, r => {
$('#sandbox_ok').css('color', 'blue');
let output = r.filter(u => u.blockreason).map(u => `${u.name}\t${u.blockreason}\t${u.blockedtimestamp}`).join('\n');
$('#sandbox2').val($('#sandbox2').val() + output + '\n');
});
});
});
$('#sandbox_fetch').click(() => {
let cont = $('#continue').val();
$('#sandbox_fetch').css('color', 'red');
let data = {
format: 'json',
action: 'query',
list: 'logevents',
letype: 'newusers',
lelimit: 500,
};
if (cont) {
data.lecontinue = cont;
}
$.ajax({
url: 'https://zh-yue.wikipedia.org/w/api.php',
data: data,
dataType: 'jsonp',
type: 'POST',
}).done(data => {
$('#sandbox_fetch').css('color', 'blue');
$('#continue').val(data.continue.lecontinue);
$('#sandbox').val(JSON.stringify(data));
$('#sandbox_ok').click();
});
});