How would I get the entire HTML contents into a JS variable?

Talk about add-ons and extension development.
Posts: 231
Joined: September 6th, 2004, 10:10 am
Location: Chicago

Post Posted September 12th, 2004, 7:44 pm

More specifically, I want to take an HTML file and using an overlay, remove all link stylesheets and add a different stylesheet to it. Either I can get the entire document contents in a string and use regex on that, or I could disable the other link's and add a new one, but I don't know how to do that. Any ideas?


User avatar
Posts: 100
Joined: July 31st, 2004, 8:50 am

Post Posted September 12th, 2004, 8:03 pm

well, you might find it easier to use DOM objects instead, but i'm not sure i know how to get the stylesheet nodes from the DOM right off..

Posts: 231
Joined: September 6th, 2004, 10:10 am
Location: Chicago

Post Posted September 12th, 2004, 8:05 pm

Well, I know there is a way to disable the link's from being used, but I don't know how to add a link stylesheet.

The Q
Posts: 359
Joined: November 14th, 2002, 7:53 am
Location: Sydney, Australia

Post Posted September 13th, 2004, 12:09 am

Have you tried a third party app like Proxomitron? It will allow you to rewrite any page as it comes in, to get rid of ads, or simply to change stylesheets to a more pleasing colour scheme for example. I also use mine to fix bugs in pages that work in IE but not in Firefox, by rewriting the bad commands (eg in Javascript) to ones that work in Firefox.

A good tagline for Proxomitron would be "Rewriting the web your way" because it's much more than just an ad killer.

See my sig for more info.
Get my current Proxomitron filters and Firefox CSS files here.

Rowne Mastaile

User avatar
Posts: 1434
Joined: December 21st, 2003, 3:05 pm
Location: Housed in a swirling neosma of scintillating thought and turgid ideas.

Post Posted September 13th, 2004, 5:48 am

Firefox already does all that, I think. The only thing it doesn't do is Javascript on a per-site basis. Though it can do Javascript globally [link].

As far as CSS is concerned, it does that too (userContent.css / userChrome.css) but to a better degree as one can control browser elements with CSS too.

Furthermore, I find Adblock [link] can easily match and even outdo most commercial blockers as it's able to deal with blocking iFrames, elements, javascript, frames, images, embeds and more.

I point this out because Proximitron is an almost dead project and Firefox does most of this anyway. As I said, the only thing it can't do is a by-site ruling for Javascripts but if it were requested, I'm sure it could be done easily.

Torisugari's bookmark-related extension (which I can't remember the name of right now) is clearly capable of snagging and comparing URIs so that could be lifted and built into an Adblock-like database.


User avatar
Posts: 531
Joined: December 7th, 2003, 2:50 pm
Location: Hertfordshire, England

Post Posted September 13th, 2004, 6:10 am

Fantastic as Adblock is, it's no match for Proxomitron. As Q said, Proxomitron isn't just a blocker, it's an editor - you can make any change you want to the incoming page before it reaches the browser (including fixing MIME-types etc. if the server is braindead). Development may have stopped, but it works perfectly as it is, so it's still alive and kicking.
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1
Thunderbird 1.0 (20041206)
EMbuttons: Buttons & options for the Extension Manager. Easy Get Mail Button is here too.

The Q
Posts: 359
Joined: November 14th, 2002, 7:53 am
Location: Sydney, Australia

Post Posted September 13th, 2004, 8:10 am

Not to hijack this thread too much, but as Moonwolf points out, whilst development on the program itself has stopped (the author died in May this year) the filter sets, which are the real power of Proxomitron, are continually being updated and worked upon. Here's the forum I frequent where developers and others can ask and answer questions and post new filters:

Proxomitron as an app is far from being dead - must there be continual upgrades to the program if it works as advertised and has zero problems on all current Windows OS's? If you are interested, grab 4.5j and my filter set and see just how far the filters have come from the default install.
Get my current Proxomitron filters and Firefox CSS files here.

Posts: 9
Joined: June 15th, 2004, 11:09 pm

Post Posted September 13th, 2004, 10:34 am

Thanks The Q (and folks) for the Proxomitron links and filters... While Adblock does a superb job of blocking most ads and is great for quick image blocking via context menu, Proxomitron is wonderful to run as well. They don't fight each other as much as you'd imagine, if at all. I've noticed Poxomitron with the right filters can not only get rid of annoying content, but also fix broken content and recode poorly coded pages so they'll display properly in Firefox.

What more could one ask for?
( Some type of Firefox context menu -> Proxo filter, that's what. :P ) - Anime, gaming, reviews, fan art.

Posts: 673
Joined: June 10th, 2003, 2:20 pm

Post Posted September 13th, 2004, 11:25 am

I came close to implementing this for Adblock, but ultimately didn't, since I couldn't determine a way to maintain backwards compatibility below moz1.4 -- I develop under 1.3.1
What I realized (during Window-Q dev.) was the http protocol handler could be replaced, saving the original, to allow an "in-browser proxy" which alters source on-the-fly. The replacement protocol would be loaded from the profile (as a runtime-registered component) and would simply intercept, change, and pass-on all input to the original handler.
I had the pieces for this model working, but stopped once it became clear older builds wouldn't be supported. If anyone wants to run with it, just hack on "windowQpopup-protocol.js": <a href="">linked</a>.

Posts: 3
Joined: September 14th, 2004, 7:55 pm

Post Posted September 15th, 2004, 10:15 am

Hopefully this code will be of some use to you:

var newsheet
var newstyle="element{property: value; property: value};
if (document.createStyleSheet) {
document.createStyleSheet("javascript:'" + newstyle + "'");
} else {

Specifically, this JS code maintains the existing stylesheet while replacing any elements specified in the newstyle variable.

This code must be called, and I'm not aware of any way to do it before the page is rendered, but it shouldn't be hard to run after the fact, even if that does seem like a bit of a hack.


Return to Extension Development

Who is online

Users browsing this forum: No registered users and 2 guests