antimatter15 (owner)

Revisions

  • c0b36f Sun Nov 01 13:45:42 -0800 2009
  • 9bc3ce Sun Nov 01 12:48:47 -0800 2009
gist: 223708 Download_button fork
public
Public Clone URL: git://gist.github.com/223708.git
Embed All Files: show embed
xpath.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
      })
    }
  })();
})()