User:MoonlightVector/thing.js

//

mw.hook('wikipage.content').add(function($content){	$.when( // TODO: FIX CACHING. This is broken. Need to switch from index.php to api.php // &maxage=86400&smaxage=86400&uselang=content = cache for 1 day // staff and sysadmins (updated manually when I get around to it) $.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&maxage=86400&smaxage=86400&uselang=content&title=User:Novem_Linguae/User_lists/Staff_and_sysadmins.js', function(data){			staffdata = data;		}), // productive IP's (updated manually when I get around to it) // these are some IP's that I've selected that have hundreds of edits and are a net positive to the encyclopedia. We'll highlight them gray (extended confirmed). $.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&maxage=86400&smaxage=86400&uselang=content&title=User:Novem_Linguae/User_lists/Productive_IPs.js', function(data){			productiveIPs = data;		}), // arbcom (updated manually by various admins) $.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&maxage=86400&smaxage=86400&uselang=content&title=User:AmoryBot/crathighlighter.js/arbcom.json', function(data){			acdata = data;		}), // everybody else (updated daily by my bot) $.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&maxage=86400&smaxage=86400&uselang=content&title=User:NovemBot/userlist.js', function(data){			swdata = data['steward'];			crdata = data['bureaucrat'];			addata = data['sysop'];			nprdata = data['patroller'];			ecdata = data['extendedconfirmed'];			tenkdata = data['10k'];		}) ).then(function { // Combine some vars that we couldn't combine above due to async swdata = { ...{'Jimbo Wales': 1}, ...staffdata, ...swdata };		ecdata = { ...ecdata, ...productiveIPs };		// admin alternative accounts acdata['AdmiralEek'] = 1; // CaptainEek addata['PEIsquirrel'] = 1; // Ivanvector addata['SubjectiveNotability'] = 1; // GeneralNotability addata['In actu'] = 1; // Guerilero addata['Nyttend backup'] = 1; // Nyttend ADMINHIGHLIGHT_NAMESPACES = [-1,2,3]; mw.loader.using(['mediawiki.util','mediawiki.Uri', 'mediawiki.Title'], function {			// Note: .plainlinks is for Wikipedia Signpost articles			mw.util.addCSS(".override-signature-colors, .override-signature-colors span, .plainlinks .override-signature-colors.external, .override-signature-colors b, .override-signature-colors font {color: #0066AA !important;}");			// extended confirmed (53,000)			mw.util.addCSS(".userhighlighter_excon, .userhighlighter_excon span, .plainlinks .userhighlighter_excon.external, .userhighlighter_excon b, .userhighlighter_excon font {color: #00AAAA !important;}"); // Teal			// 10k edits (10,000)			mw.util.addCSS(".userhighlighter_tenk, .userhighlighter_tenk span, .plainlinks .userhighlighter_tenk.external, .userhighlighter_tenk b, .userhighlighter_tenk font {color: #6666AA !important;}"); // 			// New page reviewer (714)			mw.util.addCSS(".userhighlighter_npruser, .userhighlighter_npruser span, .plainlinks .userhighlighter_npruser.external, .userhighlighter_npruser b, .userhighlighter_npruser font {color: #4800AA !important;}"); // Admin mw.util.addCSS(".userhighlighter_sysop, .userhighlighter_sysop span, .plainlinks .userhighlighter_sysop.external, .userhighlighter_sysop b, .userhighlighter_sysop font {color: #AA3200 !important;}"); // bureaucrat mw.util.addCSS(".userhighlighter_bureaucrat, .userhighlighter_bureaucrat span, .plainlinks .userhighlighter_bureaucrat.external, .userhighlighter_bureaucrat b, .userhighlighter_bureaucrat font {color: #AA6600 !important; }"); // arbcom mw.util.addCSS(".userhighlighter_arbcom, .userhighlighter_arbcom span, .plainlinks .userhighlighter_arbcom.external, .userhighlighter_arbcom b, .userhighlighter_arbcom font {color: #AA6600 !important;}"); // steward mw.util.addCSS(".userhighlighter_steward, .userhighlighter_steward span, .plainlinks .userhighlighter_steward.external, .userhighlighter_steward b, .userhighlighter_steward font {color: #AA6648 !important; }"); $('#article a, #bodyContent a, #mw_contentholder a').each(function(index,linkraw){				try {					var link = $(linkraw);					var url = link.attr('href');					// Skip  elements that aren't actually links; skip anchors					if ( ! url || url.charAt(0) === '#' ) return; 					//require http(s) links, avoid "javascript:..." etc. which mw.Uri does not support					if ( url.lastIndexOf("http://", 0) !== 0 && url.lastIndexOf("https://", 0) !== 0 && url.lastIndexOf("/", 0) !== 0 ) {						return;					}					var uri = new mw.Uri(url);					// Skip links with query strings					// Example: The pagination links, diff links, and revision links on the Special:Contributions page					// Those all have "query strings" such as "&oldid=1003511328"					// Exception: Users without a user page (red link) need to be highlighted					let isRedLinkUserPage = url.startsWith('/w/index.php?title=User:') && url.endsWith('&action=edit&redlink=1');					if ( ! $.isEmptyObject(uri.query) && ! isRedLinkUserPage ) return;					if ( uri.host == 'en.wikipedia.org' ) {						// Figure out the wikipedia article title of the link						let titleParameterOfURL = mw.util.getParamValue('title',url); // for links in the format /w/index.php?title=Blah						let URI = decodeURIComponent(uri.path.slice(6)); // for links in the format /wiki/PageName. Slice off the /wiki/ (first 6 characters)						let title = titleParameterOfURL || URI;						var mwtitle = new mw.Title(title);						if ( $.inArray(mwtitle.getNamespaceId, ADMINHIGHLIGHT_NAMESPACES) >= 0 ) {							var user = mwtitle.getMain.replace(/_/g," ");							if (mwtitle.getNamespaceId === -1) {								user = user.replace('Contributions/',); // For special page "Contributions/ "								user = user.replace('Contribs/',); // The Contribs abbreviation too							}							let hasAdvancedPermissions = false;							if (swdata[user] == 1) {								link.addClass(link.attr('class') + ' userhighlighter_steward'); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Steward"); hasAdvancedPermissions = true; }							if(crdata[user] == 1) { link.addClass(link.attr('class') + ' userhighlighter_bureaucrat'); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Bureaucrat"); hasAdvancedPermissions = true; }							if(acdata[user] == 1) { link.addClass(link.attr('class') + ' userhighlighter_arbcom'); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Arbitration Committee member"); hasAdvancedPermissions = true; }							if (addata[user] == 1) { link.addClass(link.attr('class') + ' userhighlighter_sysop'); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Admin"); hasAdvancedPermissions = true; }							if(nprdata[user] == 1) { link.addClass(link.attr('class') + " userhighlighter_npruser"); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "New page reviewer"); hasAdvancedPermissions = true; }							if(tenkdata[user] == 1) { link.addClass(link.attr('class') + " userhighlighter_tenk"); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "More than 10,000 edits"); hasAdvancedPermissions = true; }							if(ecdata[user] == 1) { link.addClass(link.attr('class') + " userhighlighter_excon"); if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Extended confirmed"); hasAdvancedPermissions = true; }							// 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 ( hasAdvancedPermissions ) { link.addClass(link.attr('class') + ' override-signature-colors'); }						}					}				} catch (e) { // Sometimes we will run into unparsable links. No big deal. Just move on. }			});		});	}); });

//