knedle / PoGoBag pokemon bag filter

// ==UserScript==
// @name         PoGoBag pokemon bag filter
// @namespace    https://openuserjs.org/scripts/knedle/PoGoBag_pokemon_bag_filter
// @updateURL    https://openuserjs.org/meta/knedle/PoGoBag_pokemon_bag_filter.meta.js
// @version      0.2
// @description  Simple filter for trainers pokemons in bag 4 web PoGoBag.me
// @author       Ladislav "knedle" Sevcuj
// @copyright    2016, @3knedle
// @require      http://code.jquery.com/jquery-latest.js
// @include      *pogobag.me/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    $(document).ready(function(){
        var $mainDiv = $('.show-pokemon-container');
        var $a;
        var pokemonName;
        $('td.name', $mainDiv ).each(function(){
            pokemonName = $(this).text();
            $(this).attr('data-name', pokemonName);
            $a = $('<a/>');
            $a.html('[f]');
            $a.attr('title', 'filter');
            $a.attr('data-filter', pokemonName);
            $(this).append(' ');
            $(this).append($a);
        });
        
        $mainDiv.on('click', 'a[data-filter]', function(){
            var filterName = $(this).attr('data-filter');
            // hide all
            $("[ng-repeat='pokemon in pokemon']", $mainDiv).hide();
            // show only filter
            $('td.name[data-name="'+ filterName +'"]', $mainDiv ).each(function(){
                $(this).closest("[ng-repeat='pokemon in pokemon']").show();
            });            
            // add reset filter 
            var $resetDiv = $('<div/>');
            $resetDiv.append($('<button class="reset-filter"/>').text('RESET FILTER'));
            $resetDiv.append('POKEMON COUNT> '+$('td.name[data-name="'+ filterName +'"]', $mainDiv ).length);
            $mainDiv.append($resetDiv);
        });
        
        $mainDiv.on('click', 'button.reset-filter', function(){
            //show all
            $("[ng-repeat='pokemon in pokemon']", $mainDiv).show();
            //remove this reset div
            $(this).closest('div').remove();
        });
    });
})();