User:VahurzpuBot/paidhighlighter.js

// /** * Paid highlighter 1.0 * - * * A very close adaptation of User:Pythoncoder/Scripts/userHighlighter.js to * highlight editors with paid editing disclosures * * @author theopolisme * @author Bellezzasolo * @author Amorymeltzer * @author Pythoncoder * @author Vahurzpu */ (function($, mw){ mw.hook('wikipage.content').add(function{ var paidlist; $.when(	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:VahurzpuBot/Disclosed_paid_editor_list', function(data){ paidlist = data; })).then(function {	PAIDHIGHLIGHT_EXTLINKS = window.PAIDHIGHLIGHT_EXTLINKS || false;	PAIDHIGHLIGHT_NAMESPACES = [-1,2,3];	mw.loader.using(['mediawiki.util','mediawiki.Uri', 'mediawiki.Title'], function { mw.util.addCSS("[class~=paidhighlighter_paid] {background-color: #f0f}"); $('#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  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. which mw.Uri does not support				var uri = new mw.Uri(url);				if (!PAIDHIGHLIGHT_EXTLINKS && !$.isEmptyObject(uri.query)) 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.path.slice(6))); // Try to get the title parameter of URL; if not available, remove '/wiki/' and use that					if ($.inArray(mwtitle.getNamespaceId, PAIDHIGHLIGHT_NAMESPACES)>=0) { var user = mwtitle.getMain.replace(/_/g," "); if (mwtitle.getNamespaceId === -1) user = user.replace('Contributions/',''); // For special page "Contributions/ " if (mwtitle.getNamespaceId === -1) user = user.replace('Contribs/',''); // The Contribs abbreviation too if (paidlist.indexOf(user) >= 0) { link.addClass(link.attr('class') + ' paidhighlighter_paid'); }					}				}			} catch (e) { // Sometimes we will run into unparsable links, so just log these and move on				window.console && console.error('Paid highlighter recoverable error',e.message); }		});	});	}); }); }(jQuery, mediaWiki)); //