User:實驗性:無用論廢人/OnlineAdmins.js
注意:在您儲存之後您必須清除瀏覽器快取才可看到最新的變動。
- Firefox / Safari:按住「Shift」時點選「重新整理」,或按「Ctrl-F5」或「Ctrl-R」 (Mac則為「⌘-R」)
- Google Chrome:按「Ctrl-Shift-R」 (Mac 則為「⌘-Shift-R」)
- Internet Explorer:按住「Ctrl」時點選「重新整理」,或按「Ctrl-F5」
- Opera:進入「工具→偏好設定」中清除快取。
- 如果您已登入但該頁面出現未登入狀態,請嘗試在網址列的URL最後新增代碼
?_=1
來訪問最新頁面。
//將[[User:星海子/js/OnlineAdmins.js]]改造
/**
* 取自[[zhwp:MediaWiki:Gadget-OnlineAdmins.js]],oldid=64572008。
* 已萌百化。
*/
(function($, mw) {
$.when($.ready, mw.loader.using(['mediawiki.api','ext.gadget.site-lib'])).then(function(){
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
'p-cactions',
'#',
wgULS('在線人員', '線上人員'),
'ca-onlineadmin'
);
var rcstart,
rcend,
time;
var users = [];
var sysops = [],
patrollers = [],
goodeditors = [],
interfaces = [],
scripteditors = [],
techeditors = [];
var api = new mw.Api();
// Bind click handler
$(portletLinkOnline).click(function(e) {
e.preventDefault();
users = [];
var usersExt = [];
sysops = [];
patrollers = [];
goodeditors = [];
interfaces = [];
scripteditors = [];
techeditors = [];
// 最近更改30分鐘內的編輯用戶
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 30);
rcend = time.toISOString();
//API:RecentChanges
api.get({
format: 'json',
action: 'query',
list: 'recentchanges',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[i] = item.user;
});
api.get({
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.logevents, function(i, item) {
usersExt[i] = item.user;
});
Array.prototype.push.apply(users, usersExt);
// 使用者名稱去重與分割
users = $.unique(users.sort());
var promises = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
// 找到管理員,去除bot
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('sysop', user.groups) > -1) {
sysops[i] = user.name;
}
if ($.inArray('patroller', user.groups) > -1) {
patrollers[i] = user.name;
}
if ($.inArray('goodeditor', user.groups) > -1) {
goodeditors[i] = user.name;
}
if ($.inArray('interface-admin', user.groups) > -1) {
interfaces[i] = user.name;
}
if ($.inArray('scripteditor', user.groups) > -1) {
scripteditors[i] = user.name;
}
if ($.inArray('techeditor', user.groups) > -1) {
techeditors[i] = user.name;
}
}
});
};
for (var i = 0; i < (users.length + 50) / 50; i++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: users.slice(i * 50, (i + 1) * 50).join('|'),
usprop: 'groups'
}).done(mark));
}
// 查詢用戶權限
$.when.apply($, promises).done(function() {
// 消除空值
var filter = function(n) {
return n;
};
sysops = sysops.filter(filter);
patrollers = patrollers.filter(filter);
goodeditors = goodeditors.filter(filter);
interfaces = interfaces.filter(filter);
scripteditors = scripteditors.filter(filter);
techeditors = techeditors.filter(filter);
var userlink = function(user) {
var user2 = user.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '<');
return '<a href="/User:' + user2 + '" target="_blank">' + user2 + '</a> <small style="opacity:.75;">(<a href="/User talk:' + user2 + '" target="_blank">留言</a>)</small> ';
};
if (sysops.length + patrollers.length > 0) {
var adminsstring = [wgULS('<p>下面是最近30分鐘之內在線的人員</p>', '<p>下面是最近30分鐘內的線上人員</p>')];
if (sysops.length > 0) {
adminsstring.push('<p style="word-break:break-all;">' + wgULS('管理員', '管理員') + ' (' + sysops.length + wgULS('個在線', '個在線') + '):');
$.each(sysops, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
if (patrollers.length > 0) {
adminsstring.push('<p style="word-break:break-all;">' + wgULS('巡查姬', '巡查姬') + ' (' + patrollers.length + wgULS('個在線', '個在線') + '):');
$.each(patrollers, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
if (goodeditors.length > 0) {
adminsstring.push('<p style="word-break:break-all;">' + wgULS('優質編輯者', '優質編輯者') + ' (' + goodeditors.length + wgULS('個在線', '個在線') + '):');
$.each(goodeditors, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
if (interfaces.length > 0) {
adminsstring.push('<p style="word-break:break-all;">' + wgULS('界面管理員', '界面管理員') + ' (' + interfaces.length + wgULS('個在線', '個在線') + '):');
$.each(interfaces, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
if (scripteditors.length > 0) {
adminsstring.push('<p style="word-break:break-all;">' + wgULS('腳本編輯員', '腳本編輯員') + ' (' + scripteditors.length + wgULS('個在線', '個在線') + '):');
$.each(scripteditors, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
if (techeditors.length > 0) {
adminsstring.push('<p style="word-break:break-all;">' + wgULS('技術編輯員', '技術編輯員') + ' (' + techeditors.length + wgULS('個在線', '個在線') + '):');
$.each(techeditors, function(i, e) {
adminsstring.push(userlink(e));
});
adminsstring.push('</p>');
}
mw.notify($(adminsstring.join('')));
} else {
mw.notify(wgULS('目前沒有人員在線。', '目前沒有人員在線。'));
}
}).fail(function() {
mw.notify(wgULS('查詢時發生錯誤,請稍後重試。', '查詢時發生錯誤,請稍後重試。'));
});
});
});
});
});
})(jQuery, mw);
此頁面最後編輯於 2022年8月8日 (星期一) 16:26。