Created
July 22, 2009 16:48
-
-
Save evansd/152130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript: (function() { | |
| var url = 'http://journeyplanner.tfl.gov.uk/user/XSLT_TRIP_REQUEST2'; | |
| var default_location = "MY_DEFAULT_LOCATION"; | |
| var input = '%s'; | |
| var matches = input.match(/(^\s*(.*)\s*>\s*(.*)\s*$|^\s*(.*)\s*<\s*(.*)\s*$)/); | |
| if( ! matches) { | |
| window.location = url; | |
| return; | |
| } | |
| var names = matches[2] != undefined ? [matches[2], matches[3]] : [matches[5], matches[4]]; | |
| var data = { | |
| 'place_origin': 'London', | |
| 'place_destination': 'London', | |
| 'language': 'en', | |
| 'execInst': '', | |
| 'sessionID': '0', | |
| 'ptOptionsActive': '-1' | |
| }; | |
| ['origin', 'destination'].forEach(function(pos, index) { | |
| data['name_'+pos] = (names[index] = names[index] || default_location); | |
| data['type_'+pos] = /[0-9]/.test(names[index]) ? 'locator' : 'stop'; | |
| }); | |
| var key, input, form = document.createElement('form'); | |
| form.method = 'post'; | |
| form.action = url; | |
| for(key in data) { | |
| input = document.createElement('input'); | |
| input.name = key; | |
| input.value = data[key]; | |
| input.type = 'hidden'; | |
| form.appendChild(input); | |
| } | |
| document.body.appendChild(form); | |
| form.submit(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment