Sort Filelist

Sorts Filelist by size

Tính đến 27-09-2021. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Sort Filelist
// @namespace    Sort Filelist
// @version      0.2
// @description  Sorts Filelist by size
// @author       Conkuist
// @match        https://www.empornium.sx/*
// @match        https://www.empornium.is/torrents.php?id=*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const filelist_table = document.querySelector(`#content #details_top .torrent_table div[id^="files"] table tbody`);

    if(filelist_table)
    {

        const filelist_table_rows = filelist_table.querySelectorAll(`tr:not(.smallhead,.rowa)`);

        if(filelist_table_rows)
        {

            Array.from(filelist_table_rows).sort(function(a,b)
            {
                return GetSize(b) - GetSize(a);
            }
            ).forEach(function(e)
            {
                filelist_table.appendChild(e);
            }
            );

        }
    }

    function GetSize(e)
    {
        const cell = e.querySelector("td:last-child");

        if(cell)
        {
            const file_size = cell.innerHTML;
            return ParseSize(file_size);
        }

        return 0;
    }

    function ParseSize(string)
    {
        const parts = string.split(" ");

        if(parts.length > 1)
        {

            const number = parseFloat(parts[0]);

            if(isNaN(number))
            {
                return 0;
            }

            switch(parts[1])
            {
                case "KiB":
                    return number * Math.pow(1024,1);
                case "MiB":
                    return number * Math.pow(1024,2);
                case "GiB":
                    return number * Math.pow(1024,3);
                case "TiB":
                    return number * Math.pow(1024,4);
                default:
                    return number;
            }
        }
    }
})();