BZOJ Helper

BZOJ助手

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

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