MyspaceMozilla





MyspaceMozilla 0.9 Beta - Coding MySpaceMozilla

How to Code your own custom modules for MySpaceMozilla

Like Ive said previously, if you have any knowledge of GreaseMonkey scripts, you will find creating an MSM script quite easy. Unlike GM scripts though, MSM scripts are held in one file on your C drive. This file is called msmscript.js.

So first things first, go into your main C drive (at the root level) and create a folder called 'myspacemozilla', now inside that folder create a file called msmscript.js (for now just leave it blank).

Now you should have a file and folder structure set up like so: file:///C:/myspacemozilla/msmscript.js

Creating your first script

Ok, open up the msmscript.js file in Notepad, or whatever other editor you feel comfortable with. It should be blank at this stage. Now start by entering the following:

function MSM_initial(){

}

You have now created an empty function for MSM to use. This is important, because everytime you go onto a new webpage, MSM will call this function and execute anything within this function. This is why its important you do call it MSM_initial, otherwise MSM wont find the function and thus not be able to execute your code.

OK now we've got this far, lets do something simple like changing all the links on MySpace Forum pages so that they are RED.

Within the MSM_initial function type the following:

if(window.content.location.href.match(/forum\.myspace\.com./))

{

var msmStyleThis="";

msmStyleThis+="<style>a {color:red!important;}</style>";

content.document.body.innerHTML = msmStyleThis + content.document.body.innerHTML;

}

Woah! For those of you not that familiar with coding, that may look like a whole lot of gobbledy-gook! But if we break it down bit by bit, it suddenly doesnt seem so scary.

if(window.content.location.href.match(/forum\.myspace\.com./))

This line is simply saying if the URL matches 'forum.myspace.com' then perform the following command. The \ before the . within forum\.myspace\.com is simply saying treat the fullstops as literally a fullstop. I won't go into the ins and outs of regular expressions, but in laymans terms, anytime you see a forward slash (\) in this context, its saying 'treat the next character after me (in this case the fullstop) as literally that character and no other character'.

Right, next 2 lines:

var msmStyleThis="";
msmStyleThis+="a {color:red!important;}";


The first of these lines just sets up a new variable called msmStyleThis. The following line then says take msmStyleThis and add the following to it:

<style>a {color:red!important;}</style>

So now msmStyleThis contains the line above, which is simply saying that all links on the page (the a) should be coloured red.

Now for the final line .......

content.document.body.innerHTML = msmStyleThis + content.document.body.innerHTML;

Get all the content within the Body Tag, and tack the contents of msmStyleThis to the front of it.

That's it! You are done!

Your msmscript.js file should now look like this:
Click here

However a better way to accomplish the same thing is like so:
Click here

In this example, we have created a whole new function, and then made a call to that function from within the MSM_initial() function. This keeps everything in a nice, neat order and if you end up with 5 or more different scripts, it can get extremely messy if you try to fit everything within just the one function.

Now close down your Firefox browser and restart it (Important Note: Whenever you make changes to msmscript.js, you will need to kickstart your browser again as the script is only called once when the browser is started so subsequent changes arent registered).

Navigate your way to the forum page and take a look. You should now see the links in a red color! If you do, everything worked fine. If not, something went wrong, so have a look at the steps again.

Important: This example was provided to give you a simple taster of how to create a script for MSM. If you are interested in doing anything more complicated, or having multiple MSM scripts running at the same time, please check out our advanced code section. This illustrates a better way to handle multiple scripts so that they are easier to maintain.


Using multiple scripts/functions

If you intend to use a variety of scripts/functions or intend to create your own, read on. In the above example, we put everything into the MSM_initial function. However imagine you had 10 different scripts floating about in there. Pretty messy huh?

So - What you should ideally do is create your very own function for each script and then make the call for that function inside the MSM_initial function. Using the above example, I shall demonstrate what I mean:

What you see below is exactly what the finished msmscript.js file will look like if you just have the above example in it.

function MSM_initial(){

MSM_stylethis();

}

function MSM_stylethis(){

if(window.content.location.href.match(/forum\.myspace\.com./))

{

var msmStyleThis="";

msmStyleThis+="<style>a {color:red!important;}</style>";

content.document.body.innerHTML = msmStyleThis + content.document.body.innerHTML;

}

}







If you require any more help please contact me on Myspace at www.myspace.com/myspacemozilla

Cheers,

Dave





Midi