icotile sort lists alphabetically

Sorts IcoTile lists alphabetically.

  1. // ==UserScript==
  2. // @name icotile sort lists alphabetically
  3. // @namespace http://www.arthaey.com/
  4. // @version 0.3
  5. // @match http://icotile.ogaoga.org/*
  6. // @copyright 2013
  7. //
  8. // Backed up from http://userscripts.org/scripts/review/175007
  9. // Last updated on 2013-08-04
  10. // @description Sorts IcoTile lists alphabetically.
  11. // ==/UserScript==
  12.  
  13. // Find all Twitter lists
  14. var listRegex = /^list-/;
  15. var lists = [];
  16. var elements = document.getElementsByClassName("list-item");
  17. for (var i = 0; i < elements.length; i++) {
  18. if (listRegex.test(elements[i].id)) {
  19. lists.push(elements[i]);
  20. }
  21. }
  22.  
  23. // Sort lists by label
  24. var sortedLists = lists.sort(function(a,b) {
  25. return a.getAttribute("label").localeCompare(b.getAttribute("label"));
  26. });
  27.  
  28. // Reorder list elements alphabetically
  29. for (var i = 0; i < sortedLists.length; i++) {
  30. var parent = sortedLists[i].parentNode;
  31. parent.removeChild(sortedLists[i]);
  32. parent.appendChild(sortedLists[i]);
  33. }