IRCSort

Sort IRCCloud channel lists

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        IRCSort
// @namespace   KWIERSO
// @description Sort IRCCloud channel lists
// @include     https://irccloud.mozilla.com/*
// @version     1
// @grant       GM_registerMenuCommand
// ==/UserScript==


var channelPriorities = {
  "#developers": 0,
  "#jetpack": 1,
  "#ateam": 2,
  "#releng": 3,
  "#buildduty": 4,
  "#taskcluster": 5,
  "#treeherder": 6,
  "#vcs": 7,
  "#b2g": 8,
  "#gaia": 9,
  "#devtools": 10,
  "#jsapi": 11,
  "#fx-team": 12,
  "#media": 13,
  "#mobile": 14,
  "#it": 15,
  "#moc": 16
};

var getChannelPriority = function(channelName) {
  var thispriority = channelPriorities[channelName];
  if(thispriority === undefined) {
    thispriority = 5555;
  }
  return thispriority;
};

var sortChannelFunction = function(a,b) {
  return a[1] - b[1];
};

var sortChannels = function() {
  var bufferList = document.querySelector("#bufferList").firstElementChild.querySelector(".buffers");
  var bufferListChildren = bufferList.querySelectorAll("li.buffer");
  var channelList = [];
  var newChannelList = [];

  for(var i=0; i < bufferListChildren.length; i++) {
    var thisEl = bufferList.firstElementChild;
    channelList.push([bufferList.removeChild(thisEl), getChannelPriority(thisEl.textContent.replace("☂",""))]);
  }


  channelList = channelList.sort(function(a,b) {
    return a[1] - b[1];
  });

  for(var j=0; j < channelList.length; j++) {
    bufferList.appendChild(channelList[j][0]);
  }
};



GM_registerMenuCommand("Sort channel list", sortChannels);