User:Natureium/userrights.js

// /* Modified version of User:Splarka/sysopdectector.js

Sysop decrier/detector (rights group displayer), version [0.2.0a] Originally from http://en.wikipedia.org/wiki/User:Splarka/sysopdectector.js Options: var showUserGroupSettings = { IP: true, unregistered: true, registered: true, groups: true, editcount: true, regdate: true, blocked: true, filter: ['user', '*', 'autoconfirmed']; fontSize: '80%' }; if ((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) && (mw.config.get('wgTitle').indexOf('/') == -1) && (mw.config.get('wgAction') == 'view')) { $(showUserGroups); }
 * All are assumed false if omitted. All but 'groups' are assumed false if undefined.

function showUserGroups { var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&callback=showUserGroupsCB&maxage=3600&smaxage=3600&usprop=blockinfo|groups|editcount|registration&list=users&ususers=' + encodeURIComponent(wgTitle); mw.loader.load(url); }

function showUserGroupsCB(obj) { var defaults = { IP: false, unregistered: false, registered: false, groups: true, editcount: true, regdate: true, blocked: true, filter: ['user', '*', 'autoconfirmed'] };	var show = Object.assign({}, defaults, window.showUserGroupSettings); var user = {}; var someHeading = ''; if (obj.query && obj.query.users) { user = obj.query.users; } else { return; } if (user.length > 0 ) { user = user[0]; } else { return; } if ($('h1, h2').length > 0) { someHeading = $('h1:first') || $('h2:first'); } else { return; } var title = 'User:' + user.name + ' '; someHeading.attr('title', title).addClass('detected-userrights-heading'); var text = ' '; if (user.invalid) { if (show.IP) text += '[IP] '; else title += '[invalid or IP username] '; } else if (user.missing) { if (show.unregistered) text += '[doesn\'t exist] '; else title += '[not a registered name] '; } else { if (show.registered) { text += '[exists] '; } else { title += '[username registered] '; }		if (user.groups) { show.filter.forEach(function(id) {				if (user.groups.includes(id)) {					user.groups.splice(user.groups.indexOf(id), 1);				}			}); text += ('[' + user.groups.join(', ') + '] '); }		if (user.editcount) { if (show.editcount) { text += '[' + user.editcount + ' edits] '; } else { title += '[' + user.editcount + ' edits] '; }		}		if (user.registration) { if (show.regdate) { text += '[created: ' + user.registration.split('T')[0] + '] '; } else { title += '[created: ' + user.registration + '] '; }		}		if ( user.blockedby ) { if (show.blocked) text += '[blocked] '; else text += '[currently blocked] '; }	}	var span = $(' ', {		'text': text, 		'style':'font-size:' + show.fontSize + ';', 		'class':'detected-userrights'	}).appendTo(someHeading); } //