BZOJ Helper

BZOJ助手

当前为 2018-09-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name BZOJ Helper
  3. // @namespace bzoj
  4. // @version 1.2
  5. // @description BZOJ助手
  6. // @author ranwen
  7. // @match https://lydsy.com/*
  8. // @match https://www.lydsy.com/*
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. function savedata(name, val) {
  14. localStorage.setItem(name, JSON.stringify(val));
  15. }
  16. function readdata(name) {
  17. return JSON.parse(localStorage.getItem(name))
  18. }
  19. var poly_star = "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
  20. <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>\
  21. </svg>";
  22. var logined = 0
  23. var username = "";
  24. var mydb = Array();
  25. var markedp = Array();
  26. var fixurl = location.href;
  27. if (fixurl.indexOf("www.lydsy.com") != -1) {
  28. fixurl = fixurl.replace("www.lydsy.com", "lydsy.com");
  29. location.href = fixurl;
  30. }
  31. function getmyusername() {
  32. for (i of document.getElementsByTagName("table")[0].childNodes[1].childNodes[0].childNodes)
  33. if (typeof (i.innerText) != "undefined" && i.innerText.indexOf("ModifyUser") != -1) {
  34. username = i.innerText.substr(12);
  35. username = username.replace(" ", "");
  36. return;
  37. }
  38. logined = -1;
  39. }
  40. function isprob() {
  41. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/problem.php?id=") == -1) {
  42. return -1;
  43. }
  44. return fixurl.substr(45);
  45. }
  46. function isstatus() {
  47. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/status.php") == -1) {
  48. return -1;
  49. }
  50. return 0;
  51. }
  52. function islist() {
  53. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/problemset.php") == -1) {
  54. return -1;
  55. }
  56. return 0;
  57. }
  58. function updateprobinfobypage(pid) {
  59. sb = {};
  60. for (i of document.getElementsByTagName("h2")[0].childNodes)
  61. if (i.nodeName == "#text") {
  62. sb["title"] = i.data.substr(6)
  63. break
  64. }
  65. sb["submit"] = document.getElementsByTagName("center")[2].getElementsByClassName("green")[2].nextSibling.data;
  66. sb["submit"] = sb["submit"].slice(0, -2);
  67. sb["solved"] = document.getElementsByTagName("center")[2].getElementsByClassName("green")[3].nextSibling.data;
  68. sb["source"] = document.getElementsByTagName("h2")[7].nextElementSibling.childNodes[0].innerText;
  69. savedata("problem_" + pid, sb)
  70. }
  71. function updateprobinfobylist() {
  72. for (i of document.getElementById("problemset").getElementsByTagName("tbody")[0].childNodes) {
  73. sb = {}
  74. prob = i.childNodes[1].innerText;
  75. sb["title"] = i.childNodes[2].innerText;
  76. sb["source"] = i.childNodes[3].innerText;
  77. sb["solved"] = i.childNodes[4].innerText;
  78. sb["submit"] = i.childNodes[5].innerText;
  79. savedata("problem_" + prob, sb)
  80. }
  81. }
  82. function getradioval(name) {
  83. for (i of document.getElementsByName(name)) {
  84. if (i.checked) {
  85. return i.value;
  86. }
  87. }
  88. }
  89. function setdefaultconfig()
  90. {
  91. def={"unmarkalert":"0"};
  92. for(i in def)
  93. {
  94. if(typeof(config[i])=="undefined")
  95. config[i]=def[i];
  96. }
  97. savedata("config",config);
  98. }
  99. getmyusername()
  100. markedp = readdata("marked");
  101. if (markedp == null) {
  102. savedata("marked", Array());
  103. markedp = Array();
  104. }
  105. if (logined == -1) {
  106. return;
  107. }
  108. config=readdata("config");
  109. if (config == null) {
  110. savedata("config", {});
  111. config = {};
  112. }
  113. setdefaultconfig();
  114. function updateuserdb() {
  115. var nm = fixurl.substr(48);
  116. var list = document.getElementsByTagName("script")[2].innerHTML.match(/p\([1-9][0-9]{3}\)/g);
  117. var rl = Array();
  118. for (var i of list) {
  119. rl.push(i.substr(2, 4))
  120. }
  121. savedata("userlist_" + nm, rl)
  122. }
  123. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/userinfo.php?user=") != -1) {
  124. updateuserdb();
  125. }
  126. mydb = readdata("userlist_" + username);
  127. if (islist() != -1) {
  128. updateprobinfobylist();
  129. for (i of document.getElementById("problemset").getElementsByTagName("tbody")[0].childNodes) {
  130. prob = i.childNodes[1].innerText;
  131. if (markedp.indexOf(prob) != -1) i.childNodes[2].innerHTML = i.childNodes[2].innerHTML + poly_star;
  132. }
  133. 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 +
  134. "<a href=\"javascript:;\" id=\"showmarkedlist\">Marked Problem</a>";
  135. document.getElementById("showmarkedlist").onclick = function () {
  136. txt = ""
  137. for (i = 0; i < markedp.length; i++) {
  138. o = markedp[i]
  139. info = readdata("problem_" + o);
  140. nr = ""
  141. nr += "<tr class=\"" + ((i & 1) == 0 ? "evenrow" : "oddrow") + "\">";
  142. nr += "<td>";
  143. if (mydb.indexOf(o) != -1) nr += "<span class=\"yes\">Y</span>";
  144. nr += "</td>";
  145. nr += "<td align=\"center\">";
  146. nr += o;
  147. nr += "</td>";
  148. nr += "<td align=\"left\">";
  149. nr += "<a href=\"problem.php?id=" + o + "\">" + info['title'] + "</a>" + poly_star;
  150. nr += "</td>"
  151. nr += "<td align=\"center\">";
  152. nr += info['source']
  153. nr += "</td>";
  154. nr += "<td align=\"center\">";
  155. nr += "<a href=\"status.php?problem_id=" + o + "&amp;jresult=4\">" + info['solved'] + "</a>";
  156. nr += "</td>";
  157. nr += "<td align=\"center\">";
  158. nr += "<a href=\"status.php?problem_id=" + o + "\">" + info['submit'] + "</a>";
  159. nr += "</td>";
  160. nr += "</tr>";
  161. txt += nr;
  162. }
  163. document.getElementById("problemset").getElementsByTagName("tbody")[0].innerHTML = txt;
  164. }
  165. }
  166. var prob = isprob();
  167. if (prob != -1) {
  168. updateprobinfobypage(prob)
  169. if (mydb.indexOf(prob) != -1) {
  170. var rdt = document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML;
  171. var tdb = "<span style=\"color:#00FF00\">Y</span>" + rdt;
  172. document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML = tdb;
  173. }
  174. var ttt = document.getElementsByTagName("center")[2].innerHTML;
  175. var fff = ttt + "[<a href=\"https://lydsy.com/JudgeOnline/status.php?problem_id=" + prob + "&user_id=" + username + "\">My Status</a>]";
  176. document.getElementsByTagName("center")[2].innerHTML = fff;
  177. var rdt = document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML;
  178. col = "#cccccc"
  179. if (markedp.indexOf(prob) != -1) col = "#FFFF00";
  180. var tdb = rdt +
  181. "<a href=\"javascript:;\" id=\"chmr\"><svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
  182. <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>\
  183. </svg></a>";
  184. document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].innerHTML = tdb;
  185.  
  186. document.getElementById("chmr").onclick = function () {
  187. if (markedp.indexOf(prob) != -1) {
  188. if (config["unmarkalert"]=="1" && !window.confirm("确定鸽掉它?")) return; //取消标记提示
  189. markedp.splice(markedp.indexOf(prob), 1)
  190. document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].getElementsByTagName("a")[0].childNodes[0].childNodes[1].style.fill = "#cccccc"
  191. }
  192. else {
  193. markedp.push(prob)
  194. document.getElementsByTagName("center")[2].getElementsByTagName("h2")[0].getElementsByTagName("a")[0].childNodes[0].childNodes[1].style.fill = "#FFFF00"
  195. }
  196. markedp.sort()
  197. savedata("marked", markedp)
  198. }
  199. }
  200. if (isstatus() != -1) {
  201. for (var i of document.getElementsByTagName("center")[0].getElementsByTagName("table")[2].getElementsByTagName("tbody")[0].childNodes) {
  202. if (i.className != "evenrow" && i.className != "oddrow") continue;
  203. prob = i.childNodes[2].childNodes[0].innerText;
  204. mkd = ""
  205. if (markedp.indexOf(prob) != -1)
  206. mkd = poly_star;
  207. if (mydb.indexOf(prob) != -1) {
  208. i.childNodes[2].childNodes[0].innerHTML = "<span style=\"color:#00FF00\">Y</span>" + i.childNodes[2].childNodes[0].innerHTML + mkd;
  209. }
  210. else {
  211. i.childNodes[2].childNodes[0].innerHTML = "<span style=\"color:#FF0000\">N</span>" + i.childNodes[2].childNodes[0].innerHTML + mkd;
  212. }
  213. }
  214. }
  215.  
  216.  
  217. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/modifypage.php") != -1) {
  218. var usco=
  219. {
  220. "unmarkalert":
  221. {
  222. "name":"取消标记时弹窗确认",
  223. "0":"关闭",
  224. "1":"开启"
  225. }
  226. };
  227. tmpid=0
  228. txt="<h3>BZOJ Helper设置</h3>"
  229. document.getElementsByTagName("center")[2].innerHTML+=txt;
  230. for(i in usco)
  231. {
  232. txt="<p>"
  233. txt+=usco[i]["name"]+":"
  234. chid=-1
  235. for(j in usco[i])
  236. {
  237. if(j=="name") continue;
  238. txt+="<label for=\"tmprad"+tmpid+"\"><input id=\"tmprad"+tmpid+"\" type=\"radio\" value=\""+j+"\" name=\""+i+"\">"+usco[i][j]+"</label>"
  239. if(j==config[i])
  240. chid=tmpid
  241. tmpid++
  242. }
  243. txt+="</p>"
  244. document.getElementsByTagName("center")[2].innerHTML+=txt;
  245. document.getElementById("tmprad"+chid).setAttribute("checked",true)
  246. }
  247. document.getElementsByTagName("center")[2].innerHTML+="<p><input id=\"helpersumbit\" type=\"button\" value=\"保存\"/></p>"
  248. document.getElementsByTagName("center")[2].innerHTML+="<span style=\"color:#FF0000\" id=\"savesucci\" hidden=\"true\">保存成功</span>"
  249. document.getElementById("helpersumbit").onclick = function ()
  250. {
  251. for(i in usco)
  252. config[i]=getradioval(i)
  253. savedata("config",config);
  254. document.getElementById("savesucci").removeAttribute("hidden")
  255. }
  256. }
  257.  
  258.  
  259.  
  260. 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>";
  261. setInterval(function () { document.getElementById("autofre").src = "https://lydsy.com/JudgeOnline/" }, 600000);//自动续命
  262. })();