// thetrainline autologin 1.0

// ==UserScript==
// @name           		theTrainline.com check tickets autologin
// @namespace      		http://www.norcimo.com/fun/greasemonkey
// @description    		Logs in automagically trainline.com when looking up tickets
// @include        		https://www.thetrainline.com/Buy_Tickets/Login/login.asp*
// ==/UserScript==

/*

Installation
============

You have two choices:
If you want to use the username and password as filled in by Firefox's built in password manager then leave the script as it is (you may have to change the value of delayTime to something bigger if you're on a slower computer--just experiment to get a working value)
If you haven't got Firefox remembering and filling those details then you can set the username and password in this script itself (as indicated below). In that case change preFill=true; to preFill=false;

*/

/*
 BEGIN LICENSE BLOCK
Copyright (C) 2005 Arvid Jakobsson

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You can download a copy of the GNU General Public License at
http://www.gnu.org/licenses/gpl.html
or get a free printed copy by writing to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
END LICENSE BLOCK */

var delayTime=1200; 
//Time to wait before submit (increase this if the form is submitting to quick for the autofiller to handle (the number is milliseconds to wait)

window.addEventListener('load',setTimeout(automagic,delayTime),true);


function automagic() {

// *******CHANGE if not using password manager filling*************

var preFill=true; //set to false to use the username & password set below
//NOTE! This holds a cleartext password!!! Caution!!!!
var USERNAME = ""; //Change this to your username (your email)
var PASSWORD = ""; //Change this to your password

// ****************************************************************

var loginform = document.getElementsByTagName("form")[0];
if (!loginform) {
	//GM_log("inloggad");
	return;
}
else {
	//GM_log("found loginform, logging in...");
}
var ourInputs=loginform.getElementsByTagName("input");
if (!preFill) {
ourInputs[0].value = USERNAME;
ourInputs[1].value = PASSWORD;
} 
ourInputs[2].click();
}
