Skip to content

Instantly share code, notes, and snippets.

@johnroyer
Created January 6, 2014 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnroyer/8282741 to your computer and use it in GitHub Desktop.
Save johnroyer/8282741 to your computer and use it in GitHub Desktop.
for Tampermonkey
// ==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