BZOJ Helper

BZOJ助手

当前为 2018-12-05 提交的版本,查看 最新版本

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