# Javascript - reading/editing HTML with a grease monkey JS



## twilyth (Jun 9, 2011)

I want to read all of the html in a web page (probably into an array) and edit the page text and/or HTML tags like font or color.  My idea is to implement the script with grease monkey.

I did a quick scan of the references at w3schools.com for DOM, HTML and JS, but didn't see anything that seemed to fit.

I'm sure there's a way to do this and would appreciate any help or ideas.  thanks.


----------



## Zyon (Jun 9, 2011)

What is grease monkey? Is that a Javascript framework?

You could try using JQuery and run an Ajax for the page you need and then if the Ajax is successful, you retrieve the entire html as a data variable (raw html) and then all you need is a way to change it to array.

But PHP with Zend Framework would make it easier for you, I think, because you can create webpages using config files and then just change the attributes until you get it right, then output it.


----------



## stinger608 (Jun 9, 2011)

Hey Twilyth, if your using Firefox just right click anywhere on the page and go down to "view Page Source." This will open up a new page in HTML form. Now just select all and paste in what ever web editing program you wish.


----------



## Disparia (Jun 9, 2011)

From what I know, it's a Firefox plugin allowing you to apply js scripts to a website or multiple websites to alter layout, functionality, etc.

Ex: You really want to see everyone's System Specs without having to click on each one. So you'd study the source, figure out what to change, and then have the script apply it whenever you're browsing www.techpowerup.com/forums (so it doesn't mess with other sites).







Push those posts over, move the already generated system specs div next to their respective person 

Now, an active site-independent editor as I think the OP is suggesting is a lot bigger in scope. Not impossible, but quite a bit of work.


----------



## twilyth (Jun 10, 2011)

Jizzler said:


> From what I know, it's a Firefox plugin allowing you to apply js scripts to a website or multiple websites to alter layout, functionality, etc.
> 
> Ex: You really want to see everyone's System Specs without having to click on each one. So you'd study the source, figure out what to change, and then have the script apply it whenever you're browsing www.techpowerup.com/forums (so it doesn't mess with other sites).
> 
> ...


I'm not familiar with the mechanics of GM but I think you summed it up nicely.  The important point is that it is usually site specific.  You write the script, tell GM which site it applies to and load it to the GM plugin.  The script can reside anywhere.  There is a specific site GM uses but you can also run it off of your hard drive.

The GM part is probably complicated and the reason someone wrote a plug-in to do this in the first place.  But the second part is pretty simple, or at least should be.

For example, I can use the getElementsByTagName() method and read the contents of every tagged element into an array.  And now that I think about it, that might actually be adequate for certain things like changing the font or background color.

What I wanted to do though was read it as a text file, one line at a time, into an array.  But the more I think about it, I may have answered my own question.  Doing it this way won't give me the contents of any .js files referenced with the <script> tag, but that wasn't really part of the plan anyway - until now . . . . bwahahaha.

Seriously though, if someone also knows how to get the contents of every .js file into an array, that will probably be very useful for other GM debauchery.


----------

