お勤めの人は会社で交通費の精算をやると思うんですね。
モバイル Suica を利用してるとネットでも JR東日本:モバイルSuica>会員メニュー 履歴を見られて便利なんですが、各乗車の運賃が出ないでその降車時の残額しか出ないのがいただけない。
ということで、SF利用履歴のページの表の部分をコピペするだけで運賃算出してくれる Google ガジェットを作ってみました。
ポイントと仕様
- 各項目のスペースは全角、区切りは半角なのでパースは楽。
- この手のツールは対象の出力のしかたが変わってしまうと動かなくなるから寿命が短いかも。
- 先頭の列定義の行があっても無視するようにした。
- キヨスク等での買い物分は出力し、チャージ分は出さないようにしている。
- 変換ボタンを押さなくても、テキストエリアからフォーカスが移ったときにコンバートするようにしている(textarea の onchange の動きがイマイチだったため)。
Content のソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| <script type="text/javascript"> <!-- String.prototype.trim = function() { return this.replace(/^\\s+|\\s+$/g, ''); }; String.prototype.getLines = function() { var lines = this.split("\\n"); for (var i=lines.length-1; i>=0; i--) { if (lines\[i\].trim().length == 0) { lines.splice(i, 1); } } return lines; }; function line2map(line) { var c = line.split(' '); if (c\[1\] == "物販") c\[2\] = c\[1\]; return { date: c\[0\], dept:c\[2\], arrv:c\[4\], acc: c\[5\].substr(1).replace(',',"") }; } function outtable(input) { try { var lines = input.getLines(); if (lines\[0\].indexOf('月/日') \> -1) lines.shift(); var i = lines.length - 1; var pre_acc = line2map(lines\[i\]).acc; var out = ""; while (--i >= 0) { if (lines\[i\].replace(' ',"").length == 0) continue; var item = line2map(lines\[i\]); if (item.dept.length > 0) { out += "<tr><td>" \+ item.date \+ "</td><td>" \+ item.dept + "</td><td>" out += item.arrv + "</td><td>" \+ (pre_acc - item.acc) \+ "</tr>"; } pre_acc = item.acc; } return '<table cellspacing="0" style="font-size:10.5pt" width="300">' \+ out + '</table>'; } catch(err) { return null; } } function chg(evt) { var textIn = document.getElementById('textIn'); var ret = outtable(textIn.value); if (ret != null) document.getElementById('textOut').innerHTML = ret; } function firstFocus(obj) { obj.value=''; obj.style.color='#000'; obj.onfocus = null; }
</script> <div id="content_div" style="border-bottom:2px solid #474;padding-top;3px;"> <table style="width:100%;" cellspacing="0"> <tr> <td><textarea id="textIn" style="float:left;color:gray;font-size:10pt;width:100%;height:75px" onfocus="firstFocus(this)" onchange="chg()" >SF(電子マネー)利用履歴をペースト</textarea></td> <td width="40"><button style="float:left;width:40px;height:75px;" onclick="chg()">変換</button></td> </tr> </table> <div id="textOut" style="border-top:2px solid #474;margin-top:3px;padding-top;3px;clear:left;height:108px;overflow:scroll"></div> </div>
|
tilfin
freelance software engineer