BZOJ Helper

BZOJ助手

当前为 2018-10-22 提交的版本,查看 最新版本

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