+2  A: 

Do you have a custom "getElementsByClass" function? DOM doesn't have a getElementsByClass method. Perhaps you were trying to borrow code from somewhere else and didn't realise this?

There are plenty of getElementsByClass methods available on the internet

Perchik
+1  A: 

+1 to Perchik, if you don't provide the definition of the functions you use, plus the html it's supposed to run on, we can't really help you to check your code.

Anyway, I still see two things you can change. The first one is to initialize your arrays as arrays, and not as empty objects. You can't use the push method if your variable is not an array:

var tagHolder = new Array();
var availJobs = new Array();

The second one is to use jQuery or any other javascript library that can make your life easier. In GreaseMonkey, you can use @require :

// ==UserScript==
// @name           Script Name
// @namespace      namespace
// @include        http://www.website.net/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
// ==/UserScript==

The @required scripts are retrieved when you add your script to GreaseMonkey: if you want to use that, you'll have to remove your script and reload it. GreaseMonkey will then keep a local copy of the @required scripts and load them when needed.

With jQuery, your code would then look like that:

var jobs = {};

jobs.scan = function() {
    var tagHolder = new Array();
    var availJobs = new Array();
    $("#app8743457343_content b").each(function() {
        tagHolder.push(this);
        if ($(this).attr("color") == "silver")
            availJobs.push($(this).text());
    });
    return alert(availJobs[0]);
}

jobs.scan();
ybo
IC, I didn't know that I can't use the push method if I didn't use the new Array() constructor. But isn't this an array too? var array = {}?Hey the required part is cool! I didn't even know that exist. TY
Richard Kevins
+1  A: 

+1 for ybo, your answer was spot on given the information available. I had a quick look at the relevant markup from the Mob Wars page, and it looks like this:

<div id="app8743457343_content" fbcontext="db6ca1f1773e">
 ...
   <b style="font-size: 15px; color: silver;">Mugging</b>
 ...

I modified your solution based on the actual markup to:

// ==UserScript==
// @name          Mob Wars Job List
// @namespace     namespace
// @description   Script to summarise available Mob Wars jobs.
// @include       http://apps.facebook.com/mobwars/jobs/
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==

$(document).ready(function() {
var jobs = {};
jobs.scan = function() {
    var availJobs = new Array();
    $("#app8743457343_content b").each(function() {
        if ($(this).css("color") == "silver")
            availJobs.push($(this).text());
    });
    return alert("Available jobs:\n" + availJobs.join('\n'));
}
jobs.scan();
});
Amal Sirisena