/* 更新时间:2019-03-29 使用方法:打开QQ邮箱,选择【已发送】界面,打开浏览器控制台(或按F12),拷贝脚本粘贴回车(按Enter) */ (function () { var win = document.getElementById('mainFrame').contentWindow; var tds = win.document.getElementsByTagName('td'); //邮件ID 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); } } //获取sid 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(/.*?<\/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); })()