Created
January 6, 2014 13:15
-
-
Save johnroyer/8282741 to your computer and use it in GitHub Desktop.
for Tampermonkey
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
// ==UserScript== | |
// @name railwayTicketFormAutoField | |
// @namespace http://railway.hinet.net/ctno1.htm | |
// @description Change some element on login page | |
// @include http://*railway.hinet.net/ctno1.htm | |
// ==/UserScript== | |
var personalId = 'A123456789'; // 身份正字號 | |
var fromStation = '100'; // 台北 | |
var toStation = '129'; // 台中港 | |
var trainNo = '111'; // 車次 | |
// 乘車日期、訂票張數需要手動改一下 | |
var form = document.forms['ctno1']; | |
form['person_id'].value = personalId; | |
var selection = document.getElementsByName('from_station')[0]; | |
for(var index in selection.options){ | |
if(selection.options[index].value == fromStation){ | |
selection.options[index].setAttribute('selected'); | |
} | |
} | |
var selection = document.getElementsByName('to_station')[0]; | |
for(var index in selection.options){ | |
if(selection.options[index].value == toStation){ | |
selection.options[index].setAttribute('selected'); | |
} | |
} | |
var selection = document.getElementsByName('getin_date')[0]; | |
for(var index in selection.options){ | |
var val = '' + selection.options[index].value; | |
if( val != undefined ){ | |
console.log(val); | |
if( val.match(/2014\/01\/18/) ){ // 日期 | |
console.log(val); | |
selection.options[index].setAttribute('selected'); | |
} | |
} | |
} | |
form['train_no'].value = trainNo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment