Skip to content

Instantly share code, notes, and snippets.

@Coldblackice
Forked from antimatter15/xpath.js
Created April 13, 2023 18:41
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 Coldblackice/3c5d16cd9492eab0c1d28d7c53a18adb to your computer and use it in GitHub Desktop.
Save Coldblackice/3c5d16cd9492eab0c1d28d7c53a18adb to your computer and use it in GitHub Desktop.
javascript:(function(){
//inspired by http://userscripts.org/scripts/show/8924
var s = document.createElement('script');
s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js');
if(typeof jQuery=='undefined') document.getElementsByTagName('head')[0].appendChild(s);
(function() {
if(typeof jQuery=='undefined') setTimeout(arguments.callee, 100)
else{
jQuery("*").one("click",function(event){
//http://snippets.dzone.com/posts/show/4349
jQuery(this)[0].scrollIntoView();
for(var path = '', elt = jQuery(this)[0]; elt && elt.nodeType==1; elt=elt.parentNode){
var idx = jQuery(elt.parentNode).children(elt.tagName).index(elt)+1;
idx>1 ? (idx='['+idx+']') : (idx='');
path='/'+elt.tagName.toLowerCase()+idx+path;
}
window.location.hash = "#xpath:"+path
event.preventDefault()
event.stopPropagation()
jQuery("*").unbind("click",arguments.callee);
})
}
})();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment