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

Content deleted Content added
refactoring to allow for custom labels
adding ๐Ÿ•ต๏ธ for check users
ย 
(9 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 = {
// console.time("get usernames")
wmf: ['๐ŸŒ', 'Wikimedia Foundation (WMF)'],
adminsbot: ['๐Ÿงน๐Ÿค–', 'AdminBot'],
stewards: ['๐Ÿฉบ', 'Steward or Ombud'],
arbcom: ['โš–๏ธ', 'Arbitration Committee member'],
bureaucrats: ['๐Ÿ’ผโ€๐Ÿ’ผ', 'Bureaucrat'],
checkUsers: ['๐Ÿ•ต๏ธ๏ธ๏ธ๏ธ', 'Check User'],
formerAdminsadmins: ['๐Ÿšฌ๐Ÿงน', 'Former Admin'],
formerAdmins: ['๐Ÿšฌ', 'Former Admin'],
newPageReviewers: ['๐Ÿงบ', 'New page reviewer'],
tenThousandEdits: ['๐Ÿฅ‡๐Ÿ“š', 'More than 10,000 edits'],
extendedConfirmed: ['๐Ÿ“š๐Ÿ“˜', 'Extended confirmed'],
lessThan500: ['๐Ÿฃ', 'Less than 500 edits'],
};
 
if(this.window.UserRoleIndicatorCustomLabels){
this.roleInfoLookup = { ...defaultRoleInfoLookup, ...window.UserRoleIndicatorCustomLabels };
}else{
const this.roleInfoLookup = {defaultRoleInfoLookup;
}
 
this.labelPosition = "after";
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 39 โŸถ 74:
this.addRoleInfoIfNeeded();
} );
// console.timeEnd("linkloop")
 
//console.timeEnd("uri");
//console.log("-------");
}
 
Line 79 โŸถ 117:
 
async getUsernames() {
if(this.wmf){
return;
}
 
const dataString = await this.getWikitextFromCache( 'User:NovemBot/userlist.js' );
const dataJSON = JSON.parse( dataString );
Line 93 โŸถ 136:
// ...dataJSON['global-sysop'],
};
..this.bot = dataJSON.bot,;
this.stewards = dataJSON.steward;
this.arbcom = dataJSON.arbcom;
this.bureaucrats = dataJSON.bureaucrat;
this.admins = dataJSON.sysop;
this.checkUsers = dataJSON.checkuser;
this.formerAdmins = dataJSON.formeradmin;
this.newPageReviewers = dataJSON.patroller;
Line 102 โŸถ 147:
this.extendedConfirmed = {
...dataJSON.extendedconfirmed,
...dataJSON.bot,
...dataJSON.productiveIPs
};
Line 240 โŸถ 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 247 โŸถ 301:
 
addRoleInfoIfNeeded() {
const roleInfoLookup = {
wmf: ['๐ŸŒ', 'Wikimedia Foundation (WMF)'],
stewards: ['๐Ÿฉบ', 'Steward or Ombud'],
arbcom: ['โš–๏ธ', 'Arbitration Committee member'],
bureaucrats: ['๐Ÿ’ผโ€', 'Bureaucrat'],
admins: ['๐Ÿงน', 'Admin'],
formerAdmins: ['๐Ÿšฌ', 'Former Admin'],
newPageReviewers: ['๐Ÿงบ', 'New page reviewer'],
tenThousandEdits: ['๐Ÿฅ‡', 'More than 10,000 edits'],
extendedConfirmed: ['๐Ÿ“š', 'Extended confirmed'],
lessThan500: ['๐Ÿฃ', 'Less than 500 edits'],
};
// highlight anybody with "WMF" in their name, case insensitive. this should not generate false positives because "WMF" is on the username blacklist. see https://meta.wikimedia.org/wiki/Title_blacklist
if ( this.user.match( /^[^/]*WMF/i ) ) {
this.addRoleIcon( '๐ŸŒ'this.roleInfoLookup.wmf[0], 'Wikimedia Foundation (WMF)'this.roleInfoLookup.wmf[1] );
}
 
// TODO: grab the order from an array, so I can keep checkForPermission and addCSS in the same order easily, lowering the risk of the HTML title="" being one thing, and the color being another
this.addRoleInfoIfAppropriate( this.wmf, roleLookupthis.roleInfoLookup.wmf[0], roleLookupthis.roleInfoLookup.wmf[1]);
this.addRoleInfoIfAppropriate( this.stewardsbot, roleLookupthis.stewardsroleInfoLookup.bot[0], roleLookupthis.roleInfoLookup.stewardsbot[1]);
this.addRoleInfoIfAppropriate( this.arbcomstewards, roleLookupthis.arbcomroleInfoLookup.stewards[0], roleLookupthis.roleInfoLookup.arbcomstewards[1]);
this.addRoleInfoIfAppropriate( this.bureaucratsarbcom, roleLookupthis.bureaucratsroleInfoLookup.arbcom[0], roleLookupthis.roleInfoLookup.bureaucratsarbcom[1]);
this.addRoleInfoIfAppropriate( this.adminsbureaucrats, roleLookupthis.adminsroleInfoLookup.bureaucrats[0], roleLookupthis.roleInfoLookup.adminsbureaucrats[1]);
this.addRoleInfoIfAppropriate( this.formerAdminscheckUsers, roleLookupthis.formerAdminsroleInfoLookup.checkUsers[0], roleLookupthis.roleInfoLookup.formerAdminscheckUsers[1]);
this.addRoleInfoIfAppropriate( this.newPageReviewersadmins, roleLookupthis.newPageReviewersroleInfoLookup.admins[0], roleLookupthis.roleInfoLookup.newPageReviewersadmins[1]);
this.addRoleInfoIfAppropriate( this.tenThousandEditsformerAdmins, roleLookupthis.tenThousandEditsroleInfoLookup.formerAdmins[0], roleLookupthis.roleInfoLookup.tenThousandEditsformerAdmins[1]);
this.addRoleInfoIfAppropriate( this.extendedConfirmednewPageReviewers, roleLookupthis.extendedConfirmedroleInfoLookup.newPageReviewers[0], roleLookupthis.roleInfoLookup.extendedConfirmednewPageReviewers[1]);
this.addRoleInfoIfAppropriate( this.tenThousandEdits, this.roleInfoLookup.tenThousandEdits[0], this.roleInfoLookup.tenThousandEdits[1]);
this.addRoleInfoIfAppropriate( this.extendedConfirmed, this.roleInfoLookup.extendedConfirmed[0], this.roleInfoLookup.extendedConfirmed[1]);
 
// If they have no perms, then they are non-EC, so <500 edits
if ( !this.hasAdvancedPermissions ) {
this.addRoleIcon(this.roleInfoLookup.lessThan500[0], this.roleInfoLookup.lessThan500[1]);
}
}
}
 
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 293 โŸถ 339:
mw.hook( 'postEdit' ).add( async () => {
await mw.loader.using( [ 'mediawiki.util', 'mediawiki.Uri', 'mediawiki.Title' ], async () => {
await ( new UserRoleIndicator( $, mw, window ) )userRoleIndicator.execute();
} );
} );