Skip to content

Instantly share code, notes, and snippets.

@s25g5d4
Created January 16, 2018 16:07
Show Gist options
  • Save s25g5d4/bb0f378a95f5097fe14d1965dc0424ac to your computer and use it in GitHub Desktop.
Save s25g5d4/bb0f378a95f5097fe14d1965dc0424ac to your computer and use it in GitHub Desktop.
高鐵搶票自動填入ㄏㄏ
// ==UserScript==
// @name THSR Ticket
// @namespace Violentmonkey Scripts
// @include https://irs.thsrc.com.tw/IMINT
// @include https://irs.thsrc.com.tw/IMINT/*
// @run-at document-idle
// @grant none
// @version 1.0
// ==/UserScript==
//
const start = '起程(台北)';
const dest = '到達(台南)';
const date = '日期(2018/02/14)';
const trainNum = '<車次(673)>';
const amount = <票數(1)>;
const id = '<身份證字號(A123456789)>';
const mobile = '<電話(0912345678)>';
const email = '<email(user@example.com)>';
if (!document.getElementById('idNumber')) {
Array.from(document.querySelectorAll('[name="selectStartStation"] option')).find(e => e.textContent === start).selected = true;
Array.from(document.querySelectorAll('[name="selectDestinationStation"] option')).find(e => e.textContent === dest).selected = true;
document.querySelector('#bookingMethod2').click();
document.querySelector('#toTimeInputField').value = date;
document.querySelector('input[name="toTrainIDInputField"]').value = trainNum;
document.querySelector('select[name="ticketPanel:rows:0:ticketAmount"]').selectedIndex = amount;
document.querySelector('input[name="homeCaptcha:securityCode"]').focus();
}
else {
document.querySelector('#idNumber').value = id;
document.querySelector('#mobileInputRadio').click();
document.querySelector('#mobilePhone').value = mobile;
document.querySelector('input[name="email"]').value = email;
document.querySelector('#memberSystemCheckBox').click();
document.querySelector('#memberSystemRadio1').click();
document.querySelector('#msNumber').value = id;
document.querySelector('input[name="agree"]').click();
window.scrollTo(0, document.querySelector('#isSubmit').getBoundingClientRect().y - 200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment