$(document).ready(function() { function customFilter(heading, filter, text) { var filtergroup = $('#changelist-filter h3:contains("'+ heading +'")').next('ul'); qs = window.location.search; // if we're already filtering by a sibling (that isn't "All") if (filtergroup.children('li:first').siblings().is('.selected')) { // remove sibling querystring from custom filter querystring var filterBase = filter.substr(0, filter.indexOf('_')); var siblingQs = qs.substr(qs.indexOf(filterBase), qs.indexOf('&', qs.indexOf(filterBase))); if (!siblingQs) { siblingQs = qs.slice(qs.indexOf(filterBase), qs.length); } qs = qs.replace(siblingQs, ''); qs = qs + '&' + filter; } else { // no current filters, make new if (!qs || qs == '?') { qs = '?' + filter; // already filtering by custom filter, ignore } else if (qs.match(filter)) { qs = qs; // current filters, append } else { qs = qs + '&' + filter; } } filtergroup.append('