Created
June 25, 2009 03:44
-
-
Save jackysee/135670 to your computer and use it in GitHub Desktop.
This file contains 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
var mtrStationsValue = { "sheung wan":26,"central":1,"admiralty":2,"wan chai":27, | |
"causeway bay":28,"tin hau":29,"fortress hill":30,"north point":31,"quarry bay":32,"tai koo":33, | |
"sai wan ho":34,"shau kei wan":35,"heng fa chuen":36,"chai wan":37,"shek kip mei":7,"kowloon tong":8, | |
"lok fu":9,"wong tai sin":10,"diamond hill":11,"choi hung":12,"kowloon bay":13,"ngau tau kok":14, | |
"kwun tong":15,"lam tin":38,"tsim sha tsui":3,"jordan":4,"yau ma tei":5,"mong kok":6,"prince edward":16, | |
"sham shui po":17,"cheung sha wan":18,"lai chi kok":19,"mei foo":20,"lai king":21,"kwai fong":22,"kwai hing":23, | |
"tai wo hau":24,"tsuen wan":25,"yau tong":48,"tiu keng leng":49,"tseung kwan o":50,"hang hau":51,"po lam":52, | |
"hong kong":39,"kowloon":40,"olympic":41,"nam cheong":53,"tsing yi":42,"tung chung":43,"sunny bay":54, | |
"disneyland resort":55,"east tsim sha tsui":80,"hung hom":64,"mong kok east":65,"kowloon tong":66,"tai wai":67, | |
"sha tin":68,"fo tan":69,"racecourse":70,"university":71,"tai po market":72,"tai wo":73,"fanling":74, | |
"sheung shui":75,"lok ma chau":78,"lo wu":76,"che kung temple":96,"sha tin wai":97,"city one":98,"shek mun":99, | |
"tai shui hang":100,"heng on":101,"ma on shan":102,"wu kai sha":103,"nam cheong":112,"mei foo":113, | |
"tsuen wan west":114,"kam sheung road":115,"yuen long":116,"long ping":117,"tin shui wai":118,"siu hong":119,"tuen mun":120}; | |
var mtrStations = []; | |
for(var i in mtrStationsValue){ | |
mtrStations.push(i); | |
} | |
var noun_type_mtr_station = new CmdUtils.NounType("mtr station", mtrStations) | |
CmdUtils.CreateCommand({ | |
name: "mtr-fare", | |
author: { name:"Jacky", email:"jackysee at gmail dot com"}, | |
takes: {"from mtr station": noun_type_mtr_station}, | |
modifiers: {to:noun_type_mtr_station}, | |
preview: function(p, from, m){ | |
if(from.text && m.to && m.to.text){ | |
var msg = "Getting fare from <i>${from}</i> to <i>${to}</li>... "; | |
p.innerHTML = CmdUtils.renderTemplate(msg, {from:from.text, to:m.to.text}); | |
var start = mtrStationsValue[from.text.toLowerCase()]; | |
var destin = mtrStationsValue[m.to.text.toLowerCase()]; | |
if(start == destin) return; | |
var url = "http://mtr.com.hk/jplanner/engtxt/planner_index.php"; | |
var params = {start:start, destin:destin}; | |
jQuery.get(url, params, function(data){ | |
var start = '<span class="subtitleRed">Standard Class Fare</span>'; | |
var end = '</table>'; | |
var data = data.substring(data.indexOf(start)); | |
var data = data.substring(data.indexOf("<table"),data.indexOf(end)+end.length); | |
p.innerHTML += data.replace("<table", "<table border='1' style='font-size:70%'"); | |
}) | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment