' + document.getElementById("nav-user-action-bar").getElementsByClassName("list-inline")[0].innerHTML;
var script = '';
document.getElementById("mShowAlert").onclick = function () {
showDialog(script + '
用户名
总计体力
-
-
', 'info', '加体力统计', null, 1);
}
document.getElementById("hiddenDiv").onclick = function () {
var urlList = [];
var urlIdList = [];
var scoreList = {};
function startGetData() {
urlList = [];
urlIdList = [];
scoreList = {};
var txt = document.getElementById("text").value;
dealUrls(txt);
}
function dealUrls(urls) {
urls = urls.replace(/\r\n/g, "").replace(/\n/g, "");
var reg = new RegExp(/https:\/\/[^:]+\d/g);
var result;
while ((result = reg.exec(urls)) != null) {
urlList.push(result[0]);
}
dealUrlList(urlList, 0);
}
function dealUrlList(list, index) {
document.getElementById("progressTxt").innerHTML = "获取帖子信息中 " + (index + 1) + "/" + list.length;
if (index >= list.length) {
webRequest(urlIdList, 0);
return;
}
var reg = new RegExp(/tid=(\d+)&pid=(\d+)/g);
var result;
if ((result = reg.exec(list[index])) != null) {
urlIdList.push([result[1], result[2]]);
dealUrlList(list, index + 1);
} else {
webRequestSpecial(list, index);
}
}
function webRequest(list, index) {
document.getElementById("progressTxt").innerHTML = "获取体力数据中 " + (index + 1) + "/" + list.length;
if (index >= list.length) {
document.getElementById("progressTxt").innerHTML = "体力数据抓取完成";
setTable(scoreList);
return;
}
jQuery.post('https://steamcn.com/forum.php', {
mod: "misc",
action: "viewratings",
inajax: 1,
tid: list[index][0],
pid: list[index][1],
}).done(function (res) {
var txt = res.all[0].innerHTML;
var reg = new RegExp(/体力.+?\+(\d+?)[\s\S]+?suid-.+?">(.+?)<\/a/g);
var result;
while ((result = reg.exec(txt)) != null) {
if (scoreList[result[2]] == null) scoreList[result[2]] = 0;
scoreList[result[2]] += result[1] / 1;
}
webRequest(urlIdList, index + 1);
});
}
function webRequestSpecial(list, index) {
jQuery.post(list[index], {
inajax: 1
}).done(function (res) {
var txt = res.all[0].innerHTML;;
var mList = [];
var reg2 = new RegExp(/t\d+/g);
mList.push(reg2.exec(list[index])[0].replace("t", ""));
var reg = new RegExp(/post_\d+/g);
mList.push(reg.exec(txt)[0].replace("post_", ""));
urlIdList.push(mList);
dealUrlList(list, index + 1);
});
}
function setTable(list) {
var tbody = document.getElementById("container");
tbody.innerHTML = "";
var newlist = sortList(list);
for (var i in newlist) {
if (newlist[i][1] == undefined) continue;
tbody.innerHTML += "
" + newlist[i][0] + "
" + newlist[i][1] + "
";
}
}
function sortList(list) {
var tmpList = JSON.parse(JSON.stringify(list));
var newList = [];
var oriCount = 0
for (var i in tmpList) {
oriCount++;
}
while (newList.length <= oriCount) {
var max = ""
for (var i in tmpList) {
if (max == "") {
max = i;
}
if (tmpList[i] > tmpList[max]) {
max = i;
}
}
newList.push([max, tmpList[max]]);
delete tmpList[max];
}
console.log(newList);
return newList;
}
startGetData();
}
}
SetPage();
})();