(function () {
var win = document.getElementById('mainFrame').contentWindow;
var tds = win.document.getElementsByTagName('td');
var mailids = [];
for (var i = 0; i < tds.length; i++) {
var td = tds[i];
if (td.getAttribute("hitmailid") == "") {
var mid = td.getAttribute("onclick").split(',')[1].split("'")[1];
mailids.push(mid);
}
}
var parms = win.location.search.split('&'), sid;
for (var i = 0; i < parms.length; i++) {
if (parms[i].indexOf("sid=") >= 0) {
sid = parms[i].split('=')[1];
break;
}
}
var printUrl = "//mail.qq.com/cgi-bin/readmail?sid=" + sid + "&t=readmail_print&s=print&filterflag=true&mailid=";
var outdata = [], en = 0;
for (var i = 0; i < mailids.length; i++) {
var url = printUrl + mailids[i];
fetch(url).then(res => res.blob()).then(blob => {
var reader = new FileReader();
reader.onload = function () {
en++;
if (reader.result.indexOf("cqhgrjb@163.com") >= 0) {
var obj = {};
reader.result.replace(/<span class="sub_title">.*?<\/td>/g, function (x) {
x.replace(/[1-9]\d*/, function (p) { obj.ymd = Number(p) });
});
var regempty=''
var alltxt = reader.result.replace(/<\/?.+?\/?>/g, '').replace(/\n/g, ' ').replace(/&nbsbp;/g, '');
obj.txt = alltxt.substring(alltxt.indexOf('今日完成'));
outdata.push(obj);
}
}
reader.readAsText(blob, 'GBK');
}).catch(function (e) {
console.error("fetch error");
console.error(e);
});
}
win.csi = setInterval(function () {
if (en < mailids.length) {
console.log('plan:' + mailids.length + " ,complete:" + en);
console.log(outdata);
} else {
outdata = outdata.sort(function (a, b) {
return a.ymd > b.ymd ? 1 : -1;
})
console.log(outdata);
console.log(JSON.stringify(outdata));
clearInterval(win.csi);
}
}, 1000);
})()