Skip to content

Instantly share code, notes, and snippets.

@shininglion
Forked from johnroyer/gist:8282741
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shininglion/f86bdf8bbb30d7a18cf8 to your computer and use it in GitHub Desktop.
Save shininglion/f86bdf8bbb30d7a18cf8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name railwayTicketFormAutoField
// @namespace http://railway.hinet.net/ctno1.htm
// @description Change some element on login page
// @include http://*railway.hinet.net/ctno1.htm
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
var personalId = 'A123456789'; // 身份正字號
var fromStation = '100'; // 台北
var toStation = '129'; // 台中港
var trainNo = '111'; // 車次
// 乘車日期、訂票張數需要手動改一下
// 填入身分證字號
$('input[name=person_id]').val(personalId);
// 選擇起站地點
$('select[name=from_station] option').prop('selected', false).filter('[value="'+ fromStation +'"]').prop('selected', true);
// 選擇到站地點
$('select[name=to_station] option').prop('selected', false).filter('[value="' + toStation + '"]').prop('selected', true);
// 選擇日期
$('select[name=getin_date] option').prop('selected', false).filter('[value^="2014/07/20"]').prop('selected', true);
// 填入車次
$('input[name=train_no]').val(trainNo);
// 一般無桌形座位車廂
$('select[name=order_qty_str] option').prop('selected', false).filter('[value="1"]').prop('selected', true);
// 有桌形座位車廂 (普悠瑪)
$('select[name=n_order_qty_str] option').prop('selected', false).filter('[value="1"]').prop('selected', true);
@johnroyer
Copy link

對方網站不一定會使用 jQuery,所以 user script 建議在前面多加一行,先載入 jQuery:

// @require    http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

@shininglion
Copy link
Author

已更新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment