NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Quick summary filters / vbaddict.net / World of Tanks
// @namespace http://twitter.com/3knedle
// @version 1.0
// @description Add filter to column 'map', 'tank' and 'result' to apply filter
// @author 3knedle
// @copyright 2015, @3knedle
// @match http://www.vbaddict.net/quick*
// @require http://code.jquery.com/jquery-latest.js
// @resource faCSS http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css
// ==/UserScript==
// add font awesome css - not working
//var faCSS = GM_getResourceText("faCSS");
//GM_addStyle(faCSS);
GM_addStyle(".fa {margin-left: 5px;}");
$searchIco = $(' <a href="#applyFilter" class="fa fa-search" title="filter this!"></a>');
$searchIco.text('[!]');
// to all page width
$('div.col-sm-9').removeClass().addClass('col-sm-12');
// add remove filter tag
var $removeFilterTag = $('<a href="#removeFilter" title="filter this!" class="label label-danger">(remove filter)</a>');
$('.panel-title').append($removeFilterTag);
$removeFilterTag.hide();
$.each($('tr', $('tbody')), function(i) {
// first 2 rows is summary - skip
if (i < 2) return true;
// select row
var $tr = $(this);
$tr.attr('data-apply-filter', 'on');
// map column
var $map = $(this).find(':nth-child(2)');
$map.attr('data-filtr', $map.text().trim());
$map.append($searchIco.clone());
// tank column
var $tank = $(this).find(':nth-child(3)');
$tank.attr('data-filtr', $tank.text().trim());
$('abbr', $tank).append($searchIco.clone());
// result column
var $result = $(this).find(':nth-child(4)');
$result.attr('data-filtr', $result.text().trim());
$('div', $result).append($searchIco.clone());
});
// apply filter
$( "a.fa" ).on( "click", function() {
var $a = $(this);
var $td = $a.closest('td');
$('tr[data-apply-filter]').each(function() {
$(this).hide(); // hide all row
if ($(this).has('td[data-filtr="'+$td.attr('data-filtr')+'"]').length) {
$(this).show(); // show row with apply filter data
}
});
$removeFilterTag.show();
});
// remove filter
$removeFilterTag.on('click', function () {
$('tr[data-apply-filter]').show();
$removeFilterTag.hide();
})