-
-
Save cers/105536 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() { | |
var d = CmdUtils.getDocumentInsecure(); | |
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 breadcrumbs(me){ | |
var path = [myTag(me) + myId(me) + myClass(me)]; | |
jQuery(me,d).parents().each(function() { | |
path[path.length] = myTag(this) + myId(this) + myClass(this); | |
}); | |
path.reverse(); | |
return path.join(' > ').replace(/.ubiquityHighlight/g,""); | |
} | |
var timer = -1; | |
function ubiquityHighlightPath(path) { | |
CmdUtils.log("ubiquityHighlight("+path+")"); | |
jQuery("body .ubiquityHighlight",d).removeClass("ubiquityHighlight"); | |
jQuery(path,d).addClass("ubiquityHighlight"); | |
} | |
if (!d.getElementById("ubiquityCss")) | |
jQuery('head',d).append('<style id="ubiquityCss" type="text/css">.ubiquityHighlight {outline: 1px blue solid !important;}</style>'); | |
jQuery("body *",d).each(function ubiquityHighlight(){ | |
jQuery(this).mouseover(function ubiquityHighlightMouseOver(e){ | |
var path = breadcrumbs(this); | |
if (timer > 0) | |
Utils.clearTimeout(timer); | |
timer = Utils.setTimeout(function delayedHighlight(){ubiquityHighlightPath(path);}, 10); | |
e.stopPropagation(); | |
}); | |
jQuery(this).mouseout(function ubiquityHighlightMouseOut(e){ | |
jQuery("body .ubiquityHighlight",d).removeClass("ubiquityHighlight"); | |
}); | |
jQuery(this).click(function ubiquityHighlightClick(e){ | |
var path = breadcrumbs(this); | |
CmdUtils.copyToClipboard(path); | |
displayMessage(path); | |
e.stopPropagation(); | |
e.preventDefault(); | |
jQuery("body *",d).unbind("mouseover").unbind("mouseout").unbind("click"); | |
return false; | |
}); | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment