MediaWiki:Gadget-Tables.js

//

const ALTROW_MIN_ROWS = 5; // minimum number of data rows required in a table before alternating colors are enabled automatically

$(document).ready(function{	// Allows tables to have a horizontal scrollbar. See CSS.	// There doesn't seem to be a good way to achieve this by styling the table element itself	$('.wikitable:not(.infobox)').wrap(' ');	// Turn table rows with IDs into clickable links (excluding reference IDs)	// Gives readers a way to discover and share section links that aren't covered in the table of contents	$("tr[id]").click(function { window.location.hash = $(this).attr("id"); });	// Add alternating row colors to large tables in the mainspace which do not have rowspans (rowspans mess up the alternations)	$(".ns-0 .wikitable:not(.infobox):not(:has([rowspan]))").each(function { const rowCount = $(this).find("tr:has(td)").length; if (rowCount >= ALTROW_MIN_ROWS) { $(this).addClass("altrow"); }	}); });