Created
May 30, 2012 14:43
-
-
Save zeitounator/2836740 to your computer and use it in GitHub Desktop.
Greasemonkey script for ezdebug display in a box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Ez Debug Box | |
// @namespace EzDebugBox | |
// @description Remplace le debug par un bouton en haut à droite qui affiche une lightbox | |
// @include * | |
// ==/UserScript== | |
if (document.getElementById('debug')) { | |
var debugBoxVisible = false; | |
var cssDebugBox = "z-index:99; height: 80%; width : 80%; overflow : scroll; position : fixed; top : 0; margin : 10% auto auto 10%; border : 2px solid black; padding : 10px; background: white;"; | |
var lastKeyCode = false; | |
var count = 0; | |
var debug = document.getElementById('debug'); | |
debug.setAttribute('style', cssDebugBox + " display:none;"); | |
var body = document.getElementsByTagName('body')[0]; | |
var a = document.createElement('a'); | |
a.setAttribute('href', '#'); | |
if (document.getElementById('ezdebug-first-error')) { | |
a.setAttribute('style', 'color:#FF4F4F; text-decoration:none;'); | |
var spans = [], span = false; | |
var iterator = document.evaluate('//td[contains(@class,"debugheader")]//span[contains(text(), "Error")]', document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null); | |
while(span = iterator.iterateNext()) count++; | |
a.appendChild(document.createTextNode('Error ('+ count +')')); | |
} else if (document.getElementById('ezdebug-first-warning')) { | |
a.setAttribute('style', 'color:orange; text-decoration:none;'); | |
var spans = [], span = false; | |
var iterator = document.evaluate('//td[contains(@class,"debugheader")]//span[contains(text(), "Warning")]', document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null); | |
while(span = iterator.iterateNext()) count++; | |
a.appendChild(document.createTextNode('Warning ('+ count +')')); | |
} else { | |
a.setAttribute('style', 'color:#fff; text-decoration:none;'); | |
a.appendChild(document.createTextNode('Debug')); | |
} | |
var onClick = function () { | |
if (debugBoxVisible == false) { | |
debug.setAttribute('style', cssDebugBox + " display:block;"); | |
debug.focus(); | |
debugBoxVisible = true; | |
} else { | |
debug.setAttribute('style', cssDebugBox + " display:none;"); | |
debugBoxVisible = false; | |
} | |
return false; | |
} | |
var onKeyPress = function (e) { | |
var keyCode = (window.event) ? event.keyCode : e.keyCode; | |
// 18 = Alt | |
// 123 = F12 | |
if (lastKeyCode == 18 && keyCode == 123) { | |
onClick(); | |
} | |
lastKeyCode = keyCode; | |
} | |
if(window.addEventListener){ | |
a.addEventListener('click', onClick, false); | |
document.addEventListener('keydown', onKeyPress, false); | |
} else { | |
a.attachEvent('onclick', onClick); | |
document.attachEvent('onkeydown', onKeyPress); | |
} | |
var p = document.createElement('p'); | |
p.setAttribute('style', "position:fixed; right:0; z-index:99; top:0; color:#ccc; font-size:10px; font-weight:bold; font-family:verdana; background-color: rgba(95, 95, 95, 0.7); padding:0.5em 1em;"); | |
p.appendChild(a); | |
document.getElementsByTagName('body')[0].appendChild(p); | |
} | |
if (document.getElementById('ClassEditForm')) { | |
try { | |
var elements = document.evaluate('//th[contains(text(), "Nouvel attribut")]', document, null, XPathResult.ANY_TYPE, null); | |
var element = elements.iterateNext(); | |
setTimeout(function() { | |
window.scrollTo(0, element.offsetTop + 250); | |
element.style.border = "1px black solid"; | |
}, 200); | |
} | |
catch (e) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment