CustomsForge min songs filter

Add minimum songs filter to CustomsForge artist search

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         CustomsForge min songs filter
// @license      WTFPL; http://www.wtfpl.net/
// @namespace    http://ttmyller.azurewebsites.net/
// @version      0.1
// @description  Add minimum songs filter to CustomsForge artist search
// @author       Teemu Myller
// @match        http://ignition.customsforge.com/search/artists
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var minSongs = $('<span>Min songs: &nbsp; <select id="minSongs" /> &nbsp; </span>');
    var select = $('#minSongs', minSongs);
    for (var i=1; i<=50; i++) {
        $('<option value="' + i + '">' + i + '</option>').appendTo(select);
    }
    select.change(function() { hideArtistsWithSongsLessThan(this.value); });
    $('nav', '#content-header-artists').prepend(minSongs);
})();

function hideArtistsWithSongsLessThan(count) {
    if (count < 1) {
        $('a', '#artists-column').show();
    } else {
        var regex = /\((\d+)\)/;
        $('a', '#artists-column').each(function() {
            var item = $(this);
            var songs = parseInt(item.text().match(regex)[1]);
            if (songs < count) {
                item.hide();
            } else {
                item.show();
            }
        });
    }
}