Jump to content

User:Pythoncoder/Scripts/userHighlighter.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
migrate from mw.uri to URL per instructions at Wikipedia:Village_pump_(technical)#Tech_News:_2025-08
code cleanup (some code taken from User:Anne_drew/admintagger-plus.js)
Line 1: Line 1:
//<nowiki>
//<nowiki>
/**
/**
* User highlighter 3.0
* User highlighter 3.1
* ---------------------
* ---------------------
* A jQuery/mediawiki-heavy rewrite of [[User:Amalthea/userhighlighter.js]]
* A jQuery/mediawiki-heavy rewrite of [[User:Amalthea/userhighlighter.js]]
Line 10: Line 10:
* and higher-ranked permissions.
* and higher-ranked permissions.
*
*
* The direct source for this script is a combination of Bellezzasolo's (adds
* The original source for this script is a combination of Bellezzasolo's (adds
* intermediate-level groups) and Amorymeltzer's (adds advanced-level groups)
* intermediate-level groups) and Amorymeltzer's (adds advanced-level groups)
* versions of the script. You may be interested in
* versions of the script. You may be interested in
Line 26: Line 26:
* @author Amorymeltzer
* @author Amorymeltzer
* @author Pythoncoder
* @author Pythoncoder
*
* Version 3.1 will be released in 2025. In addition to removing deprecated
* MediaWiki functionality (which originally prompted the update),
* I'm taking the time to backport some features from forks of this script,
* so I guess I should add more credits:
*
* @author Anne_drew
*/
*/
(function($, mw){
(function($, mw){
mw.hook('wikipage.content').add(function(){
mw.hook('wikipage.content').add(function(){
var ecdata, pcdata, mvdata, tpdata, addata;
$.when(
$.when(
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/arbcom.json', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/arbcom.json',
function(data){
acdata = data;
acdata = data;
}
}),
),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/bureaucrat.json', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
crdata = data;
'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/oversight.json',
}),
function(data){
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/oversight.json', function(data){
osdata = data;
osdata = data;
}
}),
),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/checkuser.json', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
cudata = data;
'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/checkuser.json',
}),
function(data){
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/excon.js', function(data){
ecdata = data;
cudata = data;
}
}),
),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pcusr.js', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
pcdata = data;
'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pcusr.js',
}),
function(data){
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pgmvr.js', function(data){
mvdata = data;
pcdata = data;
}
}),
),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/temop.js', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
tpdata = data;
'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pgmvr.js',
}),
function(data){
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/sysop.json', function(data){
addata = data;
mvdata = data;
}
}),
),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/ptusr.js', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
ptdata = data;
'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/temop.js',
}),
function(data){
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/interface-admin.json', function(data){
iadata = data;
tpdata = data;
}
}),
),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/steward.json', function(data){
$.getJSON(mw.config.get('wgScriptPath')+
swdata = data;
'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/ptusr.js',
})).then(function() {
function(data){
ptdata = data;
}
),
$.getJSON(mw.config.get('wgScriptPath')+
'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/interface-admin.json',
function(data){
iadata = data;
}
),
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:NovemBot/userlist.js",
function (data) {
bureaucratData = data.bureaucrat;
stewardData = data.steward;
adminData = data.sysop;
formerAdminData = data.formeradmin;
extendedConfirmedData = data.extendedconfirmed;
tenKData = data['10k'];
}
)).then(function() {
ADMINHIGHLIGHT_EXTLINKS = window.ADMINHIGHLIGHT_EXTLINKS || false;
ADMINHIGHLIGHT_EXTLINKS = window.ADMINHIGHLIGHT_EXTLINKS || false;
ADMINHIGHLIGHT_NAMESPACES = [-1,2,3];
ADMINHIGHLIGHT_NAMESPACES = [-1,2,3];
Line 98: Line 128:
if (mwtitle.getNamespaceId() === -1) user = user.replace('Contribs/',''); // The Contribs abbreviation too
if (mwtitle.getNamespaceId() === -1) user = user.replace('Contribs/',''); // The Contribs abbreviation too
if (swdata[user] == 1) {
if (stewardData[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_steward');
link.addClass(link.attr('class') + ' userhighlighter_steward');
}
}
if(crdata[user] == 1) {
if(bureaucratData[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_bureaucrat');
link.addClass(link.attr('class') + ' userhighlighter_bureaucrat');
}
}
Line 116: Line 146:
link.addClass(link.attr('class') + ' userhighlighter_checkuser');
link.addClass(link.attr('class') + ' userhighlighter_checkuser');
}
}
if (addata[user] == 1) {
if (adminData[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_sysop');
link.addClass(link.attr('class') + ' userhighlighter_sysop');
}
}
if(tpdata[user] == 1) {
if(tpdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_temop"); // Override the above color by using `a.userhighlighter_temop.userhighlighter_temop {background-color: COLOR !important}`
link.addClass(link.attr('class') + " userhighlighter_temop");
}
}
if(mvdata[user] == 1) {
if(mvdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_pgmvr"); // Override the above color by using `a.userhighlighter_pgmvr.userhighlighter_pgmvr {background-color: COLOR !important}`
link.addClass(link.attr('class') + " userhighlighter_pgmvr");
}
}
if(ptdata[user] == 1) {
if(ptdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_ptusr"); // Override the above color by using `a.userhighlighter_ptusr.userhighlighter_ptusr {background-color: COLOR !important}`
link.addClass(link.attr('class') + " userhighlighter_ptusr");
}
}
if(pcdata[user] == 1) {
if(pcdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_pcusr"); // Override the above color by using `a.userhighlighter_pcusr.userhighlighter_pcusr {background-color: COLOR !important}`
link.addClass(link.attr('class') + " userhighlighter_pcusr");
}
}
if(ecdata[user] == 1) {
if(extendedConfirmedData[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_excon"); // Override the above color by using `a.userhighlighter_excon.userhighlighter_excon {background-color: COLOR !important}`
link.addClass(link.attr('class') + " userhighlighter_excon");
}
}
if(user == 'Jimbo Wales') {
if(user == 'Jimbo Wales') {
link.addClass(link.attr('class') + " userhighlighter_jimbo"); // Override the above color by using `a.userhighlighter_jimbo.userhighlighter_jimbo {background-color: COLOR !important}`
link.addClass(link.attr('class') + " userhighlighter_jimbo");
}
}
}
}

Revision as of 06:12, 20 February 2025

//<nowiki>
/**
 * User highlighter 3.1
 * ---------------------
 * A jQuery/mediawiki-heavy rewrite of [[User:Amalthea/userhighlighter.js]]
 * 
 * This script highlights links to admins' userpages or talkpages in bodyContent
 * (that is, everything but the tabs, personal links at the top of the screen and sidebar)
 * by giving them a gold background. It also colors links to userpages of users with lower
 * and higher-ranked permissions.
 *
 * The original source for this script is a combination of Bellezzasolo's (adds
 * intermediate-level groups) and Amorymeltzer's (adds advanced-level groups) 
 * versions of the script. You may be interested in
 * [[User:Chlod/Scripts/UserHighlighter.js]], which adds a tooltip showing 
 * a user's groups. However, I continue to use this version because Navigation
 * Popups already covers this functionality. This script has been forked many 
 * times; please see my documentation page for a full chart of these forks.
 * 
 * TODO: Rollback
 *
 * @author Ais523
 * @author Amalthea
 * @author Theopolisme
 * @author Bellezzasolo
 * @author Amorymeltzer
 * @author Pythoncoder
 * 
 * Version 3.1 will be released in 2025. In addition to removing deprecated
 * MediaWiki functionality (which originally prompted the update), 
 * I'm taking the time to backport some features from forks of this script,
 * so I guess I should add more credits:
 * 
 * @author Anne_drew
 */
(function($, mw){
mw.hook('wikipage.content').add(function(){
	$.when(
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/arbcom.json', 
		function(data){
			acdata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/oversight.json', 
		function(data){
			osdata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/checkuser.json', 
		function(data){
			cudata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pcusr.js', 
		function(data){
			pcdata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pgmvr.js', 
		function(data){
			mvdata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/temop.js', 
		function(data){
			tpdata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/ptusr.js', 
		function(data){
			ptdata = data;
		}
	),
	$.getJSON(mw.config.get('wgScriptPath')+
	'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/interface-admin.json', 
		function(data){
			iadata = data;
		}
	),
	$.getJSON(
    	mw.config.get("wgScriptPath") +
    	"/index.php?action=raw&ctype=application/json&title=User:NovemBot/userlist.js",
    	function (data) {
        	bureaucratData = data.bureaucrat;
        	stewardData = data.steward;
        	adminData = data.sysop;
        	formerAdminData = data.formeradmin;
        	extendedConfirmedData = data.extendedconfirmed;
        	tenKData = data['10k'];
    	}
    )).then(function() {
	ADMINHIGHLIGHT_EXTLINKS = window.ADMINHIGHLIGHT_EXTLINKS || false;
	ADMINHIGHLIGHT_NAMESPACES = [-1,2,3];
	mw.loader.using(['mediawiki.util','mediawiki.Title'], function() {
		mw.util.addCSS("[class~=userhighlighter_excon] {background-color: #99f}");
		mw.util.addCSS("[class~=userhighlighter_pcusr] {background-color: #ddd}");
		mw.util.addCSS("[class~=userhighlighter_ptusr] {background-color: #9c9}");
		mw.util.addCSS("[class~=userhighlighter_pgmvr] {background-color: #bf9}");
		mw.util.addCSS("[class~=userhighlighter_temop] {background-color: #f9f}");
		mw.util.addCSS("[class~=userhighlighter_sysop] {background-color: #9ff}");
		mw.util.addCSS("[class~=userhighlighter_checkuser][class~=userhighlighter_sysop] {background-color: #9cf}");
		mw.util.addCSS("[class~=userhighlighter_oversight][class~=userhighlighter_sysop] {background-color: #999}");
		mw.util.addCSS("[class~=userhighlighter_arbcom][class~=userhighlighter_sysop] {background-color: #f99}");
		mw.util.addCSS("[class~=userhighlighter_interface-admin][class~=userhighlighter_sysop] {background-color: #ff9}");
		mw.util.addCSS("[class~=userhighlighter_bureaucrat][class~=userhighlighter_sysop] {background-color: #fb9}");
		mw.util.addCSS("[class~=userhighlighter_steward] {background-color: #9cc}");
		mw.util.addCSS("[class~=userhighlighter_jimbo][class~=userhighlighter_sysop] {background-color: #fd9}");
		$('#article a, #bodyContent a, #mw_contentholder a').each(function(index,linkraw){
			try {
				var link = $(linkraw);
				var url = link.attr('href');
				if (!url || url.charAt(0) === '#') return; // Skip <a> elements that aren't actually links; skip anchors
				if (url.lastIndexOf("http://", 0) !== 0 && url.lastIndexOf("https://", 0) !== 0 && url.lastIndexOf("/", 0) !== 0) return; //require http(s) links, avoid "javascript:..." etc.
				var uri = new URL(url);
				if (!ADMINHIGHLIGHT_EXTLINKS && uri.searchParams.size > 0) return; // Skip links with query strings if highlighting external links is disabled
				if (uri.host == 'en.wikipedia.org') {
					var mwtitle = new mw.Title(mw.util.getParamValue('title',url) || decodeURIComponent(uri.pathname.slice(6))); // Try to get the title parameter of URL; if not available, remove '/wiki/' and use that
					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/<username>"
						if (mwtitle.getNamespaceId() === -1) user = user.replace('Contribs/',''); // The Contribs abbreviation too
						
						if (stewardData[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_steward');
						}
						if(bureaucratData[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_bureaucrat');
						}
						if(iadata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_interface-admin');
						}
						if(acdata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_arbcom');
						}
						if(osdata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_oversight');
						}
						if(cudata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_checkuser');
						}
						if (adminData[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_sysop');
						}
						if(tpdata[user] == 1) {
							link.addClass(link.attr('class') + " userhighlighter_temop");
						}
						if(mvdata[user] == 1) {
							link.addClass(link.attr('class') + " userhighlighter_pgmvr");
						}
						if(ptdata[user] == 1) {
							link.addClass(link.attr('class') + " userhighlighter_ptusr");
						}
						if(pcdata[user] == 1) {
							link.addClass(link.attr('class') + " userhighlighter_pcusr");
						}
						if(extendedConfirmedData[user] == 1) {
							link.addClass(link.attr('class') + " userhighlighter_excon");
						}
						if(user == 'Jimbo Wales') {
							link.addClass(link.attr('class') + " userhighlighter_jimbo");
						}
					}
				}
			} catch (e) {
				// Sometimes we will run into unparsable links, so just log these and move on
				window.console && console.error('Admin highlighter recoverable error',e.message);
			}
		});
	});
	});
});
}(jQuery, mediaWiki));
//</nowiki>