Train Times Bookmarklets

A bookmarklet to easily access UK train times

Train Times Bookmarklet

For some explanation of how this bookmarklet came about please read this blog post (you can comment there too). For an explanation of what a bookmarklet actually is see the bookmarklet page. This whole thing got moved here when I wrote "version 2" of the train times bookmarklet.

Originally traintimes.org.uk's hackable URLs only dealt with trains for the current day. As Matthew comments there is now support for times in the future and return journeys. Furture, return! Oh well, what else have I got to do. Things I learnt: Javascript probably isn't my natural programming language—it's enough like C to confuse me is half the trouble—and parsing "nautral language" input like this is hard. I got the basics working and then kept adding bits again. Due to this and my laziness (and the fact I was learning as I went) the code is still hackish ;-)

The Bookmarklet

There are now two versions of the bookmarklet. The load page version simply loads the traintimes.org.uk page as you'd expect (by the way, alt+enter to open in a new tab does work). The Visit
Page

Close

%22;hDiv.innerHTML=biH;document.body.insertBefore(hDiv,document.body.firstChild);}}}function padZero(num){if (num<10) return %220%22+num;else return num.toString();}function quoted(points,start){points[start]=points[start].substr(1);var k=start+1;while (starttimes in a frame version I was inspired to write because quite often you may want to know the train times to some event your reading about on a web page…so it inserts a partially transparent br on top of the current page, fixed at the bottom (third of the available height) and loads the page in that (it has a close button and a link to the full page too, so it's now the version I use). To use either of these monsters you need to drag the appropriate link to your bookmark toolbar (or right click, Bookmark This Link…). You have to give it a keyword, which is sort of the whole point (look under the bookmark's properties) train is suggested (though I used tootoo ;-) ) Having set the keyword test it by entering a simple example in the location bar (eg train from newcastle to york) and hitting enter. You should get taken to www.traintimes.org.uk/newcastle/york/

Syntax and Notes

The syntax has been updated to support things other than today and return journeys. Old examples still work of course, the default is for the next available train today

In the syntax examples replace train with your chosen keyword, [start] with the starting station and [destination] with the destination station.

  • Basic: train from [start] to [destination]
  • With time: train from [start] to [destination] at [time]
  • Time (12 hour clock): eg train from [start] to [destination] at 7pm ; train from [start] to [destination] at 8:34 am (space is optional)
  • With date: train from [start] to [destination] on 25/11/2007 The year is optional, and can be in the form 2007 or 07. Single figure day and month can be written with or without a lead 0. Separation character can be / or - 2007-11-25 is also supported
  • With date (month name): train from [start] to [destination] on 25 November 2007. Again year is optional. You can use 3 letter month names instead (eg nov). You can do nov 25 as well
  • As Matthew supports things like Monday so does the bookmarklet (basically anything it can't parse it assumes to be the day and passes on). Also supported is next Day (or next-Day, nextDay next- Day). Also supported are today and tomorrow
  • Indicate the return portion by preceding with return (or ret or returning). If there's no ambiquity then that probably isn't necessary (i.e. train from [start] to [destination] at [dep time] on [dep date] at [ret time] on [ret date] should still work but you'll need return for things like train from [start] to [destination] today returning 10pm
  • Time (in the future): eg train from [start] to [destination] in 30 minutes ; train from [start] to [destination] in 1 hour ; train from [start] to [destination] in 2 hours 15 min. Weeks, months and years (!) too. These can be abbreviated to hrs, hr, h, etc (mnths, mnth, mns, mn for months, min, mins, m for minutes)
  • from, to, at and on are all optional, so train from [start] to [destination] at [time] on [date] is the same as train [start] [destination] [time] [date]. You can use @ rather than at
  • The timetables default to the next train anyway but you can tack "now" on the end for the sake of clarity, eg train from [start] to [destination] now
  • If your station has spaces in it's name (eg London Kings Cross) then enclose the name in quotes " (eg "london kings cross")---I actually forgot about this until the very end!
  • If the syntax more or less sounds right it will probably work, so you can always give it a try (and then be disappointed when I fail you!)
  • The code is hackish. I wrote it before Torchwood and finished the last bits after. I then hacked some more to deal with returns, future days etc. It's had no clean up etc and is very hackish
  • There is (almost) no error checking Feed it silly syntax or stupid stuff and it won't work (though this will probably only cause a javascript error, or try loading a non-nonsensical page, nothing bad)
  • This is only going to work in Firefox (or probably Seamonkey)

Remember this was just a proof of concept exercise I did for my own amusement! Thanks to Matthew for making the accessible timetables which make it possible (and those maps!), and I just wish National Railway, The Trainline and the train companies would get their acts together so buying a ticket online were as painless as it ought to be

More examples:

  • train from newcastle to york on tuesday returning 3pm wednesday
  • train Newcastle york today 10pm
  • train york newcastle 24/12 return 2 jan
  • train from Newcastle to york return tomorrow
  • train from newcastle to york at 10pm today
  • train newcastle to york return
  • train newcastle york now return tuesday
  • train from newcastle to york on 22 March 2007 @ 3 pm
  • train from newcastle to york in 3 hours
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.