Skip to content

Instantly share code, notes, and snippets.

@Geolim4
Last active April 27, 2017 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geolim4/a81502fa6c9fce4719395ee309d03eae to your computer and use it in GitHub Desktop.
Save Geolim4/a81502fa6c9fce4719395ee309d03eae to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Doctrine Time Threshold Filter
// @namespace Doctrine
// @version 1
// @grant none
// ==/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 { //Others
script.onload = function () {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", function () {
if(location.href.indexOf('_profile') > -1 && location.href.indexOf('panel=db') > -1){
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(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();
}
});
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment