I'm going to walk you through a process I went through earlier this week to begin familiarizing yourself with Greasemonkey development, as well as the process to look at a site you are modifying and determine what steps you want your script to take.
Step 1 - Define success criteria
The first step of any programming project is to figure out what you want to do. This may seem unnecessary, but deciding beforehand the success criteria for any project ensures that you are working towards something you want to achieve, it can help push you forward with motivation during the work because you are focused on the effect you want to bring about, and it is essential to stop yourself from getting sidetracked during development. One of the top problems for any software development process is scope creep, and we want to avoid this here.
In this case, the script I was looking at writing involved achieving a higher point count on a facebook game. This higher point count enabled the player to do more things. The specific game I was looking at was called Hatchery. The idea for the script came about when I watched a friend play the game and I noticed that there was a really easy but monotonous way to get points by visiting the Requests page of the game, clicking on each of the players that requested you pet their egg, and for each player clicking on "Pet this egg". I don't play the game, so the Hatchery-specific terminology I use here may be mistaken. I only looked at it from the perspective of solving the problem.
Step 2 - Develop a plan
Step 3 - Implement your plan, and test
A lot of people consider implementation and testing to be separate things. This is a flawed way of looking at things because typically there is an iterative process between the two. For the best programmers I have seen, the iterations are so small that there is really no way to differentiate between development and testing.
For the hatchery, I created the button by finding an element on the page I could replace with my buttons and message boxes. On Facebook there is an advertisement in the right column which seemed perfect. I created the button and hooked up my new button with a function that was called when the button was clicked.
Inside the function for my new button, I googled for some greasemonkey code. By looking at two or three other scripts out there I found that Greasemonkey has its own AJAX utilities, so I decided to use them. I decided on AJAX because I wanted the user interaction with my script to be minimal, but I needed to pull several URLs.
I used regular expressions to scan the current page for all of the URLs in the list. I would need to pull all of these URLs to get the IDs of the players I was going to scan. I iterated over the list making AJAX calls for each, and then processed each of those pages looking for the ID of that person's pet. I then constructed a new URL and made another AJAX call to instruct the game that I had now pet the egg with this new ID.
Step 4 - Looking at further improvements
At the end of step three, I had a completed working Greasemonkey script, and my friend was happy. I didn't necessarily stop there though. I started thinking, "what could be done to make this script better?". In this case, the answer was that I could use local storage to look at when I last pulled the data, and then automatically run the script whenever the user is logged into facebook. I analyzed this and realized it wasn't worth the time yet