AlternativeTo Enhancer

Make the AlternativeTo website even better!

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

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

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.

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

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         AlternativeTo Enhancer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Make the AlternativeTo website even better!
// @author       Al Boulley, [email protected]
// @match        https://alternativeto.net/software/*
// @grant        none
// ==/UserScript==

(function() {
    sortedItems = false;

    function sortAlternativesTo() {
        jQuery.fn.order = function(asc, fn) {
            fn = fn || function (el) {
                return $(el).text().replace(/^\s+|\s+$/g, '');
            };
            var T = asc !== false ? 1 : -1,
                F = asc !== false ? -1 : 1;
            this.sort(function (a, b) {
                a = fn(a);
                b = fn(b);
                if (a == b) return 0;
                return a < b ? F : T;
            });
            this.each(function (i) {
                this.parentNode.appendChild(this);
            });
        };

        if (!sortedItems) {
            listItems = $('#alternativeList li[id^="item-"]');
            listItems.order(false, function (el) {
                return parseInt($('.num', el).text());
            });
            sortedItems = true;
            statusComplete = '<li><h1 style="width:100%; background-color:#333; color:#3F3; padding:0.3em; font-size:3em; ';
            statusComplete += 'border:10px solid #3F3; text-align:center;">Alternatives Loaded &amp; Sorted!</h1></li>';
            listItems[0].insertAdjacentHTML('beforebegin', statusComplete);
        }
    }

    function initiateSort() {
        loadMore = $('#alternativeList button.btn-load-more');
        if (loadMore.length > 0) {
            loadMore.click();
            setTimeout(initiateSort, 4000);
        }
        setTimeout(sortAlternativesTo, 3000);
    }

    window.onload = initiateSort;
})();