need some help with alternate css

in Script development
Subscribe to need some help with alternate css 9 posts, 3 voices



haden Scriptwright
FirefoxWindows

I live in Dubai, U.A.E and my ISP (Etisalat) has blocked the the site hosting deviantart' stylesheets and javascripts .. ie.(http://st.deviantart.net/). I thought i'd create a greasmonkey script that will point to the js/css hosted on my servers.. Im no good with javascript.. Can anyone help me out with writing the code for replacing the location of the stylesheet? or even whereever http://st.deviantart.net occurs change to http://myserver.com

 
haden Scriptwright
FirefoxWindows

I figured out how to do a find and replace.. How do you load the entire HTML contents of a page as a text string?

 
JoeSimmons Scriptwright
FirefoxWindows

haden wrote:
How do you load the entire HTML contents of a page as a text string?
document.body.innerHTML
 
Avindra V.G. Scriptwright
FirefoxWindows

Replacing the href's:

var hrefs = document.evaluate("//*[starts-with(@href, 'http://st.deviantart.net')", document, null, 6, null), href;
for(var i = hrefs.snapshotLength - 1; i>=0; --i) {
	href = hrefs.snapshotItem(i);
	href.href = "http://myserver.com" + href.href.substring(24);
}

 
JoeSimmons Scriptwright
FirefoxWindows

Avindra Gool... wrote:
for(var i = hrefs.snapshotLength - 1; i>=0; --i) {
href = hrefs.snapshotItem(i);
Bro, do this instead, no comparing to 0 and it's shorter:
for(var i=0,item; (item=array.snapshotItem(i)); i++) {
// use item.href
}
 
haden Scriptwright
FirefoxWindows

Thanks guys. That worked out..

 
haden Scriptwright
FirefoxWindows

Hi guys.. Ive tried out your code.. It works for css/js links to.. But i need to replace deviantart.net to deviant.com where it occurs on the entire page.. That includes inside javascript code, img links etc..
(And also i figured i can access the resources by changing deviantart.net to deviantart.com eg..
http://sh.deviantart.net/shadow/x/150/88/logo3.png to http://sh.deviantart.com/shadow/x/150/88/logo3.png

 
JoeSimmons Scriptwright
FirefoxWindows

haden wrote:
Hi guys.. Ive tried out your code.. It works for css/js links to.. But i need to replace deviantart.net to deviant.com where it occurs on the entire page.. That includes inside javascript code, img links etc..

(And also i figured i can access the resources by changing deviantart.net to deviantart.com eg..

http://sh.deviantart.net/shadow/x/150/88/logo3.png to http://sh.deviantart.com/shadow/x/150/88/logo3.png
var array=document.evaluate("//a[contains(@href, 'deviantart.net')]",document,null,6,null);
for(var i=0,item; (item=array.snapshotItem(i)); i++) item.href=item.href.replace("deviantart.net", "deviantart.com");
 
haden Scriptwright
FirefoxWindows

I forgot to mention that i had to change the src of images. Anyway i figured it out.. I got the script working. Thanks guys..

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