// ==UserScript==
// @name BZOJ Helper
// @namespace bzoj
// @version 1.1
// @description BZOJ助手
// @author ranwen
// @match https://lydsy.com/*
// @match https://www.lydsy.com/*
// @license MIT
// ==/UserScript==
(function () {
function savedata(name, val) {
localStorage.setItem(name, JSON.stringify(val));
}
function readdata(name) {
return JSON.parse(localStorage.getItem(name))
}
var logined = 0
var username = "";
var mydb = Array();
var markedp = Array();
var fixurl = location.href;
if (fixurl.indexOf("www.lydsy.com") != -1) {
fixurl = fixurl.replace("www.lydsy.com", "lydsy.com");
location.href = fixurl;
}
function getmyusername() {
var sb = document.getElementsByTagName("table")[0].childNodes[1].childNodes[0].childNodes[17].innerText;
if (sb.indexOf("ModifyUser") == -1) {
logined = -1;
return;
}
username = sb.substr(13);
}
function isprob() {
if (fixurl.indexOf("https://lydsy.com/JudgeOnline/problem.php?id=") == -1) {
return -1;
}
return fixurl.substr(45);
}
function isstatus() {
if (fixurl.indexOf("https://lydsy.com/JudgeOnline/status.php") == -1) {
return -1;
}
return 0;
}
function islist() {
if (fixurl.indexOf("https://lydsy.com/JudgeOnline/problemset.php") == -1) {
return -1;
}
return 0;
}
function updateprobinfobypage(pid) {
sb = {};
for (i of document.getElementsByTagName("h2")[0].childNodes)
if (i.nodeName == "#text") {
sb["title"] = i.data.substr(6)
break
}
sb["submit"] = document.getElementsByTagName("center")[2].getElementsByClassName("green")[2].nextSibling.data;
sb["submit"] = sb["submit"].slice(0, -2);
sb["solved"] = document.getElementsByTagName("center")[2].getElementsByClassName("green")[3].nextSibling.data;
sb["source"] = document.getElementsByTagName("h2")[7].nextElementSibling.childNodes[0].innerText;
savedata("problem_" + pid, sb)
}
function updateprobinfobylist() {
for(i of document.getElementById("problemset").getElementsByTagName("tbody")[0].childNodes)
{
sb={}
prob=i.childNodes[1].innerText;
sb["title"]=i.childNodes[2].innerText;
sb["source"]=i.childNodes[3].innerText;
sb["solved"]=i.childNodes[4].innerText;
sb["submit"]=i.childNodes[5].innerText;
savedata("problem_" + prob, sb)
}
}
getmyusername()
markedp = readdata("marked");
if (markedp == null) {
savedata("marked", Array());
markedp = Array();
}
if (logined == -1) {
return;
}
function updateuserdb() {
var nm = fixurl.substr(48);
var list = document.getElementsByTagName("script")[2].innerHTML.match(/p\([1-9][0-9]{3}\)/g);
var rl = Array();
for (var i of list) {
rl.push(i.substr(2, 4))
}
savedata("userlist_" + nm, rl)
}
if (fixurl.indexOf("https://lydsy.com/JudgeOnline/userinfo.php?user=") != -1) {
updateuserdb();
}
mydb = readdata("userlist_" + username);
if (islist() != -1) {
updateprobinfobylist();
for(i of document.getElementById("problemset").getElementsByTagName("tbody")[0].childNodes)
{
prob=i.childNodes[1].innerText;
if(markedp.indexOf(prob)!=-1) i.childNodes[2].innerHTML=i.childNodes[2].innerHTML+"<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
<polygon points=\"19.510565162951536,6.9098300562505255 12.351141009169893,6.76393202250021 10,0 7.648858990830108,6.76393202250021 0.48943483704846535,6.9098300562505255 6.195773934819385,11.236067977499792 4.122147477075267,18.090169943749473 10,14 15.87785252292473,18.090169943749476 13.804226065180615,11.23606797749979\" style=\"fill:#FFFF00;\"></polygon>\
</svg>";
}
document.getElementById("problemset").getElementsByTagName("thead")[0].childNodes[1].childNodes[0].childNodes[0].innerHTML=document.getElementById("problemset").getElementsByTagName("thead")[0].childNodes[1].childNodes[0].childNodes[0].innerHTML+
"<a href=\"javascript:;\" id=\"showmarkedlist\">Marked Problem</a>";
document.getElementById("showmarkedlist").onclick = function () {
txt=""
for(i=0;i<markedp.length;i++)
{
o=markedp[i]
info=readdata("problem_"+o);
nr=""
nr+="<tr class=\""+((i&1)==0?"evenrow":"oddrow")+"\">";
nr+="<td>";
if(mydb.indexOf(o)!=-1) nr+="<span class=\"yes\">Y</span>";
nr+="</td>";
nr+="<td align=\"center\">";
nr+=o;
nr+="</td>";
nr+="<td align=\"left\">";
nr+="<a href=\"problem.php?id="+o+"\">"+info['title']+"</a>"+"<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
<polygon points=\"19.510565162951536,6.9098300562505255 12.351141009169893,6.76393202250021 10,0 7.648858990830108,6.76393202250021 0.48943483704846535,6.9098300562505255 6.195773934819385,11.236067977499792 4.122147477075267,18.090169943749473 10,14 15.87785252292473,18.090169943749476 13.804226065180615,11.23606797749979\" style=\"fill:#FFFF00;\"></polygon>\
</svg>";
nr+="</td>"
nr+="<td align=\"center\">";
nr+=info['source']
nr+="</td>";
nr+="<td align=\"center\">";
nr+="<a href=\"status.php?problem_id="+o+"&jresult=4\">"+info['solved']+"</a>";
nr+="</td>";
nr+="<td align=\"center\">";
nr+="<a href=\"status.php?problem_id="+o+"\">"+info['submit']+"</a>";
nr+="</td>";
nr+="</tr>";
txt+=nr;
}
document.getElementById("problemset").getElementsByTagName("tbody")[0].innerHTML=txt;
}
}
var prob = isprob();
if (prob != -1) {
updateprobinfobypage(prob)
if (mydb.indexOf(prob) != -1) {
var rdt = document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML;
var tdb = "<span style=\"color:#00FF00\">Y</span>" + rdt;
document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML = tdb;
}
var ttt = document.getElementsByTagName("center")[2].innerHTML;
var fff = ttt + "[<a href=\"https://lydsy.com/JudgeOnline/status.php?problem_id=" + prob + "&user_id=" + username + "\">My Status</a>]";
document.getElementsByTagName("center")[2].innerHTML = fff;
var rdt = document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML;
col = "#cccccc"
if (markedp.indexOf(prob) != -1) col = "#FFFF00";
var tdb = rdt +
"<a href=\"javascript:;\" id=\"chmr\"><svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
<polygon points=\"19.510565162951536,6.9098300562505255 12.351141009169893,6.76393202250021 10,0 7.648858990830108,6.76393202250021 0.48943483704846535,6.9098300562505255 6.195773934819385,11.236067977499792 4.122147477075267,18.090169943749473 10,14 15.87785252292473,18.090169943749476 13.804226065180615,11.23606797749979\" style=\"fill:"+ col + ";\"></polygon>\
</svg></a>";
document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML = tdb;
document.getElementById("chmr").onclick = function () {
if (markedp.indexOf(prob) != -1) {
//if (!window.confirm("确定鸽掉它?")) return; //取消标记提示
markedp.splice(markedp.indexOf(prob), 1)
document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].getElementsByTagName("a")[0].childNodes[0].childNodes[1].style.fill = "#cccccc"
}
else {
markedp.push(prob)
document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].getElementsByTagName("a")[0].childNodes[0].childNodes[1].style.fill = "#FFFF00"
}
markedp.sort()
savedata("marked", markedp)
}
}
if (isstatus() != -1) {
for (var i of document.getElementsByTagName("center")[0].getElementsByTagName("table")[2].getElementsByTagName("tbody")[0].childNodes) {
if (i.className != "evenrow" && i.className != "oddrow") continue;
prob = i.childNodes[2].childNodes[0].innerText;
mkd = ""
if (markedp.indexOf(prob) != -1)
mkd = "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
<polygon points=\"19.510565162951536,6.9098300562505255 12.351141009169893,6.76393202250021 10,0 7.648858990830108,6.76393202250021 0.48943483704846535,6.9098300562505255 6.195773934819385,11.236067977499792 4.122147477075267,18.090169943749473 10,14 15.87785252292473,18.090169943749476 13.804226065180615,11.23606797749979\" style=\"fill:#FFFF00;\"></polygon>\
</svg>"
if (mydb.indexOf(prob) != -1) {
i.childNodes[2].childNodes[0].innerHTML = "<span style=\"color:#00FF00\">Y</span>" + i.childNodes[2].childNodes[0].innerHTML + mkd;
}
else {
i.childNodes[2].childNodes[0].innerHTML = "<span style=\"color:#FF0000\">N</span>" + i.childNodes[2].childNodes[0].innerHTML + mkd;
}
}
}
document.getElementsByTagName("center")[0].childNodes[1].innerHTML += "<div class=\"tmp\" style=\"height:0px;width:0px;\"><img id=\"autofre\" src=\"data:image/png;base64,\" style=\"width:0px;height:0px;\"/></div>";
setInterval(function () { document.getElementById("autofre").src = "https://lydsy.com/JudgeOnline/" }, 600000);//自动续命
})();