Filter Ideabox

Sort ideabox ideas by different methods

01.06.2016 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Filter Ideabox
// @namespace    PXgamer
// @version      0.2
// @description  Sort ideabox ideas by different methods
// @author       PXgamer
// @include      *kat.cr/ideabox/*
// @grant        none
// ==/UserScript==
/*jshint multistr: true */

(function() {
    'use strict';

    $('.buttonsline.floatleft').append('<select id="sortIdeas-select" style="letter-spacing: 0px; width: 220px !important;"><option value="all">Show all</option><option value="az">Sort Alphabetically (A-Z)</option><option value="no">Sort by Age (Newest to Oldest)</option><option value="views">Sort by Views (High to Low)</option></select> <button class="siteButton bigButton" id="sortIdeas"><span>Sort</span></button>');

    $('.ideaBox').each(function(){
        var html  = $(this).html();
        var title = $('.ideaBody h3 span', $(this)).text();
        var age   = $('.ideaBody div.greyText', $(this)).split('</span>')[7];
        var views = $('.ideaBody div.greyText', $(this)).split('</span>')[3];
        rows.push({"title":title,"age":age,"views":views,"html":html});
    });

    $('#sortIdeas').on('click', function() {
        var ideaSortType = $('#sortIdeas-select').val();

        switch (ideaSortType) {
            case 'all':
                $('div.ideaBox').show();
                break;
            case 'az':    // Sort alphabetically (A-Z)
                $('div.ideaBox').show();
                sortIdeas('title', 'desc');
                break;
            case 'no':    // Sort by age (Newest to Oldest)
                $('div.ideaBox').show();
                sortIdeas('age', 'desc');
                break;
            case 'views': // Sort by views (High to Low)
                $('div.ideaBox').show();
                sortIdeas('views', 'desc');
                break;
            default:
                $('div.ideaBox').show();
                break;
        }
    });

    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 sortIdeas(sortName, sortType) {
        sortByKey(rows, sortName);
        //rows.reverse();
        $('div.ideaBox').remove();
        for (var i=0;i<rows.length;i++) {
            $('.buttonsline.floatleft').after('<div class="ideaBox" id="idea_'+i+'">'+rows[i].html+'</div>');
        }

    }
})();