User:Bugghost/Scripts/UserRoleIndicator.js: Difference between revisions

Content deleted Content added
m label swap
adding 🕵️ for check users
 
(2 intermediate revisions by the same user not shown)
Line 13:
this.mw = mw;
this.window = window;
this.linksChecked = new Set([]);
}
}
 
async execute() {
// //console.time("get usernamesuri");
const defaultRoleInfoLookup = {
wmf: ['🌐', 'Wikimedia Foundation (WMF)'],
Line 22 ⟶ 23:
stewards: ['🩺', 'Steward or Ombud'],
arbcom: ['⚖️', 'Arbitration Committee member'],
bureaucrats: ['💼‍💼', 'Bureaucrat'],
checkUsers: ['🕵️️️️', 'Check User'],
admins: ['🧹', 'Admin'],
formerAdmins: ['🚬', 'Former Admin'],
Line 37 ⟶ 39:
}
 
this.labelPosition = "after";
// console.time("get usernames")
if(this.window.UserRoleIndicatorCustomPlacement){
this.labelPosition = this.window.UserRoleIndicatorCustomPlacement;
}
 
//console.time("get usernames")
await this.getUsernames();
// //console.timeEnd("get usernames")
this.addCSS('user-role-indicator', 'font-size: smaller; display: inline; background: #b7b9ff55; padding: 0.1em; border-radius: 5px; margin-left: 3px;')
this.addCSS('label-after', 'margin-left:3px;');
this.addCSS('label-before', 'margin-right:1px;margin-left:2px;');
 
const $links = this.$( '#article a, #bodyContent a, #mw_contentholder a' );
 
// console.time("linkloop")
$links.each( ( index, element ) => {
this.$link = this.$( element );
if(this.linksChecked.has(element)){
return;
}
 
this.linksChecked.add(element);
 
if ( !this.linksToAUser() ) {
return;
Line 59 ⟶ 74:
this.addRoleInfoIfNeeded();
} );
// console.timeEnd("linkloop")
 
//console.timeEnd("uri");
//console.log("-------");
}
 
Line 99 ⟶ 117:
 
async getUsernames() {
if(this.wmf){
return;
}
 
const dataString = await this.getWikitextFromCache( 'User:NovemBot/userlist.js' );
const dataJSON = JSON.parse( dataString );
Line 118 ⟶ 141:
this.bureaucrats = dataJSON.bureaucrat;
this.admins = dataJSON.sysop;
this.checkUsers = dataJSON.checkuser;
this.formerAdmins = dataJSON.formeradmin;
this.newPageReviewers = dataJSON.patroller;
Line 260 ⟶ 284:
if ( !title || title.startsWith( 'User:' ) ) {
this.$link.attr( 'title', descriptionForHover );
 
this.$link.append($("<div class='user-role-indicator'>"+icon+"</div>"))
switch(this.labelPosition){
case "before":
this.$link.prepend($("<div class='user-role-indicator label-before'>"+icon+"</div>"))
break;
 
default:
// Defaults to "after"
this.$link.append($("<div class='user-role-indicator label-after'>"+icon+"</div>"))
break;
}
}
 
Line 279 ⟶ 313:
this.addRoleInfoIfAppropriate( this.arbcom, this.roleInfoLookup.arbcom[0], this.roleInfoLookup.arbcom[1]);
this.addRoleInfoIfAppropriate( this.bureaucrats, this.roleInfoLookup.bureaucrats[0], this.roleInfoLookup.bureaucrats[1]);
this.addRoleInfoIfAppropriate( this.checkUsers, this.roleInfoLookup.checkUsers[0], this.roleInfoLookup.checkUsers[1]);
this.addRoleInfoIfAppropriate( this.admins, this.roleInfoLookup.admins[0], this.roleInfoLookup.admins[1]);
this.addRoleInfoIfAppropriate( this.formerAdmins, this.roleInfoLookup.formerAdmins[0], this.roleInfoLookup.formerAdmins[1]);
Line 291 ⟶ 326:
}
}
 
var userRoleIndicator = new UserRoleIndicator( $, mw, window )
 
// Fire after wiki content is added to the DOM, such as when first loading a page, or when a gadget such as the XTools gadget loads.
mw.hook( 'wikipage.content' ).add( async () => {
await mw.loader.using( [ 'mediawiki.util', 'mediawiki.Uri', 'mediawiki.Title' ], async () => {
await ( new UserRoleIndicator( $, mw, window ) )userRoleIndicator.execute();
} );
} );
Line 302 ⟶ 339:
mw.hook( 'postEdit' ).add( async () => {
await mw.loader.using( [ 'mediawiki.util', 'mediawiki.Uri', 'mediawiki.Title' ], async () => {
await ( new UserRoleIndicator( $, mw, window ) )userRoleIndicator.execute();
} );
} );