icotile sort lists alphabetically

Sorts IcoTile lists alphabetically.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name       icotile sort lists alphabetically
// @namespace  http://www.arthaey.com/
// @version    0.3
// @match      http://icotile.ogaoga.org/*
// @copyright  2013
//
// Backed up from http://userscripts.org/scripts/review/175007
// Last updated on 2013-08-04
// @description Sorts IcoTile lists alphabetically.
// ==/UserScript==

// Find all Twitter lists
var listRegex = /^list-/;
var lists = [];
var elements = document.getElementsByClassName("list-item");
for (var i = 0; i < elements.length; i++) {
    if (listRegex.test(elements[i].id)) {
        lists.push(elements[i]);
    }
}

// Sort lists by label
var sortedLists = lists.sort(function(a,b) {
    return a.getAttribute("label").localeCompare(b.getAttribute("label"));
});

// Reorder list elements alphabetically
for (var i = 0; i < sortedLists.length; i++) {
    var parent = sortedLists[i].parentNode;
    parent.removeChild(sortedLists[i]);
  parent.appendChild(sortedLists[i]);
}