-
-
Save cers/81752 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CmdUtils.CreateCommand({ | |
name: "selector", | |
description: "Finds a selector that will match element currently hovered, and highlights all matches", | |
execute: function() { | |
CmdUtils.loadJQuery(function(){ | |
var d = CmdUtils.getDocumentInsecure(); | |
var w = CmdUtils.getWindowInsecure(); | |
myId = function(me){ return me.id ? '#' + me.id : '' } | |
myTag = function(me){ return me.tagName ? me.tagName.toLowerCase() : '' } | |
myClass = function(me){ return me.className ? '.' + me.className.split(' ').join('.') : '' } | |
breadcrumbs = function(me){ | |
var path = [myTag(me) + myId(me) + myClass(me)]; | |
w.jQuery(me).parents().each(function() { | |
path[path.length] = myTag(this) + myId(this) + myClass(this); | |
}); | |
path.reverse(); | |
return path.join(' > '); | |
} | |
var flasher = Components.classes["@mozilla.org/inspector/flasher;1"] | |
.getService(Components.interfaces.inIFlasher); | |
flasher.color = "#CC0000"; | |
flasher.thickness = 2; | |
flasher.invert = false; | |
var dirty = []; | |
w.jQuery("html *").each(function(){ | |
w.jQuery(this).mouseover(function(e){ | |
dirty.forEach(function(node) { | |
flasher.repaintElement(node); | |
}); | |
dirty = []; | |
var path = breadcrumbs(this); | |
var nodes = w.jQuery(path); | |
nodes.each(function() { | |
if(this.nodeType != Components.interfaces.nsIDOMNode.ELEMENT_NODE) | |
return; | |
if(this == this.ownerDocument.documentElement) | |
return; | |
flasher.drawElementOutline(this); | |
dirty.push(this); | |
}); | |
e.stopPropagation(); | |
}); | |
w.jQuery(this).mouseout(function(e){ | |
flasher.repaintElement(this); | |
}); | |
w.jQuery(this).click(function(e){ | |
displayMessage(breadcrumbs(this)); | |
e.stopPropagation(); | |
e.preventDefault(); | |
return false; | |
}); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment