User:NigelSoft/common.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
importScript('User:NigelSoft-Library/Scripts/CSTLiveClock.js');
importScript('User:PhiLiP/wikicache/load.js');
addOnloadHook(function () {
var hist; var url;
if (!(hist = document.getElementById('ca-history') )) return;
if (!(url = hist.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
wgULS('清理缓存'), 'ca-purge', wgULS('清理服务器缓存'), 'p');
});
// Doc: https://www.mediawiki.org/wiki/API:Users
importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
importScript('User:Chmarkine/translatetooltip.js');
/* https://en.wikipedia.org/w/api.php?
action=query &
list=users &
ususers=1.2.3.4%7CCatrope%7CVandal01%7CBob &
usprop=blockinfo%7Cgroups%7Ceditcount%7Cregistration%7Cemailable%7Cgender
*/
/*
usprop: Which properties to get
blockinfo: Whether the user is blocked, by whom and why
groups: All groups the user belongs to
implicitgroups: All groups a user is automatically a member of
rights: All rights the user has
editcount: The number of edits the user has made
registration: The time and date the user registered at
emailable: Whether the user can and wants to receive e-mail through Special:Emailuser
gender: Tags the gender of the user. Returns "male", "female", or "unknown"
*/
mw.loader.using( 'jquery.ui.button' );
var getBlockinfo = 1;
var getGroups = 1;
var getImplicitgroups = 1;
var getRights = 1;
var getEditcount = 1;
var getRegistration = 1;
var getEmailable = 1;
var getGender = 1;
function buildURL(username) {
var prop = ( (getBlockinfo)?"blockinfo%7C":"" ) + ( (getGroups)?"groups%7C":"" ) + ( (getImplicitgroups)?"implicitgroups%7C":"" ) +
( (getRights)?"rights%7C":"" ) + ((getEditcount)?"editcount%7C":"") + ((getRegistration)?"registration%7C":"") +
((getEmailable)?"emailable%7C":"") + ((getGender)?"gender%7C":"");
prop = prop.substring(0,prop.length-3);
var url = "/w/api.php?action=query&format=json&list=users&ususers=" + username + "&usprop=" + prop;
return url;
}
$("a").hover(function(){
var prefix_urluser = "/wiki/User:";
var link_href = $(this).attr("href");
link_href = link_href.replace("/wiki/User_talk:","/wiki/User:");
link_href = link_href.replace("/w/index.php?title=User:", "/wiki/User:");
link_href = link_href.replace("&action=edit&redlink=1", "");
var indexof_user = link_href.indexOf(prefix_urluser);
if (indexof_user != 0) {
return;
}
var username = link_href.substring( prefix_urluser.length );
if (username.indexOf("/")!= -1) {
username = username.substring(0, username.indexOf("/") );
}
if (username.indexOf("#")!= -1) {
username = username.substring(0, username.indexOf("#") );
}
var j_obj = $(this);
var url = buildURL(username);
$.get(url, function(data){
var obj_user = data.query.users[0];
var id = obj_user.userid;
var name = obj_user.name;
var editcount = obj_user.editcount;
var registration = obj_user.registration;
var gender = obj_user.gender;
var groups_array = obj_user.groups;
var rights_array = obj_user.rights;
if (gender == "male") {
gender = "男";
} else if (gender == "female") {
gender = "女";
} else {
gender = "未知";
}
if ((registration == null) || (registration == "null")) {
registration = "未知";
}
var strGroups = "";
for (var i=0; i<groups_array.length; i++) {
strGroups += groups_array[i] + "、";
}
strGroups = strGroups.substring(0, strGroups.lastIndexOf("、"));
j_obj.attr("title", "用户名:" + name + ";编辑数: " + editcount + "; 性别: " + gender + ";注册时间:" + registration + ";用户组:" + strGroups);
});
}, function(){} );