Jump to content

User:Jeeputer/highlightPiped.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jeeputer (talk | contribs) at 15:26, 27 August 2023 (exclude links inside reflist). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(function () {
	if (mw.config.get('wgNamespaceNumber') > 0 ) {return} //Only on main namespace
	var links = $('#mw-content-text a');
	for (var i = 0; i < links.length; i++) {
	    var link = $(links[i]);
        var linkText = link.text(),
            linkTitle = link.attr('title');
	    var color = window.pipeHighlighterCustomColor || '#B3446C';
	    // Check if link is piped
	    if (
	    	link.parents('div.reflist').length ||
	    	linkTitle == undefined ||
	    	linkText === linkTitle ||
	    	(linkTitle !== undefined && linkText === linkTitle.toLocaleLowerCase())
			) {
	    	// Not piped, so continue the loop
	        continue;
		} else {
			// Piped, so check if it's a redirect or disambiguation link
	        if (link.hasClass('mw-redirect') && link.css('color') === 'rgb(0, 102, 0)') {
	        	// Is a colored redirect link, so prepend a colored pipe
	            link.prepend('<span style="color: ' + color + '; font-weight: bold">|</span>');
	        } else if (link.hasClass('mw-disambig') && link.css('color') === 'rgb(241, 118, 0)') {
	        	// Is a colored disambig link, so prepend a pipe
	            link.prepend('<span style="color: ' + color + '; font-weight: bold">|</span>');
	        } else {
	        	// Is not a redirect nor a disambig link,
	        	// Or is a redirect or a disambig link without a custom color
	        	// This is intended for compatibility with other link highlighing scripts/gadgets
	            link.css('color', color);
	        }
	        
	    }
	}
});