Jump to content

User:Alex 21/script-tablecolour.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Alex 21 (talk | contribs) at 11:58, 8 September 2016. 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($) {
	var portletlink = mw.util.addPortletLink('p-tv', '#', 'Table colours', 't-tablecolour', '', '', '#t-tvepisoderatings');
	$(portletlink).click( function(e) {
		e.preventDefault();
		var loc = window.location.href; var wpTextbox1 = document.getElementById('wpTextbox1');
		if (loc.indexOf('action=edit') < 0 && loc.indexOf('action=submit') < 0) {
			alert("Go to the edit page to use this script.");
		} else {
			var s = wpTextbox1.value.split("\n");
			for (var i = 0; i < s.length; i++) {
				var reg = /\s*\|\s*(bgcolour|bgcolor|headercolour|headercolor|colour|color|fgcolour|fgcolor|background)[\s\=\#]*([0-9A-Za-z]*)/g;
				var t = reg.exec(s[i]);
				if (!t) continue;
				
				var fontColor = t[2];
				var newcolour = colourCompliance(fontColor,false);
				var reg2 = new RegExp('('+fontColor+')','gi');
				wpTextbox1.value = wpTextbox1.value.replace(reg2,newcolour);
			}
			document.getElementById('wpSummary').value += "Adjusted color contrasts via [[User:AlexTheWhovian/script-infoboxcolour|script]] per [[WP:COLOR]] and [[Template talk:Infobox television season/Archive 3]].";
			alert('Colours changed.');
		}
	});
});