BZOJ Helper

BZOJ助手

当前为 2019-05-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name BZOJ Helper
  3. // @namespace bzoj
  4. // @version 1.5.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. 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. Date.prototype.Format = function (fmt) { //author: meizz
  30. var o = {
  31. "M+": this.getMonth() + 1, //月份
  32. "d+": this.getDate(), //日
  33. "h+": this.getHours(), //小时
  34. "m+": this.getMinutes(), //分
  35. "s+": this.getSeconds(), //秒
  36. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  37. "S": this.getMilliseconds() //毫秒
  38. };
  39. if (/(y+)/.test(fmt))
  40. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  41. for (var k in o)
  42. if (new RegExp("(" + k + ")").test(fmt))
  43. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  44. return fmt;
  45. }
  46. function HaveMatch(txt,arr)
  47. {
  48. for(let i of arr)
  49. {
  50. if(txt.indexOf(i)!=-1) return 1;
  51. }
  52. return 0;
  53. }
  54. var poly_star = "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
  55. <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>\
  56. </svg>";
  57. var logined = 0
  58. var username = "";
  59. var mydb = Array();
  60. var markedp = Array();
  61. var fixurl = location.href;
  62. var havenotice = 0;
  63. if (document.getElementsByTagName("center")[1].innerText.indexOf("Notice") != -1) havenotice = 1;
  64. if (fixurl.indexOf("www.lydsy.com") != -1) {
  65. fixurl = fixurl.replace("www.lydsy.com", "lydsy.com");
  66. location.href = fixurl;
  67. }
  68. function getmyusername() {
  69. for (i of document.getElementsByTagName("table")[0].childNodes[1].childNodes[0].childNodes)
  70. if (typeof (i.innerText) != "undefined" && i.innerText.indexOf("ModifyUser") != -1) {
  71. username = i.innerText.substr(12);
  72. username = username.trim();
  73. return;
  74. }
  75. logined = -1;
  76. }
  77. //页面判断
  78. function isprob() {
  79. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/problem.php?id=") == -1) {
  80. return -1;
  81. }
  82. return fixurl.substr(45);
  83. }
  84. function isstatus() {
  85. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/status.php") == -1) {
  86. return -1;
  87. }
  88. return 0;
  89. }
  90. function islist() {
  91. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/problemset.php") == -1) {
  92. return -1;
  93. }
  94. return 0;
  95. }
  96. function isconfig() {
  97. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/modifypage.php") == -1) {
  98. return -1;
  99. }
  100. return 0;
  101. }
  102. function isdiscusspage() {
  103. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/wttl/thread.php") == -1) {
  104. return -1;
  105. }
  106. return 0;
  107. }
  108. function isdiscusslist() {
  109. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/wttl/wttl.php") == -1) {
  110. return -1;
  111. }
  112. return 0;
  113. }
  114. function isuserinfo() {
  115. if (fixurl.indexOf("https://lydsy.com/JudgeOnline/userinfo.php?user=") == -1) {
  116. return -1;
  117. }
  118. return 0;
  119.  
  120. }
  121. //更新db
  122. function updateprobinfobypage(pid) {
  123. sb = {};
  124. for (i of document.getElementsByTagName("h2")[0].childNodes)
  125. if (i.nodeName == "#text") {
  126. sb["title"] = i.data.substr(6)
  127. break
  128. }
  129. sb["submit"] = document.getElementsByTagName("center")[1 + havenotice].getElementsByClassName("green")[2].nextSibling.data;
  130. sb["submit"] = sb["submit"].slice(0, -2);
  131. sb["solved"] = document.getElementsByTagName("center")[1 + havenotice].getElementsByClassName("green")[3].nextSibling.data;
  132. sb["source"] = document.getElementsByTagName("h2")[7].nextElementSibling.childNodes[0].innerText;
  133. savedata("problem_" + pid, sb)
  134. }
  135. function updateprobinfobylist() {
  136. for (i of document.getElementById("problemset").getElementsByTagName("tbody")[0].childNodes) {
  137. sb = {}
  138. prob = i.childNodes[1].innerText.trim();
  139. sb["title"] = i.childNodes[2].innerText.trim();
  140. sb["source"] = i.childNodes[3].innerText.trim();
  141. sb["solved"] = i.childNodes[4].innerText.trim();
  142. sb["submit"] = i.childNodes[5].innerText.trim();
  143. if (i.childNodes[0].innerText.trim() == "Y") {
  144. if (mydb.indexOf(prob) == -1)
  145. mydb.push(prob)
  146. }
  147. savedata("problem_" + prob, sb)
  148. }
  149. savedata("userlist_" + username, mydb)
  150. }
  151. function updateuserdb(def = document, nm = fixurl.substr(48)) {
  152. var list = def.getElementsByTagName("script")[2].innerHTML.match(/p\([1-9][0-9]{3}\)/g);
  153. var rl = Array();
  154. for (var i of list) {
  155. rl.push(i.substr(2, 4))
  156. }
  157. savedata("userlist_" + nm, rl)
  158. }
  159. function getmydb() {
  160. ret = readdata("userlist_" + username);
  161. if (ret == null) {
  162. xhr = new XMLHttpRequest();
  163. xhr.open('GET', 'https://lydsy.com/JudgeOnline/userinfo.php?user=' + username, false);
  164. xhr.send(null);
  165. parser = new DOMParser();
  166. gg = parser.parseFromString(xhr.responseText, "text/html")
  167. updateuserdb(gg, username)
  168. ret = readdata("userlist_" + username)
  169. }
  170. return ret
  171. }
  172. function UpdateBlacklist(callb=0) {
  173. URL = "https://raw.githubusercontent.com/ranwen/BZOJHelper/master/blacklist.json";
  174. xhr = new XMLHttpRequest();
  175. xhr.open('GET', URL, false);
  176. xhr.send(null);
  177. obj = JSON.parse(xhr.responseText)
  178. res = { "updatetime": ((new Date()) / 1000), "user": obj.user, "title": obj.title }
  179. Blacklist = res
  180. savedata("blacklist", res)
  181. if(callb==1)
  182. alert("更新成功 请刷新");
  183. }
  184. function UpdateBlacklistAsync(callb=0) {
  185. setTimeout(UpdateBlacklist(callb), 1)
  186. }
  187. function CheckUpdateBlacklist() {
  188. nowt = (new Date()) / 1000
  189. if (nowt - Blacklist["updatetime"] < 7 * 24 * 3600) return;
  190. UpdateBlacklistAsync();
  191. }
  192. function setdefaultconfig() {
  193. def = { "unmarkalert": "0", "autoext": "1", "statusny": "1", "AutoUpdateBlacklist": "1", "Blacklist": "1" };
  194. for (i in def) {
  195. if (typeof (config[i]) == "undefined")
  196. config[i] = def[i];
  197. }
  198. savedata("config", config);
  199. }
  200. getmyusername()
  201. if (logined == -1) {
  202. return;
  203. }
  204. markedp = readdata("marked");
  205. if (markedp == null) {
  206. savedata("marked", Array());
  207. markedp = Array();
  208. }
  209. config = readdata("config");
  210. if (config == null) {
  211. savedata("config", {});
  212. config = {};
  213. }
  214. setdefaultconfig();
  215. Blacklist = readdata("blacklist");
  216. if (Blacklist == null) {
  217. savedata("blacklist", { "updatetime": 0, "user": [], "title": [] });
  218. Blacklist = { "updatetime": 0, "user": [], "title": [] };
  219. }
  220. if (config["AutoUpdateBlacklist"] == "1")
  221. CheckUpdateBlacklist();
  222. //page
  223. if (isuserinfo() != -1) {
  224. updateuserdb();
  225. document.getElementsByTagName("table")[1].getElementsByTagName("tr")[0].getElementsByTagName("td")[2].innerHTML += " <a href=\"javascript:;\" id=\"diffme\">Diff with me</a>"
  226. document.getElementById("diffme").onclick = function () {
  227. nm = fixurl.substr(48)
  228. txt = ""
  229. usdb = readdata("userlist_" + nm)
  230. for (i = 1000; i <= 9999; i++) {
  231. hs1 = (mydb.indexOf("" + i) != -1)
  232. hs2 = (usdb.indexOf("" + i) != -1)
  233. if (hs1 && hs2)
  234. txt += "<a href=\"problem.php?id=" + i + "\">" + i + "</a>\n"
  235. if (hs1 && (!hs2))
  236. txt += "<a href=\"problem.php?id=" + i + "\" style=\"color:#00FF00\">" + i + "</a>\n"
  237. if ((!hs1) && hs2)
  238. txt += "<a href=\"problem.php?id=" + i + "\" style=\"color:#FF0000\">" + i + "</a>\n"
  239. }
  240. document.getElementsByTagName("table")[1].getElementsByTagName("tr")[1].getElementsByTagName("td")[2].innerHTML = txt
  241. }
  242. }
  243.  
  244. mydb = getmydb();
  245. if (islist() != -1) {
  246. updateprobinfobylist();
  247. for (i of document.getElementById("problemset").getElementsByTagName("tbody")[0].childNodes) {
  248. prob = i.childNodes[1].innerText.trim();
  249. if (markedp.indexOf(prob) != -1) i.childNodes[2].innerHTML = i.childNodes[2].innerHTML + poly_star;
  250. }
  251. 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 +
  252. " <a href=\"javascript:;\" id=\"showmarkedlist\">Marked Problem(" + markedp.length + ")</a>";
  253. document.getElementById("showmarkedlist").onclick = function () {
  254. document.getElementById("problemset").getElementsByTagName("thead")[0].childNodes[1].childNodes[0].childNodes[0].innerHTML += " <a href=\"javascript:;\" id=\"unmarkac\">Unmark AC Problem</a>";
  255. txt = ""
  256. for (i = 0; i < markedp.length; i++) {
  257. o = markedp[i]
  258. info = readdata("problem_" + o);
  259. nr = ""
  260. nr += "<tr class=\"" + ((i & 1) == 0 ? "evenrow" : "oddrow") + "\">";
  261. nr += "<td>";
  262. if (mydb.indexOf(o) != -1) nr += "<span class=\"yes\">Y</span>";
  263. nr += "</td>";
  264. nr += "<td align=\"center\">";
  265. nr += o;
  266. nr += "</td>";
  267. nr += "<td align=\"left\">";
  268. nr += "<a href=\"problem.php?id=" + o + "\">" + info['title'] + "</a>" + poly_star;
  269. nr += "</td>"
  270. nr += "<td align=\"center\">";
  271. nr += info['source']
  272. nr += "</td>";
  273. nr += "<td align=\"center\">";
  274. nr += "<a href=\"status.php?problem_id=" + o + "&amp;jresult=4\">" + info['solved'] + "</a>";
  275. nr += "</td>";
  276. nr += "<td align=\"center\">";
  277. nr += "<a href=\"status.php?problem_id=" + o + "\">" + info['submit'] + "</a>";
  278. nr += "</td>";
  279. nr += "</tr>";
  280. txt += nr;
  281. }
  282. document.getElementById("problemset").getElementsByTagName("tbody")[0].innerHTML = txt;
  283.  
  284. //show unmarkac
  285. document.getElementById("unmarkac").onclick = function () {
  286. if (!window.confirm("确定取消标记所有AC题目?")) return
  287. markedp = readdata("marked")
  288. for (i = 0; i < markedp.length; i++) {
  289. o = markedp[i]
  290. if (mydb.indexOf(o) != -1) {
  291. markedp.splice(markedp.indexOf(o), 1)
  292. i--
  293. }
  294. }
  295. savedata("marked", markedp)
  296. //rerender
  297. txt = ""
  298. for (i = 0; i < markedp.length; i++) {
  299. o = markedp[i]
  300. info = readdata("problem_" + o);
  301. nr = ""
  302. nr += "<tr class=\"" + ((i & 1) == 0 ? "evenrow" : "oddrow") + "\">";
  303. nr += "<td>";
  304. if (mydb.indexOf(o) != -1) nr += "<span class=\"yes\">Y</span>";
  305. nr += "</td>";
  306. nr += "<td align=\"center\">";
  307. nr += o;
  308. nr += "</td>";
  309. nr += "<td align=\"left\">";
  310. nr += "<a href=\"problem.php?id=" + o + "\">" + info['title'] + "</a>" + poly_star;
  311. nr += "</td>"
  312. nr += "<td align=\"center\">";
  313. nr += info['source']
  314. nr += "</td>";
  315. nr += "<td align=\"center\">";
  316. nr += "<a href=\"status.php?problem_id=" + o + "&amp;jresult=4\">" + info['solved'] + "</a>";
  317. nr += "</td>";
  318. nr += "<td align=\"center\">";
  319. nr += "<a href=\"status.php?problem_id=" + o + "\">" + info['submit'] + "</a>";
  320. nr += "</td>";
  321. nr += "</tr>";
  322. txt += nr;
  323. }
  324. document.getElementById("problemset").getElementsByTagName("tbody")[0].innerHTML = txt;
  325. document.getElementById("showmarkedlist").innerText = "Marked Problem(" + markedp.length + ")";
  326. }
  327. }
  328. }
  329.  
  330. var prob = isprob();
  331. if (prob != -1) {
  332. updateprobinfobypage(prob)
  333. if (mydb.indexOf(prob) != -1) {
  334. var rdt = document.getElementsByTagName("center")[1 + havenotice].getElementsByTagName("h2")[0].innerHTML;
  335. var tdb = "<span style=\"color:#00FF00\">Y</span>" + rdt;
  336. document.getElementsByTagName("center")[1 + havenotice].getElementsByTagName("h2")[0].innerHTML = tdb;
  337. }
  338. var ttt = document.getElementsByTagName("center")[1 + havenotice].innerHTML;
  339. var fff = ttt + "[<a href=\"https://lydsy.com/JudgeOnline/status.php?problem_id=" + prob + "&user_id=" + username + "\">My Status</a>]";
  340. document.getElementsByTagName("center")[1 + havenotice].innerHTML = fff;
  341. var rdt = document.getElementsByTagName("center")[1 + havenotice].getElementsByTagName("h2")[0].innerHTML;
  342. col = "#cccccc"
  343. if (markedp.indexOf(prob) != -1) col = "#FFFF00";
  344. var tdb = rdt +
  345. "<a href=\"javascript:;\" id=\"chmr\"><svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 20px;height: 20px;\">\
  346. <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>\
  347. </svg></a>";
  348. document.getElementsByTagName("center")[1 + havenotice].getElementsByTagName("h2")[0].innerHTML = tdb;
  349.  
  350. document.getElementById("chmr").onclick = function () {
  351. markedp = readdata("marked");
  352. if (markedp.indexOf(prob) != -1) {
  353. if (config["unmarkalert"] == "1" && !window.confirm("确定鸽掉它?")) return; //取消标记提示
  354. markedp.splice(markedp.indexOf(prob), 1)
  355. document.getElementsByTagName("center")[1 + havenotice].getElementsByTagName("h2")[0].getElementsByTagName("a")[0].childNodes[0].childNodes[1].style.fill = "#cccccc"
  356. }
  357. else {
  358. markedp.push(prob)
  359. document.getElementsByTagName("center")[1 + havenotice].getElementsByTagName("h2")[0].getElementsByTagName("a")[0].childNodes[0].childNodes[1].style.fill = "#FFFF00"
  360. }
  361. markedp.sort()
  362. savedata("marked", markedp)
  363. }
  364. }
  365.  
  366. if (isstatus() != -1) {
  367. for (var i of document.getElementsByTagName("center")[0].getElementsByTagName("table")[2].getElementsByTagName("tbody")[0].childNodes) {
  368. if (i.className != "evenrow" && i.className != "oddrow") continue;
  369. prob = i.childNodes[2].childNodes[0].innerText.trim();
  370. user = i.childNodes[1].childNodes[0].innerText.trim();
  371. stat = i.childNodes[3].childNodes[0].innerText.trim();
  372. if (stat == "Accepted" && readdata("userlist_" + user) != null) {
  373. udb = readdata("userlist_" + user)
  374. if (udb.indexOf(prob) == -1)
  375. udb.push(prob)
  376. savedata("userlist_" + user, udb)
  377. if (user == username)
  378. mydb.push(prob)
  379. }
  380. mkd = ""
  381. if (markedp.indexOf(prob) != -1)
  382. mkd = poly_star;
  383. if (mydb.indexOf(prob) != -1) {
  384. fky = "<span style=\"color:#00FF00\">Y</span>";
  385. }
  386. else {
  387. fky = "<span style=\"color:#FF0000\">N</span>";
  388. }
  389.  
  390. if (config['statusny'] == "0") fky = ""
  391. i.childNodes[2].childNodes[0].innerHTML = fky + i.childNodes[2].childNodes[0].innerHTML + mkd;
  392. }
  393. }
  394.  
  395. if (isconfig() != -1) {
  396. var usco =
  397. {
  398. "unmarkalert":
  399. {
  400. "name": "取消标记时弹窗确认",
  401. "0": "关闭",
  402. "1": "开启"
  403. },
  404. "autoext":
  405. {
  406. "name": "自动续命",
  407. "0": "关闭",
  408. "1": "开启"
  409. },
  410. "statusny":
  411. {
  412. "name": "Status页面显示是否AC",
  413. "0": "关闭",
  414. "1": "开启"
  415. },
  416. "Blacklist":
  417. {
  418. "name": "Discuss黑名单",
  419. "0": "关闭",
  420. "1": "开启"
  421. },
  422. "AutoUpdateBlacklist":
  423. {
  424. "name": "自动更新Discuss黑名单",
  425. "0": "关闭",
  426. "1": "开启"
  427. }
  428. };
  429. tmpid = 0
  430. txt = "<h3>BZOJ Helper设置</h3>";
  431. document.getElementsByTagName("center")[1 + havenotice].innerHTML += txt;
  432. for (i in usco) {
  433. txt = "<p>";
  434. txt += usco[i]["name"] + ":"
  435. chid = -1
  436. for (j in usco[i]) {
  437. if (j == "name") continue;
  438. txt += "<label for=\"tmprad" + tmpid + "\"><input id=\"tmprad" + tmpid + "\" type=\"radio\" value=\"" + j + "\" name=\"" + i + "\">" + usco[i][j] + "</label>"
  439. if (j == config[i])
  440. chid = tmpid
  441. tmpid++
  442. }
  443. txt += "</p>"
  444. document.getElementsByTagName("center")[1 + havenotice].innerHTML += txt;
  445. document.getElementById("tmprad" + chid).setAttribute("checked", true)
  446. }
  447. document.getElementsByTagName("center")[1 + havenotice].innerHTML += "<p><input id=\"helpersumbit\" type=\"button\" value=\"保存\"/></p>"
  448. document.getElementsByTagName("center")[1 + havenotice].innerHTML += "<span style=\"color:#FF0000\" id=\"savesucci\" hidden=\"true\">保存成功</span>"
  449. document.getElementById("helpersumbit").onclick = function () {
  450. for (i in usco)
  451. config[i] = getradioval(i)
  452. savedata("config", config);
  453. document.getElementById("savesucci").removeAttribute("hidden")
  454. }
  455. }
  456.  
  457. if (isdiscusslist() != -1) {
  458. headerobj = document.getElementsByTagName("center")[1 + havenotice].childNodes[1]
  459. headerobj.childNodes[1].innerHTML += " [<a href=\"javascript:;\" id=\"updateblacklist\">Update Blacklist(Last: " + (new Date(Blacklist["updatetime"]*1000)).Format("MM-dd hh:mm") + ")</a>]"
  460. document.getElementById("updateblacklist").onclick = function ()
  461. {
  462. UpdateBlacklistAsync(1)
  463. }
  464. tbd=document.getElementsByTagName("tbody")[1]
  465. txt=""
  466. oo=0
  467. for(let i of tbd.childNodes)
  468. {
  469. if(i.className!="oddrow" && i.className!="evenrow")
  470. {
  471. if(i.outerHTML!=undefined)
  472. txt+=i.outerHTML
  473. continue
  474. }
  475. usern=i.childNodes[3].innerText
  476. titl=i.childNodes[4].innerText
  477. if(Blacklist.user.indexOf(usern)!=-1) continue;
  478. if(HaveMatch(titl,Blacklist.title)) continue;
  479. //if(i.className=='oddrow') continue;//check
  480. if(oo==0) i.className="evenrow"
  481. else i.className="oddrow"
  482. txt+=i.outerHTML
  483. oo^=1
  484. }
  485. tbd.innerHTML=txt
  486. }
  487.  
  488. if (isdiscusspage() != -1) {
  489. document.getElementsByTagName("center")[1 + havenotice].childNodes[1].childNodes[1].innerHTML += document.getElementsByTagName("center")[1 + havenotice].childNodes[1].childNodes[5].innerHTML;
  490. }
  491.  
  492. //自动续命
  493. 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>";
  494. if (config["autoext"] == "1") setInterval(function () { document.getElementById("autofre").src = "https://lydsy.com/JudgeOnline/" }, 600000);
  495. })();