Hi, I'm writing a greasemonkey script for a site I go on that will log in automatically. Also, the site doesn't go back to the page you were before once you logged in. It takes you to the homepage instead.

In my script I change the location back to where I was before, but when the script runs, it just keeps going back to window.location.href continuously, without stopping or letting the form submit.

Here's my code:
Code:
var nick = document.getElementsByName('form_nick')[0];
var pass = document.getElementsByName('form_pass')[0];
var form = document.getElementsByTagName('form')[0];
var url = window.location.href;

if (GM_getValue("autologin", 0) == 1)
{
  if (nick && pass) 
  {
    if (nick.value == "")
    {
      if (GM_getValue('username') != null)
      {
        nick.value = GM_getValue('username');
      }
    }
    if (pass.value == "") 
    {
      if (GM_getValue('password') != null)
      {
        pass.value = GM_getValue('password');
      }
    }
     if (nick.value != null && pass.value != null)
    { 
      if (form.action == "http://www.spogg.com/login/login.php");
      {
        if (url != "http://www.spogg.com/?logout=yes")
        {
          var preurl = window.location.href;
          form.submit();
          window.location.href = preurl;
        }
      }
    }
  }
}
Does anyone see any problems with my script? If so, how can I improve it?

Thanks in advance,
Jared