BZOJ Helper

BZOJ助手

当前为 2018-11-01 提交的版本,查看 最新版本

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