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

Content deleted Content added
popup layout
adding 🕵️ for check users
 
(21 intermediate revisions by the same user not shown)
Line 1:
// [[User:Bugghost]]
// <nowiki>
// Copied and edited from novemNovem linguaeLinguae's user highlighter simple: [[User:Novem_Linguae/Scripts/UserHighlighterSimple.js]]
 
class UserRoleIndicator {
Line 14 ⟶ 13:
this.mw = mw;
this.window = window;
this.linksChecked = new Set([]);
}
}
 
async execute() {
//console.time("uri");
await this.getUsernames();
const defaultRoleInfoLookup = {
if ( !this.window.userHighlighterSimpleNoColors ) {
wmf: ['🌐', 'Wikimedia Foundation (WMF)'],
this.setHighlightColors();
bot: ['🤖', 'Bot'],
stewards: ['🩺', 'Steward or Ombud'],
arbcom: ['⚖️', 'Arbitration Committee member'],
bureaucrats: ['💼', 'Bureaucrat'],
checkUsers: ['🕵️️️️', 'Check User'],
admins: ['🧹', '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{
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;')
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 33 ⟶ 72:
}
this.hasAdvancedPermissions = false;
this.addClassesAndHoverTextToLinkIfNeededaddRoleInfoIfNeeded();
// If the user has any advanced perms, they are likely to have a signature, so be aggressive about overriding the background and foreground color. That way there's no risk their signature is unreadable due to background color and foreground color being too similar. Don't do this for users without advanced perms... being able to see a redlinked username is useful.
if ( this.hasAdvancedPermissions ) {
this.$link.addClass( this.$link.attr( 'class' ) + ' UHS-override-signature-colors' );
}
} );
//console.timeEnd("linkloop")
 
//console.timeEnd("uri");
//console.log("-------");
}
 
Line 78 ⟶ 117:
 
async getUsernames() {
if(this.wmf){
return;
}
 
const dataString = await this.getWikitextFromCache( 'User:NovemBot/userlist.js' );
const dataJSON = JSON.parse( dataString );
Line 92 ⟶ 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.formeradminscheckUsers = dataJSON.formeradmincheckuser;
this.formerAdmins = dataJSON.formeradmin;
this.newPageReviewers = dataJSON.patroller;
this.tenThousandEdits = dataJSON[ '10k' ];
this.extendedConfirmed = {
...dataJSON.extendedconfirmed,
...dataJSON.bot,
...dataJSON.productiveIPs
};
Line 228 ⟶ 273:
}
 
checkForPermissionaddRoleInfoIfAppropriate( listOfUsernames, classNamelabel, descriptionForHover ) {
if ( listOfUsernames[ this.user ] === 1 ) {
this.addClassAndHoverTextaddRoleIcon( classNamelabel, descriptionForHover );
}
}
 
addClassAndHoverTextaddRoleIcon( classNameicon, descriptionForHover ) {
this.$link.addClass( className );
 
const title = this.$link.attr( 'title' );
if ( !title || title.startsWith( 'User:' ) ) {
this.$link.attr( 'title', descriptionForHover );
 
this.$link.prepend($("<div class='user-role-indicator-container'><div class='user-role-indicator-inner'>🧹</div></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 246 ⟶ 300:
}
 
addRoleInfoIfNeeded() {
addClassesAndHoverTextToLinkIfNeeded() {
// 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.addClassAndHoverTextaddRoleIcon( 'UHS-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.checkForPermissionaddRoleInfoIfAppropriate( this.wmf, 'UHS-this.roleInfoLookup.wmf'[0], 'Wikimedia Foundation (WMF)' this.roleInfoLookup.wmf[1]);
this.addRoleInfoIfAppropriate( this.bot, this.roleInfoLookup.bot[0], this.roleInfoLookup.bot[1]);
this.checkForPermission( this.stewards, 'UHS-steward', 'Steward or Ombud' );
this.addRoleInfoIfAppropriate( this.stewards, this.roleInfoLookup.stewards[0], this.roleInfoLookup.stewards[1]);
this.checkForPermission( this.arbcom, 'UHS-arbitration-committee', 'Arbitration Committee member' );
this.addRoleInfoIfAppropriate( this.arbcom, this.roleInfoLookup.arbcom[0], this.roleInfoLookup.arbcom[1]);
this.checkForPermission( this.bureaucrats, 'UHS-bureaucrat', 'Bureaucrat' );
this.addRoleInfoIfAppropriate( this.bureaucrats, this.roleInfoLookup.bureaucrats[0], this.roleInfoLookup.bureaucrats[1]);
this.checkForPermission( this.admins, 'UHS-administrator', 'Admin' );
this.addRoleInfoIfAppropriate( this.checkUsers, this.roleInfoLookup.checkUsers[0], this.roleInfoLookup.checkUsers[1]);
this.checkForPermission( this.formeradmins, 'UHS-former-administrator', 'Former Admin' );
this.addRoleInfoIfAppropriate( this.admins, this.roleInfoLookup.admins[0], this.roleInfoLookup.admins[1]);
this.checkForPermission( this.newPageReviewers, 'UHS-new-page-reviewer', 'New page reviewer' );
this.addRoleInfoIfAppropriate( this.formerAdmins, this.roleInfoLookup.formerAdmins[0], this.roleInfoLookup.formerAdmins[1]);
this.checkForPermission( this.tenThousandEdits, 'UHS-10000edits', 'More than 10,000 edits' );
this.addRoleInfoIfAppropriate( this.newPageReviewers, this.roleInfoLookup.newPageReviewers[0], this.roleInfoLookup.newPageReviewers[1]);
this.checkForPermission( this.extendedConfirmed, 'UHS-500edits-bot-trustedIP', 'Extended confirmed' );
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, justthen drawthey aare box around their usernamenon-EC, to make itso more<500 visible.edits
if ( !this.hasAdvancedPermissions ) {
this.addRoleIcon(this.roleInfoLookup.lessThan500[0], this.roleInfoLookup.lessThan500[1]);
this.$link.addClass( 'UHS-no-permissions' );
const title = this.$link.attr( 'title' );
if ( !title || title.startsWith( 'User:' ) ) {
this.$link.attr( 'title', 'Less than 500 edits' );
}
}
}
}
 
var userRoleIndicator = new UserRoleIndicator( $, mw, window )
setHighlightColors() {
// Highest specificity goes on bottom. So if you want an admin+steward to be highlighted steward, place the steward CSS below the admin CSS in this section.
this.addCSS( 'UHS-override-signature-colors', `
color: #0645ad !important;
background-color: transparent !important;
background: unset !important;
` );
 
this.addCSS('user-role-indicator-container', 'position: relative !important; ')
this.addCSS('user-role-indicator-inner', 'position: absolute; position: absolute; top: 1em; right: 0px; font-size: smaller; background-color: #333 !important;')
 
this.mw.util.addCSS( '.UHS-no-permissions { border: 1px solid black !important; }' );
 
// 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.addCSS( 'UHS-500edits-bot-trustedIP', 'background-color: #0f0 !important;' );
this.addCSS( 'UHS-10000edits', 'background-color: #9c9 !important;' );
this.addCSS( 'UHS-new-page-reviewer', 'background-color: #99f !important;' );
this.addCSS( 'UHS-former-administrator', 'background-color: #D3AC8B !important;' );
this.addCSS( 'UHS-administrator', 'background-color: #9ff !important;' );
this.addCSS( 'UHS-bureaucrat', 'background-color: orange !important; color: #0645ad !important;' );
this.addCSS( 'UHS-arbitration-committee', 'background-color: #FF3F3F !important; color: white !important;' );
this.addCSS( 'UHS-steward', 'background-color: #00FF00 !important;' );
this.addCSS( 'UHS-wmf', 'background-color: hotpink !important; color: #0645ad !important;' );
}
}
 
// 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 309 ⟶ 339:
mw.hook( 'postEdit' ).add( async () => {
await mw.loader.using( [ 'mediawiki.util', 'mediawiki.Uri', 'mediawiki.Title' ], async () => {
await ( new UserRoleIndicator( $, mw, window ) )userRoleIndicator.execute();
} );
} );