IRCSort

Sort IRCCloud channel lists

  1. // ==UserScript==
  2. // @name IRCSort
  3. // @namespace KWIERSO
  4. // @description Sort IRCCloud channel lists
  5. // @include https://irccloud.mozilla.com/*
  6. // @version 1
  7. // @grant GM_registerMenuCommand
  8. // ==/UserScript==
  9.  
  10.  
  11. var channelPriorities = {
  12. "#developers": 0,
  13. "#jetpack": 1,
  14. "#ateam": 2,
  15. "#releng": 3,
  16. "#buildduty": 4,
  17. "#taskcluster": 5,
  18. "#treeherder": 6,
  19. "#vcs": 7,
  20. "#b2g": 8,
  21. "#gaia": 9,
  22. "#devtools": 10,
  23. "#jsapi": 11,
  24. "#fx-team": 12,
  25. "#media": 13,
  26. "#mobile": 14,
  27. "#it": 15,
  28. "#moc": 16
  29. };
  30.  
  31. var getChannelPriority = function(channelName) {
  32. var thispriority = channelPriorities[channelName];
  33. if(thispriority === undefined) {
  34. thispriority = 5555;
  35. }
  36. return thispriority;
  37. };
  38.  
  39. var sortChannelFunction = function(a,b) {
  40. return a[1] - b[1];
  41. };
  42.  
  43. var sortChannels = function() {
  44. var bufferList = document.querySelector("#bufferList").firstElementChild.querySelector(".buffers");
  45. var bufferListChildren = bufferList.querySelectorAll("li.buffer");
  46. var channelList = [];
  47. var newChannelList = [];
  48.  
  49. for(var i=0; i < bufferListChildren.length; i++) {
  50. var thisEl = bufferList.firstElementChild;
  51. channelList.push([bufferList.removeChild(thisEl), getChannelPriority(thisEl.textContent.replace("☂",""))]);
  52. }
  53.  
  54.  
  55. channelList = channelList.sort(function(a,b) {
  56. return a[1] - b[1];
  57. });
  58.  
  59. for(var j=0; j < channelList.length; j++) {
  60. bufferList.appendChild(channelList[j][0]);
  61. }
  62. };
  63.  
  64.  
  65.  
  66. GM_registerMenuCommand("Sort channel list", sortChannels);