views:

31

answers:

2

I need a tool that can parse and insert code to the JavaScript/HTML code before the browser starts to interpret the code. I've been thinking using a proxy to do it. But now I'd like to know whether I could implement such functionality in a Firefox plug-in?

+1  A: 

Sounds like Greasemonkey to me.

What does Greasemonkey do?

Greasemonkey lets you add JavaScript code (called "user scripts") to any web page, which will run when its HTML code has loaded. Compared to writing extensions, user scripts often offer a light-weight alternative, requiring no browser restart on user script installation nor removal, and work with the common DOM API familiar to any web developer (with somewhat elevated privileges for doing cross domain XMLHttpRequest requests and storing small portions of private data). User scripts work more or less like bookmarklets automatically invoked for any URLs matching one or more glob patterns.

http://wiki.greasespot.net/FAQ

Matt Ball
It *is* similar to Greasemonkey but different. GM adds a user-script at document.loaded, but what I need is before the document is loaded into the browser.
Paul
Why? What's wrong with transforming it after `document.ready`?
Matt Ball
@downvoter - any particular reason?
Matt Ball
" GM adds a user-script at document.loaded, but what I need is before the document is loaded into the browser"
Paul
I'm still curious to know why it has to be before the browser loads the document.
Matt Ball
I'd like to do some work on the top-level javascript code, which is executed before document.load.
Paul
+1  A: 

I'm pretty sure something like TemperData might work. Or maybe Fiddler, but that's an application with additional hooks that enable it to work with Firefox.

TemperData: https://addons.mozilla.org/en-US/firefox/addon/966/
Fiddler: http://www.fiddler2.com/fiddler2/

Of course both work on a network level, so they may be a bit more arcane than what you'd need.

Yi Jiang
I've not checked out TemperData but did check Fiddler. yes, Fiddler works for my need, but it's a proxy. I'd like to explore whether plugins could work.
Paul
@Paul: How did I forget Fiddler was a proxy... (knocks head)... Well then I'd say that almost everything you want would probably work somewhat like a proxy.
Yi Jiang
@Yi, What I need is indeed something like a proxy, but I'd like to implement it as a plugin. I just checked TamperData. It seems what I need... Do you have any personal experiences about it?
Paul
@Yi, TemperData doesn't work either because there's no hook of Firefox to add the script to manipulate what I need.As a conclusion, a proxy is the only way.
Paul