Website Styler

By JoeSimmons Last update Nov 20, 2008 — Installed 2,986 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 8 posts, 5 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
Avindra V.G. Scriptwright

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 $x(".//text()", document.links[0]) or $x(document.links[0],".//text()") would work.

Tell me if it works / needs more features please.

Assumptions:

  1. That if the Result Type isn't supplied, you want to get the first result.
  2. That if the Node isn't supplied, it will be checked against the document.

 
JoeSimmons Script's Author

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();

 
Avindra V.G. Scriptwright

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)

 
JoeSimmons Script's Author

I want to do both. but I don't have much time lately. I will sometime.

 
Avindra V.G. Scriptwright

Yeah, instead of writing a greasemonkey script, you should just write the CSS for Stylish, then post it up on UserStyles.

 
Sebastian Pa... Scriptwright

You should take a look at Stylish. ;)

 
nathaniel_hi... Scriptwright

Seems nice! Thanks!

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel