Jump to content

User:Phlsph7/AlphabeticToolbox.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Phlsph7 (talk | contribs) at 16:20, 3 June 2024 (wait for other scripts to load). 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.
// sort the links in the toolbox alphabetically
$(document).ready(function() {
	setTimout(function(){
		const toolbox = document.getElementById('p-tb');
		const list = toolbox.getElementsByTagName('ul')[0];
		const items = Array.from(list.getElementsByTagName('li'));
		items.sort(function(a, b) {
			var textA = a.textContent.trim().toUpperCase();
			var textB = b.textContent.trim().toUpperCase();
			return textA.localeCompare(textB);
		});
	
		// Remove existing items and append sorted items
		while (list.firstChild) {
			list.removeChild(list.firstChild);
		}
		items.forEach(function(item) {
			list.appendChild(item);
		});
	}, 500);
});