NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Doctrine Time Threshold Filter // @namespace Doctrine // @version 1.0.3 // @grant none // @author Georges.L // ==/UserScript== (function () { function loadScript(url, callback) { var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState) { //IE script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } }; } else { script.onload = function () { callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); } if(location.href.indexOf('_profile') > -1 && location.href.indexOf('panel=db') > -1){ loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", function () { console.log('Symfony Doctrine profiler detected, adding custom filters...'); if($('table.queries-table').length){ $('<div id="queries-filter-wrapper">').insertBefore('table.queries-table'); $('<label for="queries-filter">Time threshold: </label>').appendTo('#queries-filter-wrapper'); $('<select id="queries-filter">').appendTo('#queries-filter-wrapper'); var _NO_SCALE_ = '---', timeScales = [_NO_SCALE_, 2, 5, 10, 25, 50, 100, 250, 500, 750, 1000, 2000, 5000, 10000]; for(var key in timeScales){ var matchingItem = 0; $('table.queries-table tbody tr').each(function(index){ if(parseFloat($(this).find('td:eq(1)').text()) >= timeScales[key]){ matchingItem++; } }); if(timeScales[key] !== _NO_SCALE_){ $('#queries-filter').append('<option value="' + timeScales[key] + '">' + timeScales[key] + ' ms (' + matchingItem + ')</option>'); }else{ $('#queries-filter').append('<option value="' + timeScales[key] + '">' + timeScales[key] + '</option>'); } } $('#queries-filter').on('change', function(){ if($('#queries-filter').val() !== _NO_SCALE_){ console.log('Filter set on' + $('#queries-filter').val() + ' ms'); $('table.queries-table tbody tr').each(function(index){ if(parseFloat($(this).find('td:eq(1)').text()) < $('#queries-filter').val()){ $(this).hide(); }else{ $(this).show(); } }); }else{ $('table.queries-table tbody tr').show(); } }); } }); } })();