Luogu Tasks

qwq

2021-04-02 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Luogu Tasks
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @run-at document-start
  6. // @description qwq
  7. // @author __OwO__
  8. // @match https://www.luogu.com.cn/*
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant unsafeWindow
  12. // @require https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js
  13. // @require https://cdn.staticfile.org/sweetalert/2.1.2/sweetalert.min.js
  14. // ==/UserScript==
  15.  
  16. window.onload = async () => {
  17. const inject_lantency = 500;
  18.  
  19. let local_list = GM_getValue("problem-helper-local-id");
  20. let local_problems;
  21. let geticon = (uid, pid, scr, fscr, stat = null) => {
  22. let res;
  23. let ua = (uid, pid) =>
  24. `<a data-v-303bbf52="" data-v-357e29e4="" href="/record/list?pid=${pid}&amp;user=${uid}" target="_blank" colorscheme="default" class="color-default" data-v-83961efe="" style="color: inherit; float:left; padding-right: 0.5em;"><svg data-v-1b44b3e6="" data-v-357e29e4="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512" class="icon svg-inline--fa fa-times fa-w-11" data-v-303bbf52="" style="transform: scale(1.2); color: rgb(231, 76, 60);"><path data-v-1b44b3e6="" fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z" class=""></path></svg></a>`;
  25. let ac = (uid, pid) =>
  26. `<a data-v-303bbf52="" data-v-357e29e4="" href="/record/list?pid=${pid}&amp;user=${uid}" target="_blank" colorscheme="default" class="color-default" data-v-83961efe="" style="color: inherit; float:left; padding-right: 0.5em;"><svg data-v-1b44b3e6="" data-v-357e29e4="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="icon svg-inline--fa fa-check fa-w-16" data-v-303bbf52="" style="color: rgb(82, 196, 26);"><path data-v-1b44b3e6="" fill="currentColor" d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z" class=""></path></svg></a>`;
  27. let nt = (uid, pid) =>
  28. `<a data-v-303bbf52="" data-v-357e29e4="" href="/record/list?pid=${pid}&amp;user=${uid}" target="_blank" colorscheme="default" class="color-default" data-v-83961efe="" style="color: inherit; float:left; padding-right: 0.5em;"><svg data-v-1b44b3e6="" data-v-357e29e4="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="minus" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="icon svg-inline--fa fa-minus fa-w-14" data-v-303bbf52="" style="opacity: 0.7;"><path data-v-1b44b3e6="" fill="currentColor" d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z" class=""></path></svg></a>`;
  29. if (scr == fscr || stat) res = ac(uid, pid);
  30. else if (scr == null) res = nt(uid, pid);
  31. else res = ua(uid, pid);
  32. return (
  33. `<span data-v-3fb75f36="" style="font-weight: bold;">` + res + `</span>`
  34. );
  35. };
  36. let renderList = (title, content, float) =>
  37. `
  38. <div
  39. data-v-796309f8=""
  40. data-v-3fb75f36=""
  41. class="card padding-default"
  42. data-v-6febb0e8=""
  43. id="problem-helper-container"
  44. >
  45. ${float}
  46. <h4 data-v-3fb75f36="" data-v-796309f8="" class="lfe-h4">${title}</h4>
  47. <div class="problem-helper-inner" style="display:none;">
  48. ${content}
  49. </div>
  50. <div data-v-e4b7c2ca="" data-v-3fb75f36="" class="expand-tip lfe-caption" data-v-796309f8="" >
  51. <span class="problem-helper-fold-off" style="display:none;" data-v-e4b7c2ca=""><svg data-v-e4b7c2ca="" aria-hidden="true" focusable="false" data-prefix="fal" data-icon="chevron-up" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-chevron-up fa-w-14" ><path data-v-e4b7c2ca="" fill="currentColor" d="M4.465 366.475l7.07 7.071c4.686 4.686 12.284 4.686 16.971 0L224 178.053l195.494 195.493c4.686 4.686 12.284 4.686 16.971 0l7.07-7.071c4.686-4.686 4.686-12.284 0-16.97l-211.05-211.051c-4.686-4.686-12.284-4.686-16.971 0L4.465 349.505c-4.687 4.686-4.687 12.284 0 16.97z" class=""></path></svg> 隐藏列表</span>
  52. <span class="problem-helper-fold-on" data-v-e4b7c2ca=""><svg data-v-e4b7c2ca="" aria-hidden="true" focusable="false" data-prefix="fal" data-icon="chevron-down" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-chevron-down fa-w-14"><path data-v-e4b7c2ca="" fill="currentColor" d="M443.5 162.6l-7.1-7.1c-4.7-4.7-12.3-4.7-17 0L224 351 28.5 155.5c-4.7-4.7-12.3-4.7-17 0l-7.1 7.1c-4.7 4.7-4.7 12.3 0 17l211 211.1c4.7 4.7 12.3 4.7 17 0l211-211.1c4.8-4.7 4.8-12.3.1-17z" class=""></path></svg> 查看列表</span>
  53. </div>
  54. </div>
  55. `;
  56. let loadProblemList = async (id) => {
  57. return new Promise((res, rej) => {
  58. $.get(`https://www.luogu.com.cn/training/${id}?_contentOnly=any`).then(
  59. (task) => {
  60. task = task.currentData.training;
  61. let getList = (x, is_local) => {
  62. let id = task.problems[x].problem.pid;
  63. if (
  64. GM_getValue("problem-helper-hide-aced") == 1 &&
  65. task.userScore.status[id] &&
  66. id != local_list
  67. )
  68. return "";
  69. return `
  70. <div>
  71. <div>
  72. <span data-v-3a151854="">
  73. <a
  74. data-v-303bbf52=""
  75. data-v-3fb75f36=""
  76. href="/record/list?pid=${id}&amp;user=${task.userScore.user.uid}"
  77. class="color-default"
  78. style="text-decoration: none;"
  79. >
  80. ${geticon(
  81. id,
  82. task.userScore.user.uid,
  83. task.userScore.score[id],
  84. task.problems[x].problem.fullScore,
  85. task.userScore.status[id]
  86. )}
  87. </a>
  88. ${
  89. is_local
  90. ? `
  91. <a
  92. data-v-3fb75f36=""
  93. style="float: right;font-weight: light;"
  94. class="problem-helper-delete-from-list"
  95. data="${id}"
  96. >
  97. <svg data-v-4121e124="" aria-hidden="true" focusable="false" data-prefix="fal" data-icon="times" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" class="svg-inline--fa fa-times fa-w-10"><path data-v-4121e124="" fill="currentColor" d="M193.94 256L296.5 153.44l21.15-21.15c3.12-3.12 3.12-8.19 0-11.31l-22.63-22.63c-3.12-3.12-8.19-3.12-11.31 0L160 222.06 36.29 98.34c-3.12-3.12-8.19-3.12-11.31 0L2.34 120.97c-3.12 3.12-3.12 8.19 0 11.31L126.06 256 2.34 379.71c-3.12 3.12-3.12 8.19 0 11.31l22.63 22.63c3.12 3.12 8.19 3.12 11.31 0L160 289.94 262.56 392.5l21.15 21.15c3.12 3.12 8.19 3.12 11.31 0l22.63-22.63c3.12-3.12 3.12-8.19 0-11.31L193.94 256z" class=""></path></svg>
  98. </a>
  99. `
  100. : ""
  101. }
  102. </span>
  103. <a
  104. class="colored problem-helper-text"
  105. style="padding-left: 3px"
  106. href="/problemnew/show/${id}"
  107. target="_blank"
  108. >
  109. <b>${id}</b> ${task.problems[x].problem.title}
  110. </a>
  111. </div>
  112. </div>`;
  113. };
  114. let content = "",
  115. float =
  116. '<a style="float:right;" data="${task.id}" data-v-303bbf52="" data-v-3fb75f36="" href="#" class="problem-helper-train-remove color-default">删除</a>';
  117. if (id == local_list)
  118. (float = ""),
  119. (local_problems = task.problems.map((u) => u.problem.pid));
  120. for (let i in task.problems) content += getList(i, id == local_list);
  121. res(renderList(task.title, content, float));
  122. }
  123. );
  124. });
  125. };
  126. let saveTrain = async (problems) => {
  127. return new Promise((r) => {
  128. $.ajax({
  129. type: "POST",
  130. url: `https://www.luogu.com.cn/api/training/editProblems/${local_list}`,
  131. beforeSend: function (request) {
  132. request.setRequestHeader(
  133. "x-csrf-token",
  134. $("meta[name='csrf-token']")[0].content
  135. );
  136. },
  137. contentType: "application/json;charset=UTF-8",
  138. data: JSON.stringify({ pids: problems }),
  139. success: () => r(),
  140. });
  141. });
  142. };
  143. let getScore = async (sett) => {
  144. if (sett.method == "train")
  145. return {
  146. uid: sett.task.userScore.user.uid,
  147. scr: sett.task.userScore.score[sett.id],
  148. fscr: sett.task.problems[sett.id].problem.fullScore,
  149. };
  150. else if (sett.method == "local")
  151. return new Promise((res, rej) => {
  152. $.get(`https://www.luogu.com.cn/problem/${sett.id}?_contentOnly`).then(
  153. (u) => {
  154. res({
  155. uid: u.currentUser.uid,
  156. scr: u.currentData.problem.score,
  157. fscr: u.currentData.problem.fullScore,
  158. });
  159. }
  160. );
  161. });
  162. };
  163. // let loadLocalProblem = async () => {
  164. // let local = GM_getValue("problem-helper-local-list");
  165. // let getList = async (id, opt = 1) => {
  166. // let h = "";
  167. // if (opt) {
  168. // let info = await getScore({ method: "local", id: id });
  169. // h = geticon(info.uid, id, info.scr, info.fscr);
  170. // }
  171. // return `
  172. // <div>
  173. // <div>
  174. // ${h}
  175. // <span data-v-3a151854="">
  176. // <a
  177. // data-v-303bbf52=""
  178. // data-v-3fb75f36=""
  179. // href="#"
  180. // class="color-default"
  181. // style="text-decoration: none;"
  182. // >
  183. // <span
  184. // data-v-3fb75f36=""
  185. // style="float: right;font-weight: light;"
  186. // data="${id}"
  187. // class="problem-helper-delete-from-list"
  188. // >
  189. // 删除
  190. // </span>
  191. // </a>
  192. // </span>
  193. // <a
  194. // class="colored problem-helper-text
  195. // style="padding-left: 3px"
  196. // href="/problemnew/show/${id}"
  197. // target="_blank"
  198. // >
  199. // <b>${id}</b> ${local[id]}
  200. // </a>
  201. // </div>
  202. // </div>`;
  203. // };
  204. // let content = "";
  205. // for (let i in local) content += await getList(i);
  206. // return renderList("本地列表", content, "");
  207. // };
  208. function renderItem(title, id) {
  209. return `
  210. <div>
  211. <div>
  212. <span data-v-3a151854="">
  213. <a
  214. data-v-303bbf52=""
  215. data-v-3fb75f36=""
  216. href="/record/list?pid=${id}&amp;user=${task.userScore.user.uid}"
  217. class="color-default"
  218. style="text-decoration: none;"
  219. >
  220. ${geticon(
  221. id,
  222. task.userScore.user.uid,
  223. task.userScore.score[id],
  224. task.problems[x].problem.fullScore,
  225. task.userScore.status[id]
  226. )}
  227. </a>
  228. </span>
  229. <a
  230. class="colored problem-helper-text
  231. style="padding-left: 3px"
  232. href="/problemnew/show/${id}"
  233. target="_blank"
  234. >
  235. <b>${id}</b> ${task.problems[x].problem.title}
  236. </a>
  237. </div>
  238. </div>
  239. `;
  240. }
  241. async function loaderProblemEntry() {
  242. let lists = "";
  243. let urls = GM_getValue("problem-helper-local-train-list") || [];
  244. // console.log(urls);
  245. if (local_list && !urls[local_list]) urls[local_list] = "本地列表";
  246. for (let i in urls) lists += await loadProblemList(i);
  247. lists += renderList(
  248. "设置",
  249. `<div data-v-59a1d633="" data-v-83961efe="" class="row">
  250. <div data-v-72d91c56="" data-v-59a1d633="" class="checkbox" data-v-83961efe=""><input id="problem-helper-hide-aced" type="checkbox" value="65560" ${
  251. GM_getValue("problem-helper-hide-aced") ? 'checked=""' : ""
  252. }"> <lable>
  253. 隐藏已通过题目
  254. </label> </div>
  255. <div>
  256. <label>本地题单</label>
  257. <input data-v-a7f7c968="" type="text" placeholder="题单id" class="lfe-form-sz-middle" style+"width: 30%;" value="${
  258. GM_getValue("problem-helper-local-id") || ""
  259. }" id="problem-helper-set-local-list">
  260. </div>
  261. </div>`,
  262. ""
  263. );
  264. $("#problem-helper-entry").html(lists);
  265. $(".problem-helper-fold-on").click((u) => {
  266. u = $(u.target);
  267. u.parent().prev(".problem-helper-inner").removeAttr("style");
  268. u.attr("style", "display:none;");
  269. u.prev(".problem-helper-fold-off").removeAttr("style");
  270. });
  271. $(".problem-helper-fold-off").click((u) => {
  272. u = $(u.target);
  273. u.parent().prev(".problem-helper-inner").attr("style", "display:none;");
  274. u.attr("style", "display:none;");
  275. u.next(".problem-helper-fold-on").removeAttr("style");
  276. });
  277. $("#problem-helper-hide-aced").click((u) => {
  278. u = $(u.target);
  279. GM_setValue("problem-helper-hide-aced", u[0].checked);
  280. unsafeWindow._feInstance.$swalToastSuccess("修改成功");
  281. loaderProblemEntry();
  282. });
  283. $("#problem-helper-set-local-list").keydown(function (e) {
  284. if (e.keyCode == 13) {
  285. let v = $("#problem-helper-set-local-list").val();
  286. GM_setValue("problem-helper-local-id", v.trim());
  287. local_list = GM_getValue("problem-helper-local-id");
  288. unsafeWindow._feInstance.$swalToastSuccess("修改成功");
  289. loaderProblemEntry();
  290. }
  291. });
  292. $("#problem-helper-add-to-list").click((u) => {
  293. let r = unsafeWindow.location.href.split("/");
  294. r = r[r.length - 1];
  295. while (r[r.length - 1] == "#") r = r.slice(0, r.length - 1);
  296. if (!unsafeWindow._feInjection.currentData.problem.title) return;
  297. if (local_problems.indexOf(r) == -1) local_problems.push(r);
  298. saveTrain(local_problems);
  299. unsafeWindow._feInstance.$swalToastSuccess("添加成功");
  300. loaderProblemEntry();
  301. });
  302. $(".problem-helper-delete-from-list").click((u) => {
  303. u = $(u.target).parents(".problem-helper-delete-from-list");
  304. let r = u.attr("data");
  305. let now = local_problems;
  306. let newone = [];
  307. for (let i in now) if (now[i] != r) newone[i] = now[i];
  308. saveTrain(newone);
  309. unsafeWindow._feInstance.$swalToastSuccess("删除成功");
  310. loaderProblemEntry();
  311. });
  312. $(".problem-helper-train-remove").click((u) => {
  313. u = $(u.target);
  314. let r = u.attr("data");
  315. let now = GM_getValue("problem-helper-local-train-list");
  316. let newone = {};
  317. for (let i in now) if (i != r) newone[i] = now[i];
  318. GM_setValue("problem-helper-local-train-list", newone);
  319. unsafeWindow._feInstance.$swalToastSuccess("删除成功");
  320. loaderProblemEntry();
  321. });
  322. }
  323. let deferredInjectProblemPage = () => {
  324. $("#problem-helper-container").remove();
  325. $(".side").prepend(
  326. renderList(
  327. "做题助手",
  328. '<div id="problem-helper-entry"></div>',
  329. '<a style="float:right;" data-v-303bbf52="" data-v-3fb75f36="" href="#" id="problem-helper-add-to-list" class="color-default"><svg data-v-b35188f4="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="plus-square" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-plus-square fa-w-14"><path data-v-b35188f4="" fill="currentColor" d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-32 252c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92H92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z" class=""></path></svg>添加至列表</a >'
  330. )
  331. );
  332. loaderProblemEntry();
  333. };
  334. let loadTrainList = (id) => {
  335. let local = GM_getValue("problem-helper-local-train-list");
  336. let getList = (id) => {
  337. return `
  338. <div>
  339. <div>
  340. <span data-v-3a151854="">
  341. <a
  342. style="text-decoration: none;float: right;font-weight: light;"
  343. data="${id}"
  344. class="color-default problem-helper-delete-from-list"
  345. data-v-303bbf52=""
  346. data-v-3fb75f36=""
  347. href="#"
  348. >
  349. <svg data-v-4121e124="" aria-hidden="true" focusable="false" data-prefix="fal" data-icon="times" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" class="svg-inline--fa fa-times fa-w-10"><path data-v-4121e124="" fill="currentColor" d="M193.94 256L296.5 153.44l21.15-21.15c3.12-3.12 3.12-8.19 0-11.31l-22.63-22.63c-3.12-3.12-8.19-3.12-11.31 0L160 222.06 36.29 98.34c-3.12-3.12-8.19-3.12-11.31 0L2.34 120.97c-3.12 3.12-3.12 8.19 0 11.31L126.06 256 2.34 379.71c-3.12 3.12-3.12 8.19 0 11.31l22.63 22.63c3.12 3.12 8.19 3.12 11.31 0L160 289.94 262.56 392.5l21.15 21.15c3.12 3.12 8.19 3.12 11.31 0l22.63-22.63c3.12-3.12 3.12-8.19 0-11.31L193.94 256z" class=""></path></svg>
  350. </a>
  351. </span>
  352. <a
  353. class="colored problem-helper-text"
  354. style="padding-left: 3px"
  355. href="https://www.luogu.com.cn/training/${id}#information"
  356. target="_blank"
  357. >
  358. <b>${id}</b> ${local[id]}
  359. </a>
  360. </div>
  361. </div>`;
  362. };
  363. let lists = "";
  364. for (let i in local) lists += getList(i);
  365. return lists;
  366. };
  367. let loaderTrainEntry = async () => {
  368. let lists = loadTrainList();
  369. $("#problem-helper-entry").html(lists);
  370. $(".problem-helper-fold-on").click((u) => {
  371. u = $(u.target);
  372. u.parent().prev(".problem-helper-inner").removeAttr("style");
  373. u.attr("style", "display:none;");
  374. u.prev(".problem-helper-fold-off").removeAttr("style");
  375. });
  376. $(".problem-helper-fold-off").click((u) => {
  377. u = $(u.target);
  378. u.parent().prev(".problem-helper-inner").attr("style", "display:none;");
  379. u.attr("style", "display:none;");
  380. u.next(".problem-helper-fold-on").removeAttr("style");
  381. });
  382. $("#problem-helper-add-to-list").click((u) => {
  383. let r = unsafeWindow.location.href.split("/");
  384. r = r[r.length - 1].split("#")[0];
  385. if (!unsafeWindow._feInjection.currentData.training.title) return;
  386. let now = GM_getValue("problem-helper-local-train-list");
  387. if (!now) now = {};
  388. now[r] = unsafeWindow._feInjection.currentData.training.title;
  389. GM_setValue("problem-helper-local-train-list", now);
  390. unsafeWindow._feInstance.$swalToastSuccess("添加成功");
  391. loaderTrainEntry();
  392. });
  393. $(".problem-helper-delete-from-list").click((u) => {
  394. u = $(u.target).parents(".problem-helper-delete-from-list");
  395. let r = u.attr("data");
  396. let now = GM_getValue("problem-helper-local-train-list");
  397. let newone = {};
  398. for (let i in now) if (i != r) newone[i] = now[i];
  399. GM_setValue("problem-helper-local-train-list", newone);
  400. unsafeWindow._feInstance.$swalToastSuccess("删除成功");
  401. loaderProblemEntry();
  402. });
  403. };
  404. let deferredInjectTrainPage = () => {
  405. $("#problem-helper-container").remove();
  406. $(".side").prepend(
  407. renderList(
  408. "做题助手",
  409. '<div id="problem-helper-entry"></div>',
  410. '<a style="float:right;" data-v-303bbf52="" data-v-3fb75f36="" href="#" id="problem-helper-add-to-list" class="color-default"><svg data-v-b35188f4="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="plus-square" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-plus-square fa-w-14"><path data-v-b35188f4="" fill="currentColor" d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-32 252c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92H92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z" class=""></path></svg>添加至列表</a>'
  411. )
  412. );
  413. loaderTrainEntry();
  414. };
  415. let deferredInjectProblemlist = () => {
  416. $(".problem-helper-inlist-adder").remove();
  417. let pid = "",
  418. name = "";
  419. let h = (pid, name) => `
  420. <a style="float:right; padding-right: 2em;" data="${pid}" name="${name}" data-v-303bbf52="" data-v-3fb75f36="" href="#" class="problem-helper-inlist-adder color-default"><svg data-v-b35188f4="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="plus-square" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-plus-square fa-w-14"><path data-v-b35188f4="" fill="currentColor" d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-32 252c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92H92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z" class=""></path></svg>
  421. 添加
  422. </a>`;
  423. let rows = $(".row");
  424. let trim = (s) => {
  425. return s.replace(/(^\s*)|(\s*$)/g, "");
  426. };
  427. rows.each((u) => {
  428. u = $(rows[u]);
  429. pid = u.children(".pid").text();
  430. name = u.children(".title").children(".title").text();
  431. name = trim(name);
  432. u.children(".title").prepend(h(pid, name));
  433. });
  434. $(".problem-helper-inlist-adder").click((u) => {
  435. u = $(u.target);
  436. let r = u.attr("data"),
  437. s = u.attr("name");
  438. let now = GM_getValue("problem-helper-local-list");
  439. if (!now) now = {};
  440. now[r] = s;
  441. GM_setValue("problem-helper-local-list", now);
  442. unsafeWindow._feInstance.$swalToastSuccess("添加成功");
  443. });
  444. };
  445.  
  446. /* main controller */
  447. let inject = () => {
  448. if (
  449. unsafeWindow.location.href.includes(
  450. "problem/list"
  451. ) /*deferredInjectProblemlist();*/
  452. );
  453. else if (unsafeWindow.location.href.includes("training"))
  454. deferredInjectTrainPage(), deferredInjectProblemlist();
  455. else if (unsafeWindow.location.href.includes("problem"))
  456. deferredInjectProblemPage();
  457. };
  458. $(".entry").click(() => setTimeout(inject, inject_lantency));
  459. $("a").click(() => setTimeout(inject, inject_lantency));
  460. $("button").click(() => setTimeout(inject, inject_lantency));
  461. setTimeout(inject, 100);
  462. $(document.body).append(
  463. `<style>
  464. .problem-helper-text{
  465. -webkit-line-clamp: 1; overflow: hidden; display: -webkit-box;
  466. -webkit-box-orient: vertical; white-space: normal;
  467. }
  468. .expand-tip > span[data-v-e4b7c2ca] {
  469. -webkit-user-select: none;
  470. -moz-user-select: none;
  471. -ms-user-select: none;
  472. cuser-select: none;
  473. cursor: pointer;
  474. color: rgba(0, 0, 0, .3);
  475. }
  476. .expand-tip[data-v-e4b7c2ca] {
  477. text-align: center;
  478. }
  479. .expand-tip > span[data-v-e4b7c2ca]:hover {
  480. color: inherit;
  481. }
  482. </style>`
  483. );
  484. };