scrapclouds xpatho class
scrapclouds xpatho class
by ihope
HTML
<div id="xpathoDebug">hi xpatho</div>
<p class="plain">5555</p>
CSS
.hovered {
background : #EEEEFF;
outline : thin solid red;
border-radius : 3px;
}
JavaScript
function init(){
var t = (new Date).getTime();
var r = 0,
last = 0,
lastComputed = '',
lastXpath = '',
v,context;
xpath2css = function(s) {
return "*[title='" + s + "']" ;
}
function loadJS(src,context) {
var js = window.document.createElement('script');
js.src = src;
js.type = 'text/javascript';
js.context = context;
js.onload = function(e) {
console.log("file loaded:" + e.target.src);
eval(e.target.context);
};
document.getElementsByTagName('head')[0].appendChild(js);
};
//loadJS("http://code.jquery.com/jquery.min.js","jQuery.noConflect()");
/*loadJS("http://www.prototypejs.org/javascripts/prototype.js");*/
loadJS("http://svn.coderepos.org/share/lang/javascript/javascript-xpath/bindings/prototype/release/xpath4prototype-latest.js");
function log(s) { $x('/html/body/div[@id = "xpathoDebug"]').first().innerHTML = "<p>xpath: " + s + "</p>";}
var v = $$('*').each(function(v, i) {
var s = '';
r += 1;
v.ancestors().each(function(v2, i2) {
var ind = 1;
v2.previousSiblings().each(function(v3, i3) {
if (v3.nodeName == v2.nodeName) ind++;
});
s = v2.nodeName + '[' + ind + ']' + '/' + s;
});
var ind = 1;
v.previousSiblings().each(function(v4, i4) {
if (v4.nodeName == v.nodeName) ind++;
});
s = s + v.nodeName + '[' + ind + ']';
v.writeAttribute('title', s);
v.onmouseover = function(e) {
if (e.target.tagName != 'body' && lastXpath != e.target.title) {
if (last && last.style) {
last.className = (lastComputed);
}
lastComputed = last.className;
e.target.className = lastComputed + " hovered"
last = e.target;
}
};
v.onmouseup = function(e) {
//alert($$('#'));
log(e.target.title)
//document.write($$('#xpathoDebug'));// =...