Sort alphabetically

Sorts torrents alphabetically as an option

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Sort alphabetically
// @namespace   pxgamer
// @description Sorts torrents alphabetically as an option
// @include     *kat.cr/new/*
// @include     *kat.cr/movies/*
// @include     *kat.cr/games/*
// @include     *kat.cr/tv/*
// @include     *kat.cr/books/*
// @include     *kat.cr/applications/*
// @include     *kat.cr/music/*
// @include     *kat.cr/anime/*
// @include     *kat.cr/other/*
// @include     *kat.cr/xxx/*
// @include     *kat.cr/usearch/*
// @version     1.4
// @grant       none
// ==/UserScript==

var rows = [];
 
$('.data').before('<div class="buttonsline"><select disabled id="field-select" style="letter-spacing: 0px; width: 160px !important;"><option value="title">Sort by Torrent Name</option></select><select id="field-sort" style="letter-spacing: 0px; width: 150px !important;"><option value="asc">Ascending</option><option value="desc">Descending</option></select> <button class="siteButton bigButton" id="sortTable"><span>Sort</span></button></div>');
 
$(document).delegate('#sortTable', 'click', function() {
  var sortName = $('#field-select').val();
  var sortType = ($('#field-sort').val()=="asc");
  sortTable(sortName, sortType);
});
 
$('.data tr[id^="torrent_"]').each(function() {
  var title = $('.cellMainLink', $(this)).text();
  var html = $(this).html();
  rows.push({"title":title, "html":html});
});
 
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) { // Not sortType / is false
    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>');
  }

    }