Archived Comments (locked)
|
|
The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008) |
|
|
Hey joe I improved my function:
$x=function() {
for (var i=0;i<arguments.length;i++) {
switch(typeof arguments[i]) {
case "string":var x=arguments[i];break;
case "number":var type=arguments[i];break;
case "object":var node=arguments[i];break;
}
}
return (!type) ? document.evaluate(x,(!node?document:node),null,9,null).singleNodeValue : document.evaluate(x,(!node?document:node),null,type,null)
};
It's overloaded and accepts arguments on type, not order. So Tell me if it works / needs more features please. Assumptions:
|
|
|
Thanks. but actually I have one...
// XPath by JoeSimmons
function xp(_exp, t, n) {
var exp = _exp || "//*"; // XPath Expression
var type = t || 6; // XPath type (e.g., 6=unordered node snapshot)
var node = n || document; // XPath search node (only for advanced users; research it)
return(type==9)?document.evaluate(exp, node, null, 9, null).singleNodeValue:document.evaluate(exp, node, null, type, null);
}
So if I want one result, I can just do xp("id('some_id')",9);
If I want text inside of the first link, I do xp(".//text()", 9, document.links[0]);
If I want all tags, I just do xp();
|
|
|
Joe, I made an overloaded XPath function, wanted to share it with you. Here it is:
$x=function(x,type) {
return (!type) ? document.evaluate(x,document,null,9,null).singleNodeValue : document.evaluate(x,document,null,type,null)
};
So if you want only the first result, don't supply the second part:
$x("//div[@class='header']")
or if you want all the results, just specify the type:
$x("//div[@id='footer']//a",7)
|
|
|
I want to do both. but I don't have much time lately. I will sometime. |
|
|
Yeah, instead of writing a greasemonkey script, you should just write the CSS for Stylish, then post it up on UserStyles. |
|
|
You should take a look at Stylish. ;) |
|
|
Seems nice! Thanks! |