User:Base/contribAndGenderUserlinksMarker.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//TODO think on a way to optimise that all thing
//TODO fix problem with usernames containing '
function showUserInfo() {
var api = new mw.Api();
var users = [];
//Getting all links to userpages
var user_links = $("[title^='User:']");
//console.log(user_links.length);
if (user_links.length > 0) {
//running a function for each link
user_links.each(function(index) {
//getting each link's title
var link_title = $(this).attr("title");
//cutting User: from the titles so that we have a username
var username = link_title.substring(link_title.indexOf(":") + 1, link_title.length);
//cheking whether the username is already in the array, if not - pushing it there
if (users.indexOf({key: username}) == -1 && (!username.includes("/"))) {
users.push(username);
}
//console.log( index + ": " + username );
});
if (users.length > 0) {
//fetching data for the users in the array
api.get({
action: 'query',
list: 'users',
usprop: ['editcount', 'gender'],
ususers: users
}).done(function(data) {
for (var i = 0; i < data.query.users.length; i++) {
console.log( data.query.users[i] );
var this_user_links = $("[title='User:" + data.query.users[i].name + "']");
this_user_links.each(function(index) {
var gender_colour;
var gender = data.query.users[i].gender;
//console.log( gender );
switch (gender) {
case "unknown":
gender_colour = "silver";
break;
case "female":
gender_colour = "pink";
break;
case "male":
gender_colour = "skyblue";
break;
}
$(this).css("border-bottom", "3px double " + gender_colour);
var contribs_colour;
var contribs = data.query.users[i].editcount;
var contribs_colour_index = Math.floor(Math.log10(contribs)*2);
console.log(contribs_colour_index);
switch ( contribs_colour_index ) {
case 0:
contribs_colour = "#ff0000";
break;
case 1:
contribs_colour = "#ff3300";
break;
case 2:
contribs_colour = "#ff6600";
break;
case 3:
contribs_colour = "#ff9900";
break;
case 4:
contribs_colour = "#ffcc00";
break;
case 5:
contribs_colour = "#ffff00";
break;
case 6:
contribs_colour = "#ccff00";
break;
case 7:
contribs_colour = "#99ff00";
break;
case 8:
contribs_colour = "#66ff00";
break;
case 9:
contribs_colour = "#33ff00";
break;
case 10:
contribs_colour = "#00ff00";
break;
}
$(this).css("border-top", "3px double " + contribs_colour);
});
}
});
}
}
}
mediaWiki.loader.using(['mediawiki.api']).done(
$(showUserInfo)
);