/*
* @title ポイント履歴から、ポイント送信だけを抽出する
* @description http://www.hatena.ne.jp/my を開いた状態で実行する
* @include http://www.hatena.ne.jp/
* @license MIT License
* @require
*/
(function() {
var MAX_HISTORY = 2000;
var START_HISTORY = 0;
function $(id) {
return document.getElementById(id);
}
function nextElement(e) {
while (e) {
if (e.nodeType == 1) {
return e;
}
e = e.nextSibling;
}
return e;
}
function isNum(txt) {
return /^[0-9]+$/.test(txt);
}
var n = START_HISTORY;
var point_data = [];
function load_page(nn) {
var e = $('ff');
e.src = 'http://www.hatena.ne.jp/history?of=' + nn;
}
function do_extract_data() {
document.body.innerHTML =
"<table border='1' id='all'><tr><th>日付</th><th>支払</th><th>受取</th><th>明細</th><th>残額</th><tbody id='tb'></tbody></table>" +
"<iframe id='ff' style='position:absolute; right:0; top:0; width:30%; height:90%;'></iframe>";
var e = $('ff');
e.onload = pickup_data;
load_page(n);
}
function pickup_data() {
var RE_1 = /^ポイント送信/;
var RE_2 = /手数料/;
function is_point_trade(a) {
return RE_1.test(a[3]) && ! RE_2.test(a[3]);
}
var ee = this.contentWindow.document.getElementsByTagName('table');
var tr_list = ee[0].getElementsByTagName('tr');
for (var i = 1 ; i < tr_list.length ; ++i) {
var aa = [];
var td = nextElement(tr_list[i].firstChild);
while (td) {
var txt = td.innerHTML;
if (td.firstChild.nodeType == 1) { // <b> ?
txt = nextElement(td.firstChild).innerHTML;
}
aa.push(txt);
td = nextElement(td.nextSibling);
}
if (! is_point_trade(aa)) {
continue;
}
var diff = aa[2];
if (isNum(aa[1])) {
diff = "-" + aa[1];
}
var result = aa[4].substring(1);
point_data.push( aa );
}
if (n < MAX_HISTORY && tr_list.length > 1) {
n += 20;
load_page(n);
} else {
display_data();
}
}
function display_data() {
// append HTML
var dest = $('tb');
for (var i in point_data) {
var a = point_data[i];
var xx = document.createElement("tr");
xx.innerHTML = "<td>" + a.join("</td><td>") + "</td>";
dest.appendChild(xx);
}
}
do_extract_data();
})();