User:49TL/vector.js

// response helper - import

importScript('User:MusikAnimal/responseHelper.js')

// mark user - modified from gadget

function markUser( container ) { $("[data-user-group]").removeAttr("data-user-group"); var ipv6Regex = /^((?=.*::)(?!.*::.+::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i; var contentLinks;

if ( container ) { contentLinks = $( container ).find( 'a' ); } else if ( mw.util.$content ) { contentLinks = mw.util.$content.find( 'a' ).add( '#ca-nstab-user a' ); } else { contentLinks = $; }

mw.util.addCSS('\	.ext-user[data-user-group]:before { content: attr(data-user-group); border-radius: 16px; font-weight: bold; font-size: 9px; padding: 3px 5px; font-style: normal; vertical-align: super; }\	.ext-user[data-user-group*=U]:before { border-top: 2px dotted #666666; border-left: 2px dotted #666666; color: #666666; }\	.ext-user[data-user-group*=P]:before { border-top: 2px solid #4F5BCC; border-left: 2px solid #4F5BCC; color: #4F5BCC; }\	.ext-user[data-user-group*=R]:before { border-top: 2px solid #FFA500; border-left: 2px solid #FFA500; color: #FFA500; }\	.ext-user[data-user-group*=E]:before { border-top: 2px solid #DB7093; border-left: 2px solid #DB7093; color: #DB7093; }\	.ext-user[data-user-group*=A]:before { border-top: 2px solid #8E0890; border-left: 2px solid #8E0890; color: #8E0890; }\	.ext-user[data-user-group*=I]:before { border-top: 2px solid #0000FF; border-left: 2px solid #0000FF; color: #0000FF; }\ .ext-user[data-user-group*=B]:before { border-top: 2px solid #29BBEC; border-left: 2px solid #29BBEC; color: #29BBEC; }\ .ext-user[data-user-group*=C]:before { border-top: 2px solid #8CB14F; border-left: 2px solid #8CB14F; color: #8CB14F; }\ .ext-user[data-user-group*=O]:before { border-top: 2px solid #D90222; border-left: 2px solid #D90222; color: #D90222; }\ .ext-user[data-user-group].user-warned:before { border-top: 2px dotted #999999; border-left: 2px dotted #999999; color: #999999; }\ .ext-user[data-user-group].user-blocked-temp:before { border-top: 2px solid #999999; border-left: 2px solid #999999; color: #999999; }\ .ext-user[data-user-group*=X].user-blocked-indef:before { border-top: 2px solid #000000; border-left: 2px solid #000000; color: #000000; }\ .ext-user[data-user-group*=x].user-blocked-partial:before { border-top: 2px solid #999999; border-left: 2px solid #999999; color: #999999; }\ ');	var userNS = [];	for ( var ns in mw.config.get( 'wgNamespaceIds' ) ) {		if ( mw.config.get( 'wgNamespaceIds' )[ns] == 2 || mw.config.get( 'wgNamespaceIds' )[ns] == 3 ) {			userNS.push( ns.replace( /_/g, ' ' ) + ':' );		}	}

var userTitleRX = new RegExp( '^(' + userNS.join( '|' ) + '|Special:Contributions\\/)([^\\/#]+)$', 'i' ); var articleRX = new RegExp( mw.config.get( 'wgArticlePath' ).replace('$1', '') + '([^#]+)' ); var scriptRX = new RegExp( '^' + mw.config.get( 'wgScript' ) + '\\?title=([^#&]+)' );

var userLinks = {}; var user, url, ma, pgTitle;

contentLinks.each( function( i, lnk ) {		url = $( lnk ).attr( 'href' );		if ( !url || url.charAt(0) != '/' ) {			return;		}		if ( ma = articleRX.exec( url ) ) {			pgTitle = ma[1];		} else if ( ma = scriptRX.exec( url ) ) {			pgTitle = ma[1];		} else {			return;		}		pgTitle = decodeURIComponent( pgTitle ).replace( /_/g, ' ' );		user = userTitleRX.exec( pgTitle );		if ( !user ) {			return;		}		user = user[2];		if( ipv6Regex.test(user) ) user = user.toUpperCase;		var sanitisedUser = user.replace(/[^A-Za-z0-9]/gi, "-");		var parentElement = $(lnk).closest("span.comment, li, dd, p, div, td");		var notAlreadyTagged = $(parentElement).find('.ext-user-' + sanitisedUser).length == 0;

if (($(lnk).attr("href").indexOf("/User:") != -1 || ($(lnk).attr("href").indexOf("?title=User:") != -1 && $(lnk).attr("href").indexOf("&redlink=1") != -1) || $(lnk).attr("href").indexOf("/User_talk:") != -1 || ($(lnk).attr("href").indexOf("?title=User_talk:") != -1 && $(lnk).attr("href").indexOf("&redlink=1") != -1) || $(lnk).attr("href").indexOf("/Special:Contributions/") != -1) && $(lnk).attr("href").indexOf("#") == -1 && notAlreadyTagged) { $( lnk ).addClass( 'ext-user' ); $( lnk ).addClass( 'ext-user-' + sanitisedUser ); }		if ( !userLinks[user] ) { userLinks[user] = []; }		userLinks[user].push (lnk ); } );

var users = []; var users2 = []; for ( var u in userLinks ) { users.push( u ); users2.push( u ); }	if ( users.length === 0 ) { return; }	while ( users.length > 0 ) { $.post( 			mw.util.wikiScript( 'api' ) + '?format=json&action=query',			{				list: 'blocks',				bklimit: 100,				bkusers: users.splice( 0, 50 ).join( '|' ),				bkprop: 'user|by|timestamp|expiry|reason|restrictions'			},			markLinks		); }	while ( users2.length > 0 ) { $.post( 			mw.util.wikiScript( 'api' ) + '?format=json&action=query',			{				list: 'users',				ususers: users2.splice( 0, 50 ).join( '|' ),				usprop: 'groups'			},			markLinks2		); }

return; function markLinks( resp, status, xhr ) { var list, blk, tip, links, lnk; if ( !resp || !( list = resp.query ) || !( list = list.blocks ) ) { return; }

for ( var i = 0; i < list.length; i++ ) { blk = list[i]; var attr = ''; if ( blk.restrictions && blk.restrictions.pages ) { clss = 'user-blocked-partial'; attr += 'x'			} else if ( /^in/.test( blk.expiry ) ) { clss = 'user-blocked-indef'; attr += 'X'			} else { clss = 'user-blocked-temp'; var hours = parseInt((new Date(blk.expiry) - new Date(blk.timestamp)) / 3600000); var days = parseInt(hours / 24); attr += (hours < 50 ? hours + "h" : days + "d"); }			links = userLinks[blk.user]; for ( var k = 0; links && k < links.length; k++ ) { lnk = $( links[k] ).addClass( clss ); if (attr) { var existingGroup = $( links[k] ).attr('data-user-group') ? $( links[k] ).attr('data-user-group') : ''; lnk = $( links[k] ).attr('data-user-group', existingGroup + attr); }			}		}	}	function markLinks2( resp, status, xhr ) { var list, usr, tip, links, lnk; if ( !resp || !( list = resp.query ) || !( list = list.users ) ) { return; }

for ( var i = 0; i < list.length; i++ ) { usr = list[i]; var attr = ''; if (usr.groups) { for (var l = 0; l < usr.groups.length; l++) { if (/^checkuser/.test( usr.groups[l] ) ) { attr += 'C'					} else if (/^oversight/.test( usr.groups[l] ) ) { attr += 'O'					} else if (/^bureaucrat/.test( usr.groups[l] ) ) { attr += 'B'					} else if (/^interface-admin/.test( usr.groups[l] ) ) { attr += 'I'					} else if (/^sysop/.test( usr.groups[l] ) ) { attr += 'A'					} else if (/^abusefilter/.test( usr.groups[l] ) ) { attr += 'E'					} else if (/^rollbacker/.test( usr.groups[l] ) ) { attr += 'R'					} else if (/^patroller/.test( usr.groups[l] ) ) { attr += 'P'					} else if (/^reviewer/.test( usr.groups[l] ) ) { attr += 'P'					} else if (/^user/.test( usr.groups[l] ) ) { //attr += 'U'					} }				attr = attr.replace("PP", "P"); }			links = userLinks[usr.name]; for ( var k = 0; links && k < links.length; k++ ) { if (attr) { var existingGroup = $( links[k] ).attr('data-user-group') ? $( links[k] ).attr('data-user-group') : ''; lnk = $( links[k] ).attr('data-user-group', existingGroup + attr); }			}		}	} }

$.when( $.ready, mw.loader.using( 'mediawiki.util' ) ).then( function {			markUser; 		} );