Sort Uploads Alphabetically

Sort user uploads alphabetically

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Sort Uploads Alphabetically
// @namespace    pxgamer
// @version      0.2
// @description  Sort user uploads alphabetically
// @author       pxgamer
// @include      *kat.cr/user/*/uploads/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var rows = [];

    $('tr.firstr th.width100perc.nopad').html(
        '<a class="sortAlpha">torrent name</a>'
    );

    $('.data tr[id^="torrent_"]').each(function() {
        var title = $('.cellMainLink', $(this)).text();
        var html = $(this).html();
        rows.push({"title":title, "html":html});
    });

    $('.sortAlpha').on('click', function() {
        var sortName = 'title';
        var sortType = 'desc';
        sortTable(sortName, sortType);
    });

    function sortByKey(array, key) {
        return array.sort(function(a, b) {
            var x = a[key];
            var y = b[key];
            if (typeof x == "string") {
                x = x.toLowerCase();
                y = y.toLowerCase();
            }
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
        });
    }

    function sortTable(sortName, sortType) {
        sortByKey(rows, sortName);
        if (!sortType) {
            rows.reverse();
        }
        $('.data tr[id^="torrent_"]').remove();
        for (var i=0;i<rows.length;i++) {
            $('.data').append('<tr id="torrent_'+i+'">'+rows[i].html+'</tr>');
        }

    }
})();