Greasy Fork镜像 还支持 简体中文。

Codeforces Better!

Codeforces界面汉化、黑暗模式支持、题目翻译、markdown视图、一键复制题目、跳转到洛谷、评论区分页、ClistRating分显示、榜单重新着色

目前為 2023-10-13 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Codeforces Better!
  3. // @namespace https://gf.qytechs.cn/users/747162
  4. // @version 1.68
  5. // @description Codeforces界面汉化、黑暗模式支持、题目翻译、markdown视图、一键复制题目、跳转到洛谷、评论区分页、ClistRating分显示、榜单重新着色
  6. // @author 北极小狐
  7. // @match *://*.codeforces.com/*
  8. // @match *://*.codeforc.es/*
  9. // @run-at document-start
  10. // @connect www2.deepl.com
  11. // @connect www.iflyrec.com
  12. // @connect m.youdao.com
  13. // @connect api.interpreter.caiyunai.com
  14. // @connect translate.google.com
  15. // @connect openai.api2d.net
  16. // @connect api.openai.com
  17. // @connect www.luogu.com.cn
  18. // @connect clist.by
  19. // @connect gf.qytechs.cn
  20. // @connect *
  21. // @grant GM_xmlhttpRequest
  22. // @grant GM_info
  23. // @grant GM_setValue
  24. // @grant GM_getValue
  25. // @grant GM_deleteValue
  26. // @grant GM_addStyle
  27. // @grant GM_setClipboard
  28. // @icon https://aowuucdn.oss-cn-beijing.aliyuncs.com/codeforces.png
  29. // @require https://cdn.staticfile.org/turndown/7.1.2/turndown.min.js
  30. // @require https://cdn.staticfile.org/markdown-it/13.0.1/markdown-it.min.js
  31. // @require https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/crypto-js.min.js
  32. // @require https://cdn.staticfile.org/chroma-js/2.4.2/chroma.min.js
  33. // @license MIT
  34. // @compatible Chrome
  35. // @compatible Firefox
  36. // @compatible Edge
  37. // @incompatible safari
  38. // @supportURL https://github.com/beijixiaohu/OJBetter/issues
  39. // ==/UserScript==
  40.  
  41. // 状态与初始化
  42. const getGMValue = (key, defaultValue) => {
  43. const value = GM_getValue(key);
  44. if (value === undefined || value === "") {
  45. GM_setValue(key, defaultValue);
  46. return defaultValue;
  47. }
  48. return value;
  49. };
  50. var darkMode = getGMValue("darkMode", "follow");
  51. var is_mSite, is_acmsguru, is_oldLatex, is_contest, is_problem, is_problemset, is_cfStandings;
  52. var bottomZh_CN, showLoading, hoverTargetAreaDisplay, expandFoldingblocks, renderPerfOpt, translation, commentTranslationChoice;
  53. var openai_model, openai_key, openai_proxy, openai_header, openai_data, opneaiConfig;
  54. var commentTranslationMode, retransAction, transWaitTime, replaceSymbol, commentPaging, showJumpToLuogu, loaded;
  55. var showClistRating_contest, showClistRating_problem, showClistRating_problemset, RatingHidden, clist_Authorization;
  56. var standingsRecolor;
  57. function init() {
  58. const { hostname, href } = window.location;
  59. is_mSite = hostname.startsWith('m');
  60. is_oldLatex = $('.tex-span').length;
  61. is_acmsguru = href.includes("acmsguru") && href.includes('/problem/');
  62. is_contest = /\/contest\/[\d\/\s]+$/.test(href) && !href.includes('/problem/');
  63. is_problem = href.includes('/problem/');
  64. is_problemset = href.includes('/problemset') && !href.includes('/problem/');
  65. is_cfStandings = href.includes('/standings') &&
  66. $('.standings tr:first th:nth-child(n+5)')
  67. .map(() => $(this).find('span').text())
  68. .get().every(score => /^[0-9]+$/.test(score));
  69. bottomZh_CN = getGMValue("bottomZh_CN", true);
  70. showLoading = getGMValue("showLoading", true);
  71. hoverTargetAreaDisplay = getGMValue("hoverTargetAreaDisplay", false);
  72. expandFoldingblocks = getGMValue("expandFoldingblocks", true);
  73. renderPerfOpt = getGMValue("renderPerfOpt", false);
  74. commentPaging = getGMValue("commentPaging", true);
  75. showJumpToLuogu = getGMValue("showJumpToLuogu", true);
  76. standingsRecolor = getGMValue("standingsRecolor", true);
  77. loaded = getGMValue("loaded", false);
  78. translation = getGMValue("translation", "deepl");
  79. commentTranslationMode = getGMValue("commentTranslationMode", "0");
  80. commentTranslationChoice = getGMValue("commentTranslationChoice", "0");
  81. retransAction = getGMValue("retransAction", "0");
  82. transWaitTime = getGMValue("transWaitTime", "200");
  83. replaceSymbol = getGMValue("replaceSymbol", "2");
  84. showClistRating_contest = getGMValue("showClistRating_contest", false);
  85. showClistRating_problem = getGMValue("showClistRating_problem", false);
  86. showClistRating_problemset = getGMValue("showClistRating_problemset", false);
  87. RatingHidden = getGMValue("RatingHidden", false);
  88. clist_Authorization = getGMValue("clist_Authorization", "");
  89. //openai
  90. opneaiConfig = getGMValue("chatgpt-config", {
  91. "choice": -1,
  92. "configurations": []
  93. });
  94. if (opneaiConfig.choice !== -1 && opneaiConfig.configurations.length !== 0) {
  95. const configAtIndex = opneaiConfig.configurations[opneaiConfig.choice];
  96.  
  97. if (configAtIndex == undefined) {
  98. let existingConfig = GM_getValue('chatgpt-config');
  99. existingConfig.choice = 0;
  100. GM_setValue('chatgpt-config', existingConfig);
  101. location.reload();
  102. }
  103.  
  104. openai_model = configAtIndex.model;
  105. openai_key = configAtIndex.key;
  106. openai_proxy = configAtIndex.proxy;
  107. openai_header = configAtIndex._header ?
  108. configAtIndex._header.split("\n").map(header => {
  109. const [key, value] = header.split(":");
  110. return { [key.trim()]: value.trim() };
  111. }) : [];
  112. openai_data = configAtIndex._data ?
  113. configAtIndex._data.split("\n").map(header => {
  114. const [key, value] = header.split(":");
  115. return { [key.trim()]: value.trim() };
  116. }) : [];
  117. }
  118. }
  119.  
  120. // 显示警告消息
  121. function ShowAlertMessage() {
  122. if (is_oldLatex) {
  123. let newElement = $("<div></div>").addClass("alert alert-warning ojbetter-alert")
  124. .html(`Codeforces Better! —— 注意:当前页面存在未保存原 LaTeX 代码的 LaTeX 公式(这通常是一道古老的题目),这导致脚本无法将其还原回 LaTeX,因此当前页面部分功能不适用。
  125. <br>此外当前页面的翻译功能采用了特别的实现方式,因此可能会出现排版错位的情况。`)
  126. .css({ "margin": "1em", "text-align": "center", "position": "relative" });
  127. $(".menu-box:first").next().after(newElement);
  128. }
  129. if (is_acmsguru) {
  130. let newElement = $("<div></div>").addClass("alert alert-warning ojbetter-alert")
  131. .html(`Codeforces Better! —— 注意:当前页面为 acmsguru 题目(这是一道非常古老的题目),部分功能不适用。
  132. <br>此外当前页面的翻译功能采用了特别的实现方式,因此可能会出现排版错位的情况。`)
  133. .css({ "margin": "1em", "text-align": "center", "position": "relative" });
  134. $(".menu-box:first").next().after(newElement);
  135. }
  136. if (commentTranslationMode == "1") {
  137. let newElement = $("<div></div>").addClass("alert alert-error CFBetter_alert")
  138. .html(`Codeforces Better! —— 注意!当前为分段翻译模式,这会造成负面效果,<p>除非你现在需要翻译超长篇的博客或者题目,否则请前往设置切换为普通模式</p>`)
  139. .css({ "margin": "1em", "text-align": "center", "position": "relative" });
  140. $(".menu-box:first").next().after(newElement);
  141. }
  142. if (commentTranslationMode == "2") {
  143. let newElement = $("<div></div>").addClass("alert alert-error CFBetter_alert")
  144. .html(`Codeforces Better! —— 注意!当前为选段翻译模式,只会翻译目标区域内已选中的部分,点击段落以选中(橙色框)<br>
  145. <p>如果你现在不需要翻译超长篇的博客或者题目,建议你请前往设置切换为普通模式</p>`)
  146. .css({ "margin": "1em", "text-align": "center", "position": "relative" });
  147. $(".menu-box:first").next().after(newElement);
  148. }
  149. }
  150.  
  151. // 常量
  152. const helpCircleHTML = '<div class="help-icon"><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm23.744 191.488c-52.096 0-92.928 14.784-123.2 44.352-30.976 29.568-45.76 70.4-45.76 122.496h80.256c0-29.568 5.632-52.8 17.6-68.992 13.376-19.712 35.2-28.864 66.176-28.864 23.936 0 42.944 6.336 56.32 19.712 12.672 13.376 19.712 31.68 19.712 54.912 0 17.6-6.336 34.496-19.008 49.984l-8.448 9.856c-45.76 40.832-73.216 70.4-82.368 89.408-9.856 19.008-14.08 42.24-14.08 68.992v9.856h80.96v-9.856c0-16.896 3.52-31.68 10.56-45.76 6.336-12.672 15.488-24.64 28.16-35.2 33.792-29.568 54.208-48.576 60.544-55.616 16.896-22.528 26.048-51.392 26.048-86.592 0-42.944-14.08-76.736-42.24-101.376-28.16-25.344-65.472-37.312-111.232-37.312zm-12.672 406.208a54.272 54.272 0 0 0-38.72 14.784 49.408 49.408 0 0 0-15.488 38.016c0 15.488 4.928 28.16 15.488 38.016A54.848 54.848 0 0 0 523.072 768c15.488 0 28.16-4.928 38.72-14.784a51.52 51.52 0 0 0 16.192-38.72 51.968 51.968 0 0 0-15.488-38.016 55.936 55.936 0 0 0-39.424-14.784z"></path></svg></div>';
  153. const unfoldIcon = `<svg t="1695971616104" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2517" width="18" height="18"><path d="M747.451 527.394L512.376 707.028l-235.071-185.71a37.975 37.975 0 0 0-23.927-8.737 38 38 0 0 0-29.248 13.674 37.984 37.984 0 0 0 4.938 53.552l259.003 205.456c14.013 11.523 34.219 11.523 48.231 0l259.003-199.002a37.974 37.974 0 0 0 5.698-53.552 37.982 37.982 0 0 0-53.552-5.315z m0 0" p-id="2518"></path><path d="M488.071 503.845c14.013 11.522 34.219 11.522 48.231 0l259.003-199.003a37.97 37.97 0 0 0 13.983-25.591 37.985 37.985 0 0 0-8.285-27.959 37.97 37.97 0 0 0-25.591-13.979 37.985 37.985 0 0 0-27.96 8.284L512.376 425.61 277.305 239.899a37.974 37.974 0 0 0-23.927-8.736 37.993 37.993 0 0 0-29.248 13.674 37.984 37.984 0 0 0 4.938 53.552l259.003 205.456z m0 0" p-id="2519"></path></svg>`;
  154. const putawayIcon = `<svg t="1695971573189" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2266" width="18" height="18"><path d="M276.549 496.606l235.075-179.634 235.071 185.711a37.975 37.975 0 0 0 23.927 8.737 38 38 0 0 0 29.248-13.674 37.986 37.986 0 0 0-4.938-53.552L535.929 238.737c-14.013-11.523-34.219-11.523-48.231 0L228.695 437.739a37.974 37.974 0 0 0-5.698 53.552 37.982 37.982 0 0 0 53.552 5.315z m0 0" p-id="2267"></path><path d="M535.929 520.155c-14.013-11.522-34.219-11.522-48.231 0L228.695 719.158a37.97 37.97 0 0 0-13.983 25.591 37.985 37.985 0 0 0 8.285 27.959 37.97 37.97 0 0 0 25.591 13.979 37.985 37.985 0 0 0 27.96-8.284L511.624 598.39l235.071 185.711a37.974 37.974 0 0 0 23.927 8.736 37.993 37.993 0 0 0 29.248-13.674 37.984 37.984 0 0 0-4.938-53.552L535.929 520.155z m0 0" p-id="2268"></path></svg>`;
  155. const closeIcon = `<svg t="1696693011050" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4322" width="14" height="14"><path d="M0 0h1024v1024H0z" fill-opacity="0" p-id="4323"></path><path d="M240.448 168l2.346667 2.154667 289.92 289.941333 279.253333-279.253333a42.666667 42.666667 0 0 1 62.506667 58.026666l-2.133334 2.346667-279.296 279.210667 279.274667 279.253333a42.666667 42.666667 0 0 1-58.005333 62.528l-2.346667-2.176-279.253333-279.253333-289.92 289.962666a42.666667 42.666667 0 0 1-62.506667-58.005333l2.154667-2.346667 289.941333-289.962666-289.92-289.92a42.666667 42.666667 0 0 1 57.984-62.506667z" p-id="4324"></path></svg>`;
  156. const copyIcon = `<svg t="1695970366492" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2499" width="16" height="16"><path d="M720 192h-544A80.096 80.096 0 0 0 96 272v608C96 924.128 131.904 960 176 960h544c44.128 0 80-35.872 80-80v-608C800 227.904 764.128 192 720 192z m16 688c0 8.8-7.2 16-16 16h-544a16 16 0 0 1-16-16v-608a16 16 0 0 1 16-16h544a16 16 0 0 1 16 16v608z" p-id="2500"></path><path d="M848 64h-544a32 32 0 0 0 0 64h544a16 16 0 0 1 16 16v608a32 32 0 1 0 64 0v-608C928 99.904 892.128 64 848 64z" p-id="2501"></path><path d="M608 360H288a32 32 0 0 0 0 64h320a32 32 0 1 0 0-64zM608 520H288a32 32 0 1 0 0 64h320a32 32 0 1 0 0-64zM480 678.656H288a32 32 0 1 0 0 64h192a32 32 0 1 0 0-64z" p-id="2502"></path></svg>`;
  157. const copyedIcon = `<svg t="1697105956577" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="986" width="16" height="16"><path d="M928 612.8V144c0-44.8-35.2-80-80-80H304c-17.6 0-32 14.4-32 32s14.4 32 32 32h544c8 0 16 8 16 16v425.6c-19.2-9.6-41.6-16-64-17.6V272c0-44.8-35.2-80-80-80H176c-44.8 0-80 35.2-80 80v608c0 44.8 35.2 80 80 80h460.8c36.8 27.2 83.2 43.2 132.8 43.2 126.4 0 227.2-100.8 227.2-227.2 0-64-27.2-121.6-68.8-163.2zM176 896c-8 0-16-8-16-16V272c0-8 8-16 16-16h544c8 0 16 8 16 16v280c-108.8 16-193.6 110.4-193.6 224 0 44.8 12.8 84.8 33.6 120H176z m593.6 72c-19.2 0-36.8-3.2-54.4-8-38.4-11.2-72-33.6-96-64-25.6-32-41.6-75.2-41.6-120 0-94.4 67.2-172.8 158.4-188.8 11.2-1.6 22.4-3.2 33.6-3.2 11.2 0 20.8 0 30.4 1.6 22.4 3.2 44.8 11.2 64 22.4 25.6 14.4 48 35.2 64 59.2 20.8 30.4 33.6 68.8 33.6 108.8 0 107.2-84.8 192-192 192z" p-id="987"></path>
  158. <path d="M608 360H288c-17.6 0-32 14.4-32 32s14.4 32 32 32h320c17.6 0 32-14.4 32-32s-14.4-32-32-32z m0 160H288c-17.6 0-32 14.4-32 32s14.4 32 32 32h320c17.6 0 32-14.4 32-32s-14.4-32-32-32z m-128 158.4H288c-17.6 0-32 14.4-32 32s14.4 32 32 32h192c17.6 0 32-14.4 32-32s-14.4-32-32-32zM731.2 886.4c-6.4 0-11.2-1.6-16-6.4l-73.6-73.6c-9.6-9.6-9.6-22.4 0-32s22.4-9.6 32 0l57.6 57.6 137.6-137.6c9.6-9.6 22.4-9.6 32 0s9.6 22.4 0 32L747.2 880c-4.8 3.2-9.6 6.4-16 6.4z" p-id="988"></path></svg>`;
  159. const translateIcon = `<svg t="1696837407077" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6325" width="22" height="22"><path d="M536.380952 121.904762a73.142857 73.142857 0 0 1 73.142858 73.142857v219.428571h219.428571a73.142857 73.142857 0 0 1 73.142857 73.142858v341.333333a73.142857 73.142857 0 0 1-73.142857 73.142857H487.619048a73.142857 73.142857 0 0 1-73.142858-73.142857v-219.428571H195.047619a73.142857 73.142857 0 0 1-73.142857-73.142858V195.047619a73.142857 73.142857 0 0 1 73.142857-73.142857h341.333333zM243.809524 682.666667v97.523809h97.523809v73.142857h-97.523809a73.142857 73.142857 0 0 1-73.142857-73.142857v-97.523809h73.142857z m585.142857-195.047619h-219.428571v48.761904a73.142857 73.142857 0 0 1-73.142858 73.142858h-48.761904v219.428571h341.333333V487.619048z m-115.760762 89.526857L787.21219 780.190476h-62.025142l-14.043429-42.715428h-76.068571L620.739048 780.190476h-60.854858l74.605715-203.044571h78.701714z m-38.034286 50.029714h-3.510857l-21.065143 63.488h45.348572l-20.772572-63.488zM536.380952 195.047619H195.047619v341.333333h341.333333V195.047619z
  160. m-195.072 49.883429l44.78781 1.072762v37.278476h87.698286v145.359238h-87.698286v65.974857h-44.78781v-65.974857h-87.698285v-145.359238h87.698285v-38.351238z m0 83.139047h-44.787809v56.05181h44.787809v-56.05181z m89.307429 0h-44.519619v56.05181h44.519619v-56.05181zM780.190476 170.666667a73.142857 73.142857 0 0 1 73.142857 73.142857v97.523809h-73.142857v-97.523809h-97.523809V170.666667h97.523809z" p-id="6326"></path></svg>`;
  161. const clistIcon = `<svg width="37.7pt" height="10pt" viewBox="0 0 181 48" version="1.1" xmlns="http://www.w3.org/2000/svg"><g id="#0057b8ff"><path fill="#0057b8" opacity="1.00" d=" M 17.36 0.00 L 18.59 0.00 C 23.84 6.49 30.28 11.92 36.01 17.98 C 34.01 19.99 32.01 21.99 30.00 23.99 C 26.02 19.97 22.02 15.98 18.02 11.99 C 14.01 15.98 10.01 19.99 6.00 23.99 C 4.16 22.04 2.30 20.05 0.00 18.61 L 0.00 17.37 C 3.44 15.11 6.00 11.84 8.96 9.03 C 11.79 6.05 15.09 3.47 17.36 0.00 Z" /></g><g id="#a0a0a0ff"><path fill="#a0a0a0" opacity="1.00" d=" M 56.76 13.74 C 61.48 4.80 76.07 3.90 81.77 12.27 C 83.09 13.94 83.44 16.10 83.91 18.12 C 81.53 18.23 79.16 18.24 76.78 18.23 C 75.81 15.72 73.99 13.31 71.14 12.95 C 67.14 12.02 63.45 15.29 62.48 18.99 C 61.30 23.27 61.71 28.68 65.34 31.70 C 67.82 34.05 72.19 33.93 74.61 31.55 C 75.97 30.18 76.35 28.23 76.96 26.48 C 79.36 26.43 81.77 26.44 84.17 26.56 C 83.79 30.09 82.43 33.49 79.89 36.02 C 74.14 41.35 64.17 40.80 58.77 35.25 C 53.52 29.56 53.18 20.38 56.76 13.74 Z" />
  162. <path fill="#a0a0a0" opacity="1.00" d=" M 89.01 7.20 C 91.37 7.21 93.74 7.21 96.11 7.22 C 96.22 15.71 96.10 24.20 96.18 32.69 C 101.25 32.76 106.32 32.63 111.39 32.79 C 111.40 34.86 111.41 36.93 111.41 39.00 C 103.94 39.00 96.47 39.00 89.00 39.00 C 89.00 28.40 88.99 17.80 89.01 7.20 Z" /><path fill="#a0a0a0" opacity="1.00" d=" M 115.00 7.21 C 117.33 7.21 119.66 7.21 121.99 7.21 C 122.01 17.81 122.00 28.40 122.00 39.00 C 119.67 39.00 117.33 39.00 115.00 39.00 C 115.00 28.40 114.99 17.80 115.00 7.21 Z" /><path fill="#a0a0a0" opacity="1.00" d=" M 133.35 7.47 C 139.11 5.56 146.93 6.28 150.42 11.87 C 151.42 13.39 151.35 15.31 151.72 17.04 C 149.33 17.05 146.95 17.05 144.56 17.03 C 144.13 12.66 138.66 11.12 135.34 13.30 C 133.90 14.24 133.54 16.87 135.35 17.61 C 139.99 20.02 145.90 19.54 149.92 23.19 C 154.43 26.97 153.16 35.36 147.78 37.72 C 143.39 40.03 137.99 40.11 133.30 38.69 C 128.80 37.34 125.34 32.90 125.91 28.10 C 128.22 28.10 130.53 28.11 132.84 28.16 C 132.98 34.19 142.68 36.07 145.18 30.97 C 146.11 27.99 142.17 27.05 140.05 26.35 C 135.54 25.04 129.83 24.33 127.50 19.63 C 125.30 14.78 128.42 9.00 133.35 7.47 Z" />
  163. <path fill="#a0a0a0" opacity="1.00" d=" M 153.31 7.21 C 161.99 7.21 170.67 7.21 179.34 7.21 C 179.41 9.30 179.45 11.40 179.48 13.50 C 176.35 13.50 173.22 13.50 170.09 13.50 C 170.05 21.99 170.12 30.48 170.05 38.98 C 167.61 39.00 165.18 39.00 162.74 39.00 C 162.64 30.52 162.73 22.04 162.69 13.55 C 159.57 13.49 156.44 13.49 153.32 13.50 C 153.32 11.40 153.31 9.31 153.31 7.21 Z" /></g><g id="#ffd700ff"><path fill="#ffd700" opacity="1.00" d=" M 12.02 29.98 C 14.02 27.98 16.02 25.98 18.02 23.98 C 22.01 27.99 26.03 31.97 30.00 35.99 C 34.01 31.99 38.01 27.98 42.02 23.99 C 44.02 25.98 46.02 27.98 48.01 29.98 C 42.29 36.06 35.80 41.46 30.59 48.00 L 29.39 48.00 C 24.26 41.42 17.71 36.08 12.02 29.98 Z" /></g></svg>`;
  164. const darkenPageStyle = `body::before { content: ""; display: block; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.4); z-index: 100; }`;
  165. const darkenPageStyle2 = `body::before { content: ""; display: block; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.4); z-index: 300; }`;
  166.  
  167. // 报错信息捕获
  168. /*let errorMessages = "";
  169. const defaultError = console.error.bind(console);
  170. console.error = (message) => {
  171. const error = new Error();
  172. const stack = error.stack.split("\n").slice(2).join("\n");
  173. const now = new Date().toLocaleString();
  174. errorMessages += "\n## " + message + "\n### time: " + now +"\n" + stack + "\n";
  175. defaultError(message);
  176. };
  177. window.onerror = (message, source, lineno, colno, error) => {
  178. const now = new Date().toLocaleString();
  179. errorMessages += "\n## " + message + "\n### time: " + now +"\n" + error.stack + "\n";
  180. defaultError(message);
  181. return true;
  182. };*/
  183.  
  184. // 切换系统黑暗监听
  185. const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
  186. const changeEventListeners = [];
  187. function handleColorSchemeChange(event) {
  188. const newColorScheme = event.matches ? $('html').attr('data-theme', 'dark') : $('html').attr('data-theme', 'light');
  189. if (!event.matches) {
  190. var originalColor = $(this).data("original-color");
  191. $(this).css("background-color", originalColor);
  192. }
  193. }
  194.  
  195. // 黑暗模式
  196. (function setDark() {
  197. // 初始化
  198. function setDarkTheme() {
  199. const htmlElement = document.querySelector('html');
  200. if (htmlElement) {
  201. htmlElement.setAttribute('data-theme', 'dark');
  202. } else {
  203. setTimeout(setDarkTheme, 100);
  204. }
  205. }
  206. if (darkMode == "dark") {
  207. setDarkTheme();
  208. } else if (darkMode == "follow") {
  209. // 添加事件监听器
  210. changeEventListeners.push(handleColorSchemeChange);
  211. mediaQueryList.addEventListener('change', handleColorSchemeChange);
  212.  
  213. if (window.matchMedia('(prefers-color-scheme: dark)').matches) setDarkTheme();
  214. }
  215.  
  216. GM_addStyle(`
  217. /* 黑暗支持 */
  218. html[data-theme=dark]:root {
  219. color-scheme: light dark;
  220. }
  221. /* 文字颜色1 */
  222. html[data-theme=dark] .title,html[data-theme=dark] .problem-statement,
  223. html[data-theme=dark] .ttypography, html[data-theme=dark] .roundbox, html[data-theme=dark] .info,
  224. html[data-theme=dark] .ttypography .bordertable, html[data-theme=dark] .ttypography .bordertable thead th,
  225. html[data-theme=dark] .ttypography h1, html[data-theme=dark] .ttypography h2, html[data-theme=dark] .ttypography h3,
  226. html[data-theme=dark] .ttypography h4, html[data-theme=dark] .ttypography h5, html[data-theme=dark] .ttypography h6
  227. html[data-theme=dark] .datatable table, html[data-theme=dark] .problem-statement .sample-tests pre,
  228. html[data-theme=dark] .alert-success, html[data-theme=dark] .alert-info, html[data-theme=dark] .alert-error,
  229. html[data-theme=dark] .alert-warning, html[data-theme=dark] .markItUpEditor, html[data-theme=dark] #pageContent,
  230. html[data-theme=dark] .ace-chrome .ace_gutter, html[data-theme=dark] .translate-problem-statement,
  231. html[data-theme=dark] .setting-name, html[data-theme=dark] .CFBetter_setting_menu, html[data-theme=dark] .help_tip .tip_text,
  232. html[data-theme=dark] textarea, html[data-theme=dark] .user-black, html[data-theme=dark] .comments label.show-archived,
  233. html[data-theme=dark] .comments label.show-archived *, html[data-theme=dark] table,
  234. html[data-theme=dark] #items-per-page, html[data-theme=dark] #pagBar, html[data-theme=dark] .CFBetter_setting_sidebar li a:link,
  235. html[data-theme=dark] .popup .content{
  236. color: #a0adb9 !important;
  237. }
  238. html[data-theme=dark] h1 a, html[data-theme=dark] h2 a, html[data-theme=dark] h3 a, html[data-theme=dark] h4 a{
  239. color: #adbac7;
  240. }
  241. /* 文字颜色2 */
  242. html[data-theme=dark] .contest-state-phase, html[data-theme=dark] .legendary-user-first-letter,
  243. html[data-theme=dark] .lang-chooser,
  244. html[data-theme=dark] .second-level-menu-list li a, html[data-theme=dark] #footer,
  245. html[data-theme=dark] .ttypography .tt, html[data-theme=dark] select,
  246. html[data-theme=dark] .roundbox .caption, html[data-theme=dark] .topic .title *,
  247. html[data-theme=dark] .user-admin, html[data-theme=dark] button.html2mdButton:hover,
  248. html[data-theme=dark] .CFBetter_modal button{
  249. color: #9099a3 !important;
  250. }
  251. /* 文字颜色3 */
  252. html[data-theme=dark] button.html2mdButton, html[data-theme=dark] #program-source-text-copy{
  253. color: #6385a6;
  254. }
  255. html[data-theme=dark] input{
  256. color: #6385a6 !important;
  257. }
  258. /* 文字颜色4 */
  259. html[data-theme=dark] .ttypography .MathJax, html[data-theme=dark] .MathJax span{
  260. color: #cbd6e2 !important;
  261. }
  262. /* 链接颜色 */
  263. html[data-theme=dark] a:link {
  264. color: #3989c9;
  265. }
  266. html[data-theme=dark] a:visited {
  267. color: #8590a6;
  268. }
  269. html[data-theme=dark] .menu-box a, html[data-theme=dark] .sidebox th a{
  270. color: #9099a3 !important;
  271. }
  272. /* 按钮 */
  273. html[data-theme=dark] .second-level-menu-list li.backLava {
  274. border-radius: 6px;
  275. overflow: hidden;
  276. filter: invert(1) hue-rotate(.5turn);
  277. }
  278. html[data-theme=dark] input:hover{
  279. background-color: #22272e !important;
  280. }
  281. /* 背景层次1 */
  282. html[data-theme=dark] body, html[data-theme=dark] .ttypography .bordertable thead th,
  283. html[data-theme=dark] .datatable table, html[data-theme=dark] .datatable .dark, html[data-theme=dark] li#add_button,
  284. html[data-theme=dark] .problem-statement .sample-tests pre, html[data-theme=dark] .markItUpEditor,
  285. html[data-theme=dark] .SumoSelect>.CaptionCont, html[data-theme=dark] .SumoSelect>.optWrapper,
  286. html[data-theme=dark] .SumoSelect>.optWrapper.multiple>.options li.opt span i, html[data-theme=dark] .ace_scroller,
  287. html[data-theme=dark] .CFBetter_setting_menu, html[data-theme=dark] .help_tip .tip_text, html[data-theme=dark] li#add_button:hover,
  288. html[data-theme=dark] textarea, html[data-theme=dark] .state, html[data-theme=dark] .ace-chrome .ace_gutter-active-line,
  289. html[data-theme=dark] .sidebar-menu ul li:hover, html[data-theme=dark] .sidebar-menu ul li.active,
  290. html[data-theme=dark] label.config_bar_ul_li_text:hover, html[data-theme=dark] button.html2mdButton:hover,
  291. html[data-theme=dark] .CFBetter_setting_sidebar li a.active, html[data-theme=dark] .CFBetter_setting_sidebar li,
  292. html[data-theme=dark] .CFBetter_setting_menu::-webkit-scrollbar-track, html[data-theme=dark] .CFBetter_setting_content::-webkit-scrollbar-track,
  293. html[data-theme=dark] .CFBetter_modal, html[data-theme=dark] .CFBetter_modal button:hover,
  294. html[data-theme=dark] .popup .content, html[data-theme=dark] .file.input-view .text, html[data-theme=dark] .file.output-view .text,
  295. html[data-theme=dark] .file.answer-view .text, html[data-theme=dark] .file.checker-comment-view .text,
  296. html[data-theme=dark] #config_bar_list{
  297. background-color: #22272e !important;
  298. }
  299. /* 背景层次2 */
  300. html[data-theme=dark] .roundbox, html[data-theme=dark] .roundbox .dark, html[data-theme=dark] .bottom-links,
  301. html[data-theme=dark] button.html2mdButton, html[data-theme=dark] .spoiler-content, html[data-theme=dark] input,
  302. html[data-theme=dark] .problem-statement .test-example-line-even, html[data-theme=dark] .highlight-blue,
  303. html[data-theme=dark] .ttypography .tt, html[data-theme=dark] select,
  304. html[data-theme=dark] .alert-success, html[data-theme=dark] .alert-info, html[data-theme=dark] .alert-error,
  305. html[data-theme=dark] .alert-warning, html[data-theme=dark] .SumoSelect>.optWrapper>.options li.opt:hover,
  306. html[data-theme=dark] .input-output-copier:hover, html[data-theme=dark] .translate-problem-statement-panel,
  307. html[data-theme=dark] .aceEditorTd, html[data-theme=dark] .ace-chrome .ace_gutter,
  308. html[data-theme=dark] .translate-problem-statement, html[data-theme=dark] .datatable,
  309. html[data-theme=dark] .CFBetter_setting_list,
  310. html[data-theme=dark] .CFBetter_setting_menu hr,
  311. html[data-theme=dark] .highlighted-row td, html[data-theme=dark] .highlighted-row th,
  312. html[data-theme=dark] .pagination span.active, html[data-theme=dark] .CFBetter_setting_sidebar li a,
  313. html[data-theme=dark] .CFBetter_setting_menu::-webkit-scrollbar-thumb, html[data-theme=dark] .CFBetter_setting_content::-webkit-scrollbar-thumb,
  314. html[data-theme=dark] .CFBetter_modal button, html[data-theme=dark] .test-for-popup pre,
  315. html[data-theme=dark] .popup .content pre, html[data-theme=dark] .popup .content pre code,
  316. html[data-theme=dark] ul#config_bar_ul::-webkit-scrollbar-thumb{
  317. background-color: #2d333b !important;
  318. }
  319. /* 实线边框颜色-圆角 */
  320. html[data-theme=dark] .roundbox, html[data-theme=dark] .roundbox .rtable td,
  321. html[data-theme=dark] button.html2mdButton, html[data-theme=dark] .sidebar-menu ul li,
  322. html[data-theme=dark] input, html[data-theme=dark] .ttypography .tt, html[data-theme=dark] #items-per-page,
  323. html[data-theme=dark] .datatable td, html[data-theme=dark] .datatable th,
  324. html[data-theme=dark] .alert-success, html[data-theme=dark] .alert-info, html[data-theme=dark] .alert-error,
  325. html[data-theme=dark] .alert-warning, html[data-theme=dark] .translate-problem-statement,
  326. html[data-theme=dark] textarea, html[data-theme=dark] .input-output-copier{
  327. border: 1px solid #424b56 !important;
  328. border-radius: 2px;
  329. }
  330. /* 实线边框颜色-无圆角 */
  331. html[data-theme=dark] .CFBetter_setting_list, html[data-theme=dark] #config_bar_list,
  332. html[data-theme=dark] label.config_bar_ul_li_text, html[data-theme=dark] .problem-statement .sample-tests .input,
  333. html[data-theme=dark] .problem-statement .sample-tests .output, html[data-theme=dark] .pagination span.active,
  334. html[data-theme=dark] .CFBetter_setting_sidebar li, html[data-theme=dark] .CFBetter_setting_menu select,
  335. html[data-theme=dark] .translate-problem-statement-panel, html[data-theme=dark] .CFBetter_modal button,
  336. html[data-theme=dark] .test-for-popup pre{
  337. border: 1px solid #424b56 !important;
  338. }
  339. html[data-theme=dark] .roundbox .titled, html[data-theme=dark] .roundbox .rtable th {
  340. border-bottom: 1px solid #424b56 !important;
  341. }
  342. html[data-theme=dark] .roundbox .bottom-links, html[data-theme=dark] #footer{
  343. border-top: 1px solid #424b56 !important;
  344. }
  345. html[data-theme=dark] .topic .content {
  346. border-left: 4px solid #424b56 !important;
  347. }
  348. html[data-theme=dark] .CFBetter_setting_sidebar {
  349. border-right: 1px solid #424b56 !important;
  350. }
  351. html[data-theme=dark] hr {
  352. border-color: #424b56 !important;
  353. }
  354. /* 虚线边框颜色 */
  355. html[data-theme=dark] .comment-table, html[data-theme=dark] li#add_button,
  356. html[data-theme=dark] .CFBetter_setting_menu_label_text{
  357. border: 1px dashed #424b56 !important;
  358. }
  359. html[data-theme=dark] li#add_button:hover{
  360. border: 1px dashed #03A9F4 !important;
  361. background-color: #2d333b !important;
  362. color: #03A9F4 !important;
  363. }
  364. /* focus-visible */
  365. html[data-theme=dark] input:focus-visible, html[data-theme=dark] textarea, html[data-theme=dark] select{
  366. border-width: 1.5px !important;
  367. outline: none;
  368. }
  369. /* 图片-亮度 */
  370. html[data-theme=dark] img, html[data-theme=dark] #facebox .popup a{
  371. opacity: .75;
  372. }
  373. /* 反转 */
  374. html[data-theme=dark] .SumoSelect>.CaptionCont>label>i, html[data-theme=dark] .delete-resource-link,
  375. html[data-theme=dark] #program-source-text, html[data-theme=dark] .spoiler-content pre,
  376. html[data-theme=dark] .popup .content pre code{
  377. filter: invert(1) hue-rotate(.5turn);
  378. }
  379. /* 区域遮罩 */
  380. html[data-theme=dark] .overlay {
  381. background: repeating-linear-gradient(135deg, #49525f6e, #49525f6e 30px, #49525f29 0px, #49525f29 55px);
  382. color: #9099a3;
  383. text-shadow: 0px 0px 2px #000000;
  384. }
  385. /* 其他样式 */
  386. html[data-theme=dark] .rated-user{
  387. display: initial;
  388. }
  389. html[data-theme=dark] .datatable .ilt, html[data-theme=dark] .datatable .irt,
  390. html[data-theme=dark] .datatable .ilb, html[data-theme=dark] .datatable .irb,
  391. html[data-theme=dark] .datatable .lt, html[data-theme=dark] .datatable .rt,
  392. html[data-theme=dark] .datatable .lb, html[data-theme=dark] .datatable .rb{
  393. background: none;
  394. }
  395. html[data-theme=dark] .problems .accepted-problem td.id{
  396. border-left: 6px solid #47837d !important;
  397. }
  398. html[data-theme=dark] .problems .rejected-problem td.id{
  399. border-left: 6px solid #ef9a9a !important;
  400. }
  401. html[data-theme=dark] .problems .accepted-problem td.act {
  402. background-color: #47837d !important;
  403. border-radius: 0px;
  404. }
  405. html[data-theme=dark] .problems .rejected-problem td.act{
  406. background-color: #ef9a9a !important;
  407. border-radius: 0px;
  408. }
  409. html[data-theme=dark] .CFBetter_setting_menu, html[data-theme=dark] .CFBetter_modal{
  410. box-shadow: 0px 0px 0px 4px #2d333b;
  411. border: 1px solid #2d333b;
  412. }
  413. html[data-theme=dark] .collapsible-topic.collapsed .content .collapsible-topic-options:before{
  414. background-image: linear-gradient(#22272e00, #22272e);
  415. }
  416. html[data-theme=dark] .alert{
  417. text-shadow: none;
  418. }
  419. html[data-theme=dark] input[type="radio"]:checked+.CFBetter_setting_menu_label_text {
  420. color: #a0adb9 !important;
  421. border: 1px solid #326154 !important;
  422. }
  423. /* 评测状态文字颜色 */
  424. html[data-theme=dark] .verdict-accepted, html[data-theme=dark] .verdict-accepted-challenged,
  425. html[data-theme=dark] .verdict-successful-challenge{
  426. color: #0a0 !important;
  427. }
  428. html[data-theme=dark] .verdict-failed, html[data-theme=dark] .verdict-challenged{
  429. color: red !important;
  430. }
  431. html[data-theme=dark] .verdict-rejected, html[data-theme=dark] .verdict-unsuccessful-challenge{
  432. color: #673ab7 !important;
  433. }
  434. html[data-theme=dark] .verdict-waiting {
  435. color: gray !important;
  436. }
  437. `);
  438. })()
  439.  
  440. // 样式
  441. GM_addStyle(`
  442. html {
  443. scroll-behavior: smooth;
  444. }
  445. :root {
  446. --vp-font-family-base: "Chinese Quotes", "Inter var", "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  447. }
  448. span.mdViewContent {
  449. white-space: pre-wrap;
  450. }
  451. /*翻译区域提示*/
  452. .overlay {
  453. pointer-events: none;
  454. position: absolute;
  455. top: 0;
  456. left: 0;
  457. width: 100%;
  458. height: 100%;
  459. background: repeating-linear-gradient(135deg, #97e7cacc, #97e7cacc 30px, #e9fbf1cc 0px, #e9fbf1cc 55px);
  460. border-radius: 5px;
  461. display: flex;
  462. align-items: center;
  463. justify-content: center;
  464. color: #00695C;
  465. font-size: 16px;
  466. font-weight: bold;
  467. text-shadow: 0px 0px 2px #edfcf4;
  468. }
  469. /*翻译div*/
  470. .translate-problem-statement {
  471. justify-items: start;
  472. letter-spacing: 1.8px;
  473. color: #059669;
  474. background-color: #f9f9fa;
  475. border: 1px solid #c5ebdf;
  476. box-shadow: 0px 0px 0.5px 0.5px #defdf3;
  477. border-radius: 0rem 0rem 0.3rem 0.3rem;
  478. padding: 5px;
  479. margin: -5px 0px 6px 0px;
  480. width: 100%;
  481. box-sizing: border-box;
  482. font-size: 13px;
  483. }
  484. .translate-problem-statement.error_translate {
  485. color: red;
  486. border-color: red;
  487. }
  488. .translate-problem-statement a, .translate-problem-statement a:link {
  489. color: #10b981;
  490. font-weight: 600;
  491. background: 0 0;
  492. text-decoration: none;
  493. }
  494. .translate-problem-statement ol, .translate-problem-statement ul {
  495. display: grid;
  496. margin-inline-start: 0.8em;
  497. margin-block-start: 0em;
  498. margin: 0.5em 0 0 3em;
  499. }
  500. .translate-problem-statement li {
  501. display: list-item;
  502. height: auto;
  503. word-wrap: break-word;
  504. }
  505. .translate-problem-statement ol li {
  506. list-style-type: auto;
  507. }
  508. .translate-problem-statement ul li {
  509. list-style-type: disc;
  510. }
  511. .translate-problem-statement img {
  512. max-width: 100.0%;
  513. max-height: 100.0%;
  514. }
  515. .ttypography .translate-problem-statement .MathJax {
  516. color: #059669!important;
  517. }
  518. .translate-problem-statement span.math {
  519. margin: 0px 2.5px !important;
  520. }
  521. .translate-problem-statement a:hover {
  522. background-color: #800;
  523. color: #fff;
  524. text-decoration: none;
  525. }
  526. .translate-problem-statement-panel{
  527. display: flex;
  528. justify-content: space-between;
  529. background-color: #f9f9fa;
  530. border: 1px solid #c5ebdf;
  531. box-shadow: 0px 0px 0.5px 0.5px #defdf3;
  532. border-radius: 0.3rem;
  533. margin: 4px 0px;
  534. }
  535. .html2md-panel {
  536. display: flex;
  537. justify-content: flex-end;
  538. align-items: center;
  539. }
  540. .html2md-panel a {
  541. text-decoration: none;
  542. }
  543. .html2mdButton {
  544. display: flex;
  545. align-items: center;
  546. cursor: pointer;
  547. background-color: #ffffff;
  548. color: #606266;
  549. height: 22px;
  550. width: auto;
  551. font-size: 13px;
  552. border-radius: 0.3rem;
  553. padding: 1px 5px;
  554. margin: 5px !important;
  555. border: 1px solid #dcdfe6;
  556. }
  557. .html2mdButton:hover {
  558. color: #409eff;
  559. border-color: #409eff;
  560. background-color: #f1f8ff;
  561. }
  562. button.html2mdButton.copied {
  563. background-color: #f0f9eb;
  564. color: #67c23e;
  565. border: 1px solid #b3e19d;
  566. }
  567. button.html2mdButton.mdViewed {
  568. background-color: #fdf6ec;
  569. color: #e6a23c;
  570. border: 1px solid #f3d19e;
  571. }
  572. button.html2mdButton.error {
  573. background-color: #fef0f0;
  574. color: #f56c6c;
  575. border: 1px solid #fab6b6;
  576. }
  577. button.translated {
  578. background-color: #f0f9eb;
  579. color: #67c23e;
  580. border: 1px solid #b3e19d;
  581. }
  582. button.html2mdButton.reTranslation {
  583. background-color: #f4f4f5;
  584. color: #909399;
  585. border: 1px solid #c8c9cc;
  586. }
  587. .topText {
  588. display: flex;
  589. margin-left: 5px;
  590. color: #9e9e9e;
  591. font-size: 13px;
  592. align-items: center;
  593. }
  594. .borderlessButton{
  595. display: flex;
  596. align-items: center;
  597. margin: 2.5px 7px;
  598. fill: #9E9E9E;
  599. }
  600. .borderlessButton:hover{
  601. cursor: pointer;
  602. fill: #059669;
  603. }
  604. .translate-problem-statement table {
  605. border: 1px #ccc solid !important;
  606. margin: 1.5em 0 !important;
  607. color: #059669 !important;
  608. }
  609. .translate-problem-statement table thead th {
  610. border: 1px #ccc solid !important;
  611. color: #059669 !important;
  612. }
  613. .translate-problem-statement table td {
  614. border-right: 1px solid #ccc;
  615. border-top: 1px solid #ccc;
  616. padding: 0.7143em 0.5em;
  617. }
  618. .translate-problem-statement table th {
  619. padding: 0.7143em 0.5em;
  620. }
  621. .translate-problem-statement p:not(:first-child) {
  622. margin: 1.5em 0 0;
  623. }
  624. .translate-problem-statement p {
  625. line-height: 20px !important;
  626. }
  627. .problem-statement p:last-child {
  628. margin-bottom: 0px !important;
  629. }
  630. /*设置面板*/
  631. header .enter-or-register-box, header .languages {
  632. position: absolute;
  633. right: 170px;
  634. }
  635. button.html2mdButton.CFBetter_setting {
  636. float: right;
  637. height: 30px;
  638. background: #60a5fa;
  639. color: white;
  640. margin: 10px;
  641. border: 0px;
  642. }
  643.  
  644. button.html2mdButton.CFBetter_setting.open {
  645. background-color: #e6e6e6;
  646. color: #727378;
  647. cursor: not-allowed;
  648. }
  649.  
  650. .CFBetter_setting_menu {
  651. z-index: 200;
  652. box-shadow: 0px 0px 0px 4px #ffffff;
  653. display: grid;
  654. position: fixed;
  655. top: 50%;
  656. left: 50%;
  657. width: 485px;
  658. height: 600px;
  659. transform: translate(-50%, -50%);
  660. border-radius: 6px;
  661. background-color: #f0f4f9;
  662. border-collapse: collapse;
  663. border: 1px solid #ffffff;
  664. color: #697e91;
  665. font-family: var(--vp-font-family-base);
  666. padding: 10px 20px 20px 10px;
  667. box-sizing: content-box;
  668. }
  669. .CFBetter_setting_menu h3 {
  670. margin-top: 10px;
  671. }
  672. .CFBetter_setting_menu h4 {
  673. margin: 15px 0px 10px 0px;
  674. }
  675. .CFBetter_setting_menu h4,.CFBetter_setting_menu h5 {
  676. font-weight: 600;
  677. }
  678. .CFBetter_setting_menu hr {
  679. border: none;
  680. height: 1px;
  681. background-color: #ccc;
  682. margin: 10px 0;
  683. }
  684. .CFBetter_setting_menu .badge {
  685. border-radius: 4px;
  686. border: 1px solid #009688;
  687. color: #009688;
  688. font-size: 12px;
  689. padding: 0.5px 4px;
  690. margin-left: 5px;
  691. margin-right: auto;
  692. }
  693. /* 页面切换 */
  694. .settings-page {
  695. display: none;
  696. }
  697. .settings-page.active {
  698. display: block;
  699. }
  700. .CFBetter_setting_container {
  701. display: flex;
  702. }
  703. .CFBetter_setting_sidebar {
  704. width: 100px;
  705. padding: 6px 10px 6px 6px;
  706. margin: 20px 0px;
  707. border-right: 1px solid #d4d8e9;
  708. }
  709. .CFBetter_setting_content {
  710. flex-grow: 1;
  711. width: 350px;
  712. margin: 20px 0px 0px 20px;
  713. padding-right: 10px;
  714. max-height: 580px;
  715. overflow-y: auto;
  716. box-sizing: border-box;
  717. }
  718. .CFBetter_setting_sidebar h3 {
  719. margin-top: 0;
  720. }
  721. .CFBetter_setting_sidebar hr {
  722. margin-top: 10px;
  723. margin-bottom: 10px;
  724. border: none;
  725. border-top: 1px solid #DADCE0;
  726. }
  727. .CFBetter_setting_sidebar ul {
  728. list-style-type: none;
  729. margin: 0;
  730. padding: 0;
  731. }
  732. .CFBetter_setting_sidebar li {
  733. margin: 5px 0px;
  734. background-color: #ffffff;
  735. border: 1px solid #d4d8e9;
  736. border-radius: 4px;
  737. font-size: 16px;
  738. }
  739. .CFBetter_setting_sidebar li a {
  740. text-decoration: none;
  741. display: flex;
  742. width: 100%;
  743. color: gray;
  744. letter-spacing: 2px;
  745. padding: 7px;
  746. border-radius: 4px;
  747. align-items: center;
  748. -webkit-box-sizing: border-box;
  749. -moz-box-sizing: border-box;
  750. box-sizing: border-box;
  751. }
  752. .CFBetter_setting_sidebar li a.active {
  753. background-color: #eceff1c7;
  754. }
  755. /* 下拉选择框 */
  756. .CFBetter_setting_menu select {
  757. margin-left: 6px;
  758. border-style: solid;
  759. border-color: #26A69A;
  760. color: #009688;
  761. font-size: 15px;
  762. }
  763. .CFBetter_setting_menu select:focus-visible {
  764. outline: none;
  765. }
  766. /* 数值输入框 */
  767. .CFBetter_setting_menu input[type="number"] {
  768. width: 60px;
  769. border: 1px solid #26A69A;
  770. color: #009688;
  771. font-size: 15px;
  772. }
  773. .CFBetter_setting_menu input[type="number"]:focus-visible {
  774. outline: none;
  775. }
  776. /*设置面板-滚动条*/
  777. .CFBetter_setting_menu::-webkit-scrollbar, .CFBetter_setting_content::-webkit-scrollbar {
  778. width: 5px;
  779. height: 7px;
  780. background-color: #aaa;
  781. }
  782. .CFBetter_setting_menu::-webkit-scrollbar-thumb, .CFBetter_setting_content::-webkit-scrollbar-thumb {
  783. background-clip: padding-box;
  784. background-color: #d7d9e4;
  785. }
  786. .CFBetter_setting_menu::-webkit-scrollbar-track, .CFBetter_setting_content::-webkit-scrollbar-track {
  787. background-color: #f1f1f1;
  788. }
  789. /*设置面板-关闭按钮*/
  790. .CFBetter_setting_menu .tool-box {
  791. position: absolute;
  792. align-items: center;
  793. justify-content: center;
  794. width: 20px;
  795. height: 20px;
  796. overflow: hidden;
  797. border-radius: 10px;
  798. top: 3px;
  799. right: 3px;
  800. }
  801.  
  802. .CFBetter_setting_menu .btn-close {
  803. display: flex;
  804. text-align: center;
  805. width: 20px;
  806. height: 20px;
  807. color: transparent;
  808. font-size: 0;
  809. cursor: pointer;
  810. background-color: #ff000080;
  811. border: none;
  812. margin: 0px;
  813. padding: 0px;
  814. overflow: hidden;
  815. transition: .15s ease all;
  816. align-items: center;
  817. justify-content: center;
  818. box-sizing: border-box;
  819. }
  820.  
  821. .CFBetter_setting_menu .btn-close:hover {
  822. width: 20px;
  823. height: 20px !important;
  824. font-size: 17px;
  825. color: #ffffff;
  826. background-color: #ff0000cc;
  827. box-shadow: 0 5px 5px 0 #00000026;
  828. }
  829.  
  830. .CFBetter_setting_menu .btn-close:active {
  831. width: 20px;
  832. height: 20px;
  833. font-size: 1px;
  834. color: #ffffffde;
  835. --shadow-btn-close: 0 3px 3px 0 #00000026;
  836. box-shadow: var(--shadow-btn-close);
  837. }
  838.  
  839. /*设置面板-checkbox*/
  840. .CFBetter_setting_menu input[type=checkbox]:focus {
  841. outline: 0px;
  842. }
  843.  
  844. .CFBetter_setting_menu input[type="checkbox"] {
  845. margin: 0px;
  846. appearance: none;
  847. -webkit-appearance: none;
  848. width: 40px;
  849. height: 20px !important;
  850. border: 1.5px solid #D7CCC8;
  851. padding: 0px !important;
  852. border-radius: 20px;
  853. background: #efebe978;
  854. position: relative;
  855. box-sizing: border-box;
  856. }
  857.  
  858. .CFBetter_setting_menu input[type="checkbox"]::before {
  859. content: "";
  860. width: 14px;
  861. height: 14px;
  862. background: #D7CCC8;
  863. border: 1.5px solid #BCAAA4;
  864. border-radius: 50%;
  865. position: absolute;
  866. top: 0;
  867. left: 0;
  868. transform: translate(2%, 2%);
  869. transition: all 0.3s ease-in-out;
  870. }
  871.  
  872. .CFBetter_setting_menu input[type="checkbox"]::after {
  873. content: url("data:image/svg+xml,%3Csvg xmlns='://www.w3.org/2000/svg' width='23' height='23' viewBox='0 0 23 23' fill='none'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M6.55021 5.84315L17.1568 16.4498L16.4497 17.1569L5.84311 6.55026L6.55021 5.84315Z' fill='%23EA0707' fill-opacity='0.89'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M17.1567 6.55021L6.55012 17.1568L5.84302 16.4497L16.4496 5.84311L17.1567 6.55021Z' fill='%23EA0707' fill-opacity='0.89'/%3E%3C/svg%3E");
  874. position: absolute;
  875. top: 0;
  876. left: 24px;
  877. }
  878.  
  879. .CFBetter_setting_menu input[type="checkbox"]:checked {
  880. border: 1.5px solid #C5CAE9;
  881. background: #E8EAF6;
  882. }
  883.  
  884. .CFBetter_setting_menu input[type="checkbox"]:checked::before {
  885. background: #C5CAE9;
  886. border: 1.5px solid #7986CB;
  887. transform: translate(122%, 2%);
  888. transition: all 0.3s ease-in-out;
  889. }
  890.  
  891. .CFBetter_setting_menu input[type="checkbox"]:checked::after {
  892. content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 15 13' fill='none'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M14.8185 0.114533C15.0314 0.290403 15.0614 0.605559 14.8855 0.818454L5.00187 12.5L0.113036 6.81663C-0.0618274 6.60291 -0.0303263 6.2879 0.183396 6.11304C0.397119 5.93817 0.71213 5.96967 0.886994 6.18339L5.00187 11L14.1145 0.181573C14.2904 -0.0313222 14.6056 -0.0613371 14.8185 0.114533Z' fill='%2303A9F4' fill-opacity='0.9'/%3E%3C/svg%3E");
  893. position: absolute;
  894. top: 1.5px;
  895. left: 4.5px;
  896. }
  897.  
  898. .CFBetter_setting_menu label, #darkMode_span, #loaded_span {
  899. font-size: 16px;
  900. }
  901.  
  902. .CFBetter_setting_list {
  903. display: flex;
  904. align-items: center;
  905. padding: 10px;
  906. margin: 5px 0px;
  907. background-color: #ffffff;
  908. border-bottom: 1px solid #c9c6c696;
  909. border-radius: 8px;
  910. justify-content: space-between;
  911. }
  912.  
  913. /*设置面板-radio*/
  914. .CFBetter_setting_menu #translation-settings label {
  915. list-style-type: none;
  916. padding-inline-start: 0px;
  917. overflow-x: auto;
  918. max-width: 100%;
  919. margin: 3px 0px;
  920. }
  921.  
  922. .CFBetter_setting_menu_label_text {
  923. display: flex;
  924. border: 1px dashed #00aeeccc;
  925. height: 35px;
  926. width: 100%;
  927. color: #6e6e6e;
  928. font-weight: 300;
  929. font-size: 14px;
  930. letter-spacing: 2px;
  931. padding: 7px;
  932. margin-bottom: 4px;
  933. align-items: center;
  934. -webkit-box-sizing: border-box;
  935. -moz-box-sizing: border-box;
  936. box-sizing: border-box;
  937. }
  938.  
  939. input[type="radio"]:checked+.CFBetter_setting_menu_label_text {
  940. background: #41e49930;
  941. border: 1px solid green;
  942. color: green;
  943. text-shadow: 0px 0px 0.5px green;
  944. }
  945.  
  946. .CFBetter_setting_menu label input[type="radio"], .CFBetter_contextmenu label input[type="radio"]{
  947. appearance: none;
  948. list-style: none;
  949. padding: 0px !important;
  950. margin: 0px;
  951. clip: rect(0 0 0 0);
  952. -webkit-clip-path: inset(100%);
  953. clip-path: inset(100%);
  954. height: 1px;
  955. overflow: hidden;
  956. position: absolute;
  957. white-space: nowrap;
  958. width: 1px;
  959. }
  960.  
  961. .CFBetter_setting_menu input[type="text"] {
  962. display: block;
  963. height: 25px !important;
  964. width: 100%;
  965. background-color: #ffffff;
  966. color: #727378;
  967. font-size: 12px;
  968. border-radius: 0.3rem;
  969. padding: 1px 5px !important;
  970. box-sizing: border-box;
  971. margin: 5px 0px 5px 0px;
  972. border: 1px solid #00aeeccc;
  973. box-shadow: 0 0 1px #0000004d;
  974. }
  975.  
  976. .CFBetter_setting_menu .CFBetter_setting_list input[type="text"] {
  977. margin-left: 5px;
  978. }
  979.  
  980. .CFBetter_setting_menu input[type="text"]:focus-visible{
  981. border-style: solid;
  982. border-color: #3f51b5;
  983. outline: none;
  984. }
  985.  
  986. .CFBetter_setting_menu_input {
  987. width: 100%;
  988. display: grid;
  989. margin-top: 5px;
  990. -webkit-box-sizing: border-box;
  991. -moz-box-sizing: border-box;
  992. box-sizing: border-box;
  993. }
  994. .CFBetter_setting_menu input::placeholder {
  995. color: #727378;
  996. }
  997. .CFBetter_setting_menu input.no_default::placeholder{
  998. color: #BDBDBD;
  999. }
  1000. .CFBetter_setting_menu input.is_null::placeholder{
  1001. color: red;
  1002. border-width: 1.5px;
  1003. }
  1004. .CFBetter_setting_menu input.is_null{
  1005. border-color: red;
  1006. }
  1007. .CFBetter_setting_menu textarea {
  1008. display: block;
  1009. width: 100%;
  1010. height: 60px;
  1011. background-color: #ffffff;
  1012. color: #727378;
  1013. font-size: 12px;
  1014. padding: 1px 5px !important;
  1015. box-sizing: border-box;
  1016. margin: 5px 0px 5px 0px;
  1017. border: 1px solid #00aeeccc;
  1018. box-shadow: 0 0 1px #0000004d;
  1019. }
  1020. .CFBetter_setting_menu textarea:focus-visible{
  1021. border-style: solid;
  1022. border-color: #3f51b5;
  1023. outline: none;
  1024. }
  1025. .CFBetter_setting_menu textarea::placeholder{
  1026. color: #BDBDBD;
  1027. font-size: 14px;
  1028. }
  1029.  
  1030. .CFBetter_setting_menu #save {
  1031. cursor: pointer;
  1032. display: inline-flex;
  1033. padding: 5px;
  1034. background-color: #1aa06d;
  1035. color: #ffffff;
  1036. font-size: 14px;
  1037. line-height: 1.5rem;
  1038. font-weight: 500;
  1039. justify-content: center;
  1040. width: 100%;
  1041. border-radius: 0.375rem;
  1042. border: none;
  1043. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  1044. margin-top: 20px
  1045. }
  1046. .CFBetter_setting_menu button#debug_button.debug_button {
  1047. width: 18%;
  1048. }
  1049.  
  1050. .CFBetter_setting_menu span.tip {
  1051. color: #999;
  1052. font-size: 12px;
  1053. font-weight: 500;
  1054. padding: 5px 0px;
  1055. }
  1056. /*设置面板-tip*/
  1057. .help_tip {
  1058. margin-right: auto;
  1059. }
  1060. span.input_label {
  1061. font-size: 14px;
  1062. }
  1063. .help_tip .tip_text {
  1064. display: none;
  1065. position: absolute;
  1066. color: #697e91;
  1067. font-weight: 400;
  1068. font-size: 14px;
  1069. letter-spacing: 0px;
  1070. background-color: #ffffff;
  1071. padding: 10px;
  1072. margin: 5px 0px;
  1073. border-radius: 4px;
  1074. border: 1px solid #e4e7ed;
  1075. box-shadow: 0px 0px 12px rgba(0, 0, 0, .12);
  1076. z-index: 100;
  1077. }
  1078. .help_tip .tip_text p {
  1079. margin-bottom: 5px;
  1080. }
  1081. .help_tip .tip_text:before {
  1082. content: "";
  1083. position: absolute;
  1084. top: -20px;
  1085. right: -10px;
  1086. bottom: -10px;
  1087. left: -10px;
  1088. z-index: -1;
  1089. }
  1090. .help-icon {
  1091. cursor: help;
  1092. width: 15px;
  1093. color: #b4b9d4;
  1094. margin-left: 5px;
  1095. margin-top: 3px;
  1096. }
  1097. .CFBetter_setting_menu .CFBetter_setting_menu_label_text .help_tip .help-icon {
  1098. color: #7fbeb2;
  1099. }
  1100. .help_tip .help-icon:hover + .tip_text, .help_tip .tip_text:hover {
  1101. display: block;
  1102. cursor: help;
  1103. width: 250px;
  1104. }
  1105.  
  1106. /*确认弹窗*/
  1107. .CFBetter_modal {
  1108. z-index: 600;
  1109. display: grid;
  1110. position: fixed;
  1111. top: 50%;
  1112. left: 50%;
  1113. transform: translate(-50%, -50%);
  1114. font-size: 12px;
  1115. font-family: var(--vp-font-family-base);
  1116. padding: 10px 20px;
  1117. box-shadow: 0px 0px 0px 4px #ffffff;
  1118. border-radius: 6px;
  1119. background-color: #f0f4f9;
  1120. border-collapse: collapse;
  1121. border: 1px solid #ffffff;
  1122. color: #697e91;
  1123. }
  1124. .CFBetter_modal .buttons{
  1125. display: flex;
  1126. padding-top: 15px;
  1127. }
  1128. .CFBetter_modal button {
  1129. display: inline-flex;
  1130. justify-content: center;
  1131. align-items: center;
  1132. line-height: 1;
  1133. white-space: nowrap;
  1134. cursor: pointer;
  1135. text-align: center;
  1136. box-sizing: border-box;
  1137. outline: none;
  1138. transition: .1s;
  1139. user-select: none;
  1140. vertical-align: middle;
  1141. -webkit-appearance: none;
  1142. height: 24px;
  1143. padding: 5px 11px;
  1144. margin-right: 15px;
  1145. font-size: 12px;
  1146. border-radius: 4px;
  1147. color: #ffffff;
  1148. background: #009688;
  1149. border-color: #009688;
  1150. border: none;
  1151. }
  1152. .CFBetter_modal button#cancelButton{
  1153. background-color:#4DB6AC;
  1154. }
  1155. .CFBetter_modal button:hover{
  1156. background-color:#4DB6AC;
  1157. }
  1158. .CFBetter_modal button#cancelButton:hover {
  1159. background-color: #80CBC4;
  1160. }
  1161. .CFBetter_modal .help-icon {
  1162. margin: 0px 8px 0px 0px;
  1163. height: 1em;
  1164. width: 1em;
  1165. line-height: 1em;
  1166. display: inline-flex;
  1167. justify-content: center;
  1168. align-items: center;
  1169. position: relative;
  1170. fill: currentColor;
  1171. font-size: inherit;
  1172. }
  1173. .CFBetter_modal p {
  1174. margin: 5px 0px;
  1175. }
  1176. /*更新检查*/
  1177. div#update_panel {
  1178. z-index: 200;
  1179. position: fixed;
  1180. top: 50%;
  1181. left: 50%;
  1182. width: 240px;
  1183. transform: translate(-50%, -50%);
  1184. box-shadow: 0px 0px 4px 0px #0000004d;
  1185. padding: 10px 20px 20px 20px;
  1186. color: #444242;
  1187. background-color: #f5f5f5;
  1188. border: 1px solid #848484;
  1189. border-radius: 8px;
  1190. }
  1191. div#update_panel #updating {
  1192. cursor: pointer;
  1193. display: inline-flex;
  1194. padding: 3px;
  1195. background-color: #1aa06d;
  1196. color: #ffffff;
  1197. font-size: 14px;
  1198. line-height: 1.5rem;
  1199. font-weight: 500;
  1200. justify-content: center;
  1201. width: 100%;
  1202. border-radius: 0.375rem;
  1203. border: none;
  1204. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  1205. }
  1206. div#update_panel #updating a {
  1207. text-decoration: none;
  1208. color: white;
  1209. display: flex;
  1210. position: inherit;
  1211. top: 0;
  1212. left: 0;
  1213. width: 100%;
  1214. height: 22px;
  1215. font-size: 14px;
  1216. justify-content: center;
  1217. align-items: center;
  1218. }
  1219. #skip_menu {
  1220. display: flex;
  1221. margin-top: 10px;
  1222. justify-content: flex-end;
  1223. align-items: center;
  1224. }
  1225. #skip_menu .help_tip {
  1226. margin-right: 5px;
  1227. margin-left: -5px;
  1228. }
  1229. #skip_menu .help-icon {
  1230. color: #f44336;
  1231. }
  1232. /* 配置管理 */
  1233. .embed-responsive {
  1234. height: max-content;
  1235. padding-bottom: 0px;
  1236. }
  1237. .config_bar {
  1238. height: 70px;
  1239. width: 100%;
  1240. display: flex;
  1241. justify-content: space-between;
  1242. }
  1243. li#add_button {
  1244. cursor: pointer;
  1245. height: 40px;
  1246. border: 1px dashed #BDBDBD;
  1247. border-radius: 8px;
  1248. background-color: #fcfbfb36;
  1249. color: #bdbdbd;
  1250. font-size: 14px;
  1251. align-items: center;
  1252. justify-content: center;
  1253. }
  1254. li#add_button:hover {
  1255. border: 1px dashed #03A9F4;
  1256. background-color: #d7f0fb8c;
  1257. color: #03A9F4;
  1258. }
  1259. div#config_bar_list {
  1260. display: flex;
  1261. width: 335px;
  1262. border: 1px solid #c5cae9;
  1263. border-radius: 8px;
  1264. background-color: #f0f8ff;
  1265. box-sizing: border-box;
  1266. }
  1267. div#config_bar_list input[type="radio"] {
  1268. appearance: none;
  1269. width: 0;
  1270. height: 0;
  1271. overflow: hidden;
  1272. }
  1273. div#config_bar_list input[type="radio"] {
  1274. margin: 0px;
  1275. }
  1276. div#config_bar_list input[type=radio]:focus {
  1277. outline: 0px;
  1278. }
  1279. label.config_bar_ul_li_text {
  1280. display: flex;
  1281. align-items: center;
  1282. justify-content: center;
  1283. max-width: 100%;
  1284. height: 40px;
  1285. overflow-x: auto;
  1286. font-size: 14px;
  1287. font-weight: 400;
  1288. margin: 0px 4px;
  1289. padding: 3px;
  1290. border: 1px solid #dedede;
  1291. border-radius: 10px;
  1292. box-shadow: 0px 2px 4px 0px rgba(0,0,0,.05);
  1293. box-sizing: border-box;
  1294. }
  1295. ul#config_bar_ul li button {
  1296. background-color: #e6e6e6;
  1297. color: #727378;
  1298. height: 23px;
  1299. font-size: 14px;
  1300. border-radius: 0.3rem;
  1301. padding: 1px 5px;
  1302. margin: 5px;
  1303. border: none;
  1304. box-shadow: 0 0 1px #0000004d;
  1305. }
  1306. ul#config_bar_ul {
  1307. display: flex;
  1308. align-items: center;
  1309. list-style-type: none;
  1310. padding-inline-start: 0px;
  1311. overflow-x: auto;
  1312. max-width: 100%;
  1313. margin: 0px;
  1314. }
  1315. ul#config_bar_ul li {
  1316. width: 80px;
  1317. display: grid;
  1318. margin: 4px 4px;
  1319. min-width: 100px;
  1320. box-sizing: border-box;
  1321. }
  1322. label.config_bar_ul_li_text:hover {
  1323. background-color: #eae4dc24;
  1324. }
  1325. input[type="radio"]:checked + .config_bar_ul_li_text {
  1326. background: #41b3e430;
  1327. border: 1px solid #5e7ce0;
  1328. color: #5e7ce0;
  1329. }
  1330. ul#config_bar_ul::-webkit-scrollbar {
  1331. width: 5px;
  1332. height: 3px;
  1333. }
  1334. ul#config_bar_ul::-webkit-scrollbar-thumb {
  1335. background-clip: padding-box;
  1336. background-color: #d7d9e4;
  1337. border-radius: 8px;
  1338. }
  1339. ul#config_bar_ul::-webkit-scrollbar-button:start:decrement {
  1340. width: 4px;
  1341. background-color: transparent;
  1342. }
  1343. ul#config_bar_ul::-webkit-scrollbar-button:end:increment {
  1344. width: 4px;
  1345. background-color: transparent;
  1346. }
  1347. ul#config_bar_ul::-webkit-scrollbar-track {
  1348. border-radius: 5px;
  1349. }
  1350. label.config_bar_ul_li_text::-webkit-scrollbar {
  1351. width: 5px;
  1352. height: 7px;
  1353. background-color: #aaa;
  1354. }
  1355. label.config_bar_ul_li_text::-webkit-scrollbar-thumb {
  1356. background-clip: padding-box;
  1357. background-color: #d7d9e4;
  1358. }
  1359. label.config_bar_ul_li_text::-webkit-scrollbar-track {
  1360. background-color: #f1f1f1;
  1361. }
  1362. .config_bar_list_add_div {
  1363. display: flex;
  1364. height: 40px;
  1365. margin: 4px 2px;
  1366. }
  1367. /* 修改菜单 */
  1368. div#config_bar_menu {
  1369. z-index: 400;
  1370. position: absolute;
  1371. width: 60px;
  1372. background: #ffffff;
  1373. box-shadow: 1px 1px 4px 0px #0000004d;
  1374. border: 0px solid rgba(0,0,0,0.04);
  1375. border-radius: 4px;
  1376. padding: 8px 0;
  1377. }
  1378. div.config_bar_menu_item {
  1379. cursor: pointer;
  1380. padding: 2px 6px;
  1381. display: flex;
  1382. justify-content: center;
  1383. align-items: center;
  1384. height: 32px;
  1385. color: rgba(0,0,0,0.75);
  1386. font-size: 14px;
  1387. font-weight: 500;
  1388. box-shadow: inset 0px 0px 0px 0px #8bb2d9;
  1389. }
  1390. div#config_bar_menu_edit:hover {
  1391. background-color: #00aeec;
  1392. color: white;
  1393. }
  1394. div#config_bar_menu_delete:hover {
  1395. background-color: #FF5722;
  1396. color: white;
  1397. }
  1398. /* 配置页面 */
  1399. #config_edit_menu {
  1400. z-index: 300;
  1401. width: 450px;
  1402. }
  1403. /* 黑暗模式选项 */
  1404. .dark-mode-selection {
  1405. display: flex;
  1406. justify-content: center;
  1407. align-items: center;
  1408. max-width: 350px;
  1409. -webkit-user-select: none;
  1410. -moz-user-select: none;
  1411. -ms-user-select: none;
  1412. user-select: none;
  1413. }
  1414. .dark-mode-selection > * {
  1415. margin: 6px;
  1416. }
  1417. .dark-mode-selection .CFBetter_setting_menu_label_text {
  1418. border-radius: 8px;
  1419. }
  1420. /* 右键菜单 */
  1421. .CFBetter_contextmenu {
  1422. z-index: 500;
  1423. display: grid;
  1424. position: absolute;
  1425. background-color: #f0f4f9;
  1426. border-collapse: collapse;
  1427. color: #697e91;
  1428. font-family: var(--vp-font-family-base);
  1429. overflow: hidden;
  1430. box-sizing: content-box;
  1431. box-shadow: 0px 0px 0px 2px #eddbdb4d;
  1432. }
  1433. input[type="radio"]:checked+.CFBetter_contextmenu_label_text {
  1434. background: #41e49930;
  1435. border: 1px solid green;
  1436. color: green;
  1437. font-weight: 500;
  1438. }
  1439. .CFBetter_contextmenu_label_text {
  1440. display: flex;
  1441. border: 1px dashed #80cbc4;
  1442. height: 26px;
  1443. width: 100%;
  1444. color: gray;
  1445. font-size: 13px;
  1446. padding: 4px;
  1447. align-items: center;
  1448. -webkit-box-sizing: border-box;
  1449. -moz-box-sizing: border-box;
  1450. box-sizing: border-box;
  1451. }
  1452. .CFBetter_contextmenu_label_text:hover {
  1453. color: #F44336;
  1454. border: 1px dashed #009688;
  1455. background-color: #ffebcd;
  1456. }
  1457. /* RatingByClist */
  1458. .ratingBadges, html[data-theme=dark] button.ratingBadges{
  1459. font-weight: 700;
  1460. margin-top: 5px;
  1461. border-radius: 4px;
  1462. color: #ffffff00;
  1463. border: 1px solid #cccccc66;
  1464. }
  1465. /* 多选翻译 */
  1466. .block_selected{
  1467. box-shadow: 0px 0px 0px 1px #FF9800;
  1468. outline: none;
  1469. }
  1470. /* 悬浮菜单 */
  1471. .CFBetter_MiniTranslateButton {
  1472. z-index: 100;
  1473. display: grid;
  1474. position: absolute;
  1475. border-collapse: collapse;
  1476. fill: #F57C00;
  1477. background-color: #FFF3E0;
  1478. overflow: hidden;
  1479. box-sizing: content-box;
  1480. box-shadow: 0px 0px 0px 2px #FFE0B2;
  1481. border-radius: 100%;
  1482. }
  1483. .CFBetter_MiniTranslateButton:hover {
  1484. cursor: pointer;
  1485. box-shadow: 0px 0px 0px 2px #FFB74D;
  1486. }
  1487. /* acmsguru划分块 */
  1488. .CFBetter_acmsguru {
  1489. margin: 0 0 1em!important;
  1490. }
  1491. /* 移动设备 */
  1492. @media (max-device-width: 450px) {
  1493. button.html2mdButton{
  1494. height: 2em;
  1495. font-size: 1.2em;
  1496. }
  1497. button.html2mdButton.CFBetter_setting{
  1498. height: 2.5em;
  1499. font-size: 1em;
  1500. }
  1501. .CFBetter_setting_menu{
  1502. width: 90%;
  1503. }
  1504. .CFBetter_setting_menu label, #darkMode_span, #loaded_span, .CFBetter_setting_menu_label_text,
  1505. .CFBetter_setting_sidebar li{
  1506. font-size: 1em;
  1507. }
  1508. .translate-problem-statement{
  1509. font-size: 1.2em;
  1510. }
  1511. .CFBetter_modal{
  1512. font-size: 1.5em;
  1513. }
  1514. .CFBetter_setting_list, .translate-problem-statement{
  1515. padding: 0.5em;
  1516. }
  1517. .CFBetter_setting_menu_label_text{
  1518. height: 2.5em;
  1519. padding: 0.5em;
  1520. }
  1521. #pagBar #jump-input, #pagBar #items-per-page, .CFBetter_modal button{
  1522. height: 2.5em;
  1523. font-size: 1em;
  1524. }
  1525. .translate-problem-statement p, .translate-problem-statement ul li{
  1526. line-height: 1.5em !important;
  1527. }
  1528. .CFBetter_contextmenu_label_text{
  1529. height: 3em;
  1530. font-size: 1em;
  1531. }
  1532. }
  1533. `);
  1534.  
  1535. // 工具
  1536. // 获取cookie
  1537. function getCookie(name) {
  1538. const cookies = document.cookie.split(";");
  1539. for (let i = 0; i < cookies.length; i++) {
  1540. const cookie = cookies[i].trim();
  1541. const [cookieName, cookieValue] = cookie.split("=");
  1542.  
  1543. if (cookieName === name) {
  1544. return decodeURIComponent(cookieValue);
  1545. }
  1546. }
  1547. return "";
  1548. }
  1549.  
  1550. // 防抖函数
  1551. function debounce(callback) {
  1552. let timer;
  1553. let immediateExecuted = false;
  1554. const delay = 500;
  1555. return function () {
  1556. clearTimeout(timer);
  1557. if (!immediateExecuted) { callback.call(this); immediateExecuted = true; }
  1558. timer = setTimeout(() => { immediateExecuted = false; }, delay);
  1559. };
  1560. }
  1561.  
  1562. // 为元素添加鼠标拖动
  1563. function addDraggable(element) {
  1564. let isDragging = false;
  1565. let initialX, initialY; // 元素的初始位置
  1566. let startX, startY, offsetX, offsetY; // 鼠标起始位置,移动偏移量
  1567. let isSpecialMouseDown = false; // 选取某些元素时不拖动
  1568.  
  1569. element.on('mousedown', function (e) {
  1570. var elem = $(this);
  1571. var elemOffset = elem.offset();
  1572. var centerX = elemOffset.left + elem.outerWidth() / 2;
  1573. var centerY = elemOffset.top + elem.outerHeight() / 2;
  1574. initialX = centerX - window.pageXOffset;
  1575. initialY = centerY - window.pageYOffset;
  1576.  
  1577. isDragging = true;
  1578. startX = e.clientX;
  1579. startY = e.clientY;
  1580.  
  1581. isSpecialMouseDown = $(e.target).is('label, p, input, textarea, span, select');
  1582. if (isSpecialMouseDown) return;
  1583. $('body').css('cursor', 'all-scroll');
  1584. });
  1585.  
  1586. $(document).on('mousemove', function (e) {
  1587. if (!isDragging) return;
  1588. // 不执行拖动操作
  1589. if ($(e.target).is('label, p, input, textarea, span') || isSpecialMouseDown && !$(e.target).is('input, textarea')) return;
  1590. e.preventDefault();
  1591. offsetX = e.clientX - startX;
  1592. offsetY = e.clientY - startY;
  1593. element.css({ top: initialY + offsetY + 'px', left: initialX + offsetX + 'px' });
  1594. });
  1595.  
  1596. $(document).on('mouseup', function () {
  1597. isDragging = false;
  1598. isSpecialMouseDown = false;
  1599. $('body').css('cursor', 'default');
  1600. });
  1601. }
  1602.  
  1603. // 更新检查
  1604. function checkScriptVersion() {
  1605. function compareVersions(version1 = "0", version2 = "0") {
  1606. const v1Array = String(version1).split(".");
  1607. const v2Array = String(version2).split(".");
  1608. const minLength = Math.min(v1Array.length, v2Array.length);
  1609. let result = 0;
  1610. for (let i = 0; i < minLength; i++) {
  1611. const curV1 = Number(v1Array[i]);
  1612. const curV2 = Number(v2Array[i]);
  1613. if (curV1 > curV2) {
  1614. result = 1;
  1615. break;
  1616. } else if (curV1 < curV2) {
  1617. result = -1;
  1618. break;
  1619. }
  1620. }
  1621. if (result === 0 && v1Array.length !== v2Array.length) {
  1622. const v1IsBigger = v1Array.length > v2Array.length;
  1623. const maxLenArray = v1IsBigger ? v1Array : v2Array;
  1624. for (let i = minLength; i < maxLenArray.length; i++) {
  1625. const curVersion = Number(maxLenArray[i]);
  1626. if (curVersion > 0) {
  1627. v1IsBigger ? result = 1 : result = -1;
  1628. break;
  1629. }
  1630. }
  1631. }
  1632. return result;
  1633. }
  1634.  
  1635. GM_xmlhttpRequest({
  1636. method: "GET",
  1637. url: "https://gf.qytechs.cn/zh-CN/scripts/465777.json",
  1638. timeout: 10 * 1e3,
  1639. onload: function (response) {
  1640. const scriptData = JSON.parse(response.responseText);
  1641. const skipUpdate = getCookie("skipUpdate");
  1642.  
  1643. if (
  1644. scriptData.name === GM_info.script.name &&
  1645. compareVersions(scriptData.version, GM_info.script.version) === 1 &&
  1646. skipUpdate !== "true"
  1647. ) {
  1648. const styleElement = GM_addStyle(darkenPageStyle);
  1649. $("body").append(`
  1650. <div id='update_panel'>
  1651. <h3>${GM_info.script.name}有新版本!</h3>
  1652. <hr>
  1653. <div class='update_panel_menu'>
  1654. <span class ='tip'>版本信息:${GM_info.script.version} ${scriptData.version}</span>
  1655. </div>
  1656. <br>
  1657. <div id="skip_menu">
  1658. <div class="help_tip">
  1659. `+ helpCircleHTML + `
  1660. <div class="tip_text">
  1661. <p><b>更新遇到了问题?</b></p>
  1662. <p>由于 Greasyfork 平台的原因,当新版本刚发布时,点击 Greasyfork 上的更新按钮<u>可能</u>会出现<u>实际更新/安装的却是上一个版本</u>的情况</p>
  1663. <p>通常你只需要稍等几分钟,然后再次前往更新/安装即可</p>
  1664. <p>你也可以<u>点击下方按钮,在本次浏览器会话期间将不再提示更新</u></p>
  1665. <button id='skip_update' class='html2mdButton'>暂不更新</button>
  1666. </div>
  1667. </div>
  1668. <button id='updating'><a target="_blank" href="${scriptData.url}">更新</a></button>
  1669. </div>
  1670. </div>
  1671. `);
  1672.  
  1673. $("#skip_update").click(function () {
  1674. document.cookie = "skipUpdate=true; expires=session; path=/";
  1675. styleElement.remove();
  1676. $("#update_panel").remove();
  1677. });
  1678. }
  1679. }
  1680. });
  1681.  
  1682. };
  1683.  
  1684. // 汉化替换
  1685. function toZH_CN() {
  1686. if (!bottomZh_CN) return;
  1687. // 设置语言为zh
  1688. var htmlTag = document.getElementsByTagName("html")[0];
  1689. htmlTag.setAttribute("lang", "zh-CN");
  1690.  
  1691. // 文本节点遍历替换
  1692. function traverseTextNodes(node, rules) {
  1693. if (!node) return;
  1694. if (node.nodeType === Node.TEXT_NODE) {
  1695. rules.forEach(rule => {
  1696. const regex = new RegExp(rule.match, 'g');
  1697. node.textContent = node.textContent.replace(regex, rule.replace);
  1698. });
  1699. } else {
  1700. $(node).contents().each((_, child) => traverseTextNodes(child, rules));
  1701. }
  1702. }
  1703.  
  1704. // 严格
  1705. function strictTraverseTextNodes(node, rules) {
  1706. if (!node) return;
  1707. if (node.nodeType === Node.TEXT_NODE) {
  1708. const nodeText = node.textContent.trim();
  1709. rules.forEach(rule => {
  1710. if (nodeText === rule.match) {
  1711. node.textContent = rule.replace;
  1712. }
  1713. });
  1714. } else {
  1715. $(node).contents().each((_, child) => strictTraverseTextNodes(child, rules));
  1716. }
  1717. }
  1718.  
  1719. const rules1 = [
  1720. { match: 'Virtual participation', replace: '参加虚拟重现赛' },
  1721. { match: 'Enter', replace: '进入' },
  1722. { match: 'Current standings', replace: '当前榜单' },
  1723. { match: 'Final standings', replace: '最终榜单' },
  1724. { match: 'Preliminary results', replace: '初步结果' },
  1725. { match: 'open hacking:', replace: '公开黑客攻击中' },
  1726. { match: 'School/University/City/Region Championship', replace: '学校/大学/城市/区域比赛' },
  1727. { match: 'Official School Contest', replace: '学校官方比赛' },
  1728. { match: 'Training Contest', replace: '训练赛' },
  1729. { match: 'Training Camp Contest', replace: '训练营比赛' },
  1730. { match: 'Official ICPC Contest', replace: 'ICPC官方比赛' },
  1731. { match: 'Official International Personal Contest', replace: '官方国际个人赛' },
  1732. { match: 'China', replace: '中国' },
  1733. { match: 'Statements', replace: '题目描述' },
  1734. { match: 'in Chinese', replace: '中文' },
  1735. { match: 'Trainings', replace: '训练' },
  1736. { match: 'Prepared by', replace: '编写人' },
  1737. { match: 'Current or upcoming contests', replace: '当前或即将举行的比赛' },
  1738. { match: 'Past contests', replace: '过去的比赛' },
  1739. { match: 'Exclusions', replace: '排除' },
  1740. { match: 'Before start', replace: '距比赛开始还有' },
  1741. { match: 'Before registration', replace: '距报名开始还有' },
  1742. { match: 'Until closing ', replace: '距报名结束还有' },
  1743. { match: 'Before extra registration', replace: '额外报名还未开始' },
  1744. { match: 'Register »', replace: '报名 »' },
  1745. { match: 'Registration completed', replace: '已报名' },
  1746. { match: 'Registration closed', replace: '报名已结束' },
  1747. { match: 'Problems', replace: '问题集' },
  1748. { match: 'Questions about problems', replace: '关于问题的提问' },
  1749. { match: 'Contest status', replace: '比赛状态' },
  1750. ];
  1751. traverseTextNodes($('.datatable'), rules1);
  1752.  
  1753. const rules2 = [
  1754. { match: 'Home', replace: '主页' },
  1755. { match: 'Top', replace: '热门' },
  1756. { match: 'Catalog', replace: '指南目录' },
  1757. { match: 'Contests', replace: '比赛' },
  1758. { match: 'Gym', replace: '训练营' },
  1759. { match: 'Problemset', replace: '题单' },
  1760. { match: 'Groups', replace: '团体' },
  1761. { match: 'Rating', replace: 'Rating(评级)排行榜' },
  1762. { match: 'Edu', replace: '培训' },
  1763. { match: 'Calendar', replace: '日历' },
  1764. { match: 'Help', replace: '帮助' }
  1765. ];
  1766. traverseTextNodes($('.menu-list.main-menu-list'), rules2);
  1767.  
  1768. const rules3 = [
  1769. { match: 'Settings', replace: '设置' },
  1770. { match: 'Blog', replace: '博客' },
  1771. { match: 'Teams', replace: '队伍' },
  1772. { match: 'Submissions', replace: '提交' },
  1773. { match: 'Favourites', replace: '收藏' },
  1774. { match: 'Talks', replace: '私信' },
  1775. { match: 'Contests', replace: '比赛' },
  1776. ];
  1777. traverseTextNodes($('.nav-links'), rules3);
  1778.  
  1779. const rules4 = [
  1780. { match: 'Before contest', replace: '即将进行的比赛' },
  1781. { match: 'Contest is running', replace: '比赛进行中' },
  1782. ];
  1783. traverseTextNodes($('.contest-state-phase'), rules4);
  1784.  
  1785. const rules5 = [
  1786. { match: 'has extra registration', replace: '有额外的报名时期' },
  1787. { match: 'If you are late to register in 5 minutes before the start, you can register later during the extra registration. Extra registration opens 10 minutes after the contest starts and lasts 25 minutes.', replace: '如果您在比赛开始前5分钟前还未报名,您可以在额外的报名期间稍后报名。额外的报名将在比赛开始后10分钟开放,并持续25分钟。' },
  1788. ];
  1789. traverseTextNodes($('.notice'), rules5);
  1790.  
  1791. const rules6 = [
  1792. { match: 'Contribution', replace: '贡献' },
  1793. ];
  1794. traverseTextNodes($('.propertyLinks'), rules6);
  1795.  
  1796. const rules7 = [
  1797. { match: 'Contest history', replace: '比赛历史' },
  1798. ];
  1799. traverseTextNodes($('.contests-table'), rules7);
  1800.  
  1801. const rules8 = [
  1802. { match: 'Register now', replace: '现在报名' },
  1803. { match: 'No tag edit access', replace: '没有标签编辑权限' },
  1804. { match: 'Language:', replace: '语言:' },
  1805. { match: 'Choose file:', replace: '选择文件:' },
  1806. ];
  1807. traverseTextNodes($('.roundbox.sidebox.borderTopRound '), rules8);
  1808.  
  1809. const rules9 = [
  1810. { match: 'Add to exclusions', replace: '添加到排除列表' },
  1811. ];
  1812. traverseTextNodes($('.icon-eye-close.icon-large'), rules9);
  1813.  
  1814. const rules10 = [
  1815. { match: 'Add to exclusions for gym contests filter', replace: '添加训练营过滤器的排除项' },
  1816. ];
  1817. traverseTextNodes($("._ContestFilterExclusionsManageFrame_addExclusionLink"), rules10);
  1818.  
  1819. const rules11 = [
  1820. { match: 'Announcement', replace: '公告' },
  1821. { match: 'Statements', replace: '统计报表' },
  1822. { match: 'Tutorial', replace: '题解' },
  1823. ];
  1824. traverseTextNodes($('.roundbox.sidebox.sidebar-menu.borderTopRound '), rules11);
  1825.  
  1826. const rules12 = [
  1827. { match: 'Problems', replace: '问题' },
  1828. { match: 'Submit Code', replace: '提交代码' },
  1829. { match: 'My Submissions', replace: '我的提交' },
  1830. { match: 'Status', replace: '状态' },
  1831. { match: 'Standings', replace: '榜单' },
  1832. { match: 'Custom Invocation', replace: '自定义调试' },
  1833. { match: 'Common standings', replace: '全部排行' },
  1834. { match: 'Friends standings', replace: '只看朋友' },
  1835. { match: 'Submit', replace: '提交' },
  1836. { match: 'Hacks', replace: '黑客' },
  1837. { match: 'Room', replace: '房间' },
  1838. { match: 'Custom test', replace: '自定义测试' },
  1839. { match: 'Blog', replace: '博客' },
  1840. { match: 'Teams', replace: '队伍' },
  1841. { match: 'Submissions', replace: '提交记录' },
  1842. { match: 'Groups', replace: '团体' },
  1843. { match: 'Favourites', replace: '收藏' },
  1844. { match: 'Contests', replace: '比赛' },
  1845. { match: 'Members', replace: '成员' },
  1846. { match: '问题etting', replace: '参与编写的问题' },
  1847. { match: 'Streams', replace: '直播' },
  1848. { match: 'Gym', replace: '训练营' },
  1849. { match: 'Mashups', replace: '组合混搭' },
  1850. { match: 'Posts', replace: '帖子' },
  1851. { match: 'Comments', replace: '回复' },
  1852. { match: 'Main', replace: '主要的' },
  1853. { match: 'Settings', replace: '设置' },
  1854. { match: 'Lists', replace: '列表' },
  1855. { match: 'General', replace: '基本' },
  1856. { match: 'Sidebar', replace: '侧边栏' },
  1857. { match: 'Social', replace: '社会信息' },
  1858. { match: 'Address', replace: '地址' },
  1859. { match: 'Wallets', replace: '钱包' },
  1860. ];
  1861. traverseTextNodes($('.second-level-menu'), rules12);
  1862. if (is_mSite) {
  1863. traverseTextNodes($('nav'), rules12);
  1864. }
  1865.  
  1866. const rules13 = [
  1867. { match: 'Expand', replace: '展开' }
  1868. ];
  1869. traverseTextNodes($('.topic-toggle-collapse'), rules13);
  1870.  
  1871. const rules14 = [
  1872. { match: 'Full text and comments', replace: '阅读全文/评论' }
  1873. ];
  1874. traverseTextNodes($('.topic-read-more'), rules14);
  1875.  
  1876. const rules15 = [
  1877. { match: 'Switch off editor', replace: '关闭编辑器语法高亮' }
  1878. ];
  1879. traverseTextNodes($('.toggleEditorCheckboxLabel'), rules15);
  1880.  
  1881. const rules16 = [
  1882. { match: 'Registration for the contest', replace: '比赛报名' }
  1883. ];
  1884. traverseTextNodes($('.submit'), rules16);
  1885.  
  1886. const rules17 = [
  1887. { match: 'Difficulty:', replace: '难度:' },
  1888. ];
  1889. traverseTextNodes($('._FilterByTagsFrame_difficulty'), rules17);
  1890.  
  1891. const rules18 = [
  1892. { match: 'Add tag', replace: '添加标签' }
  1893. ];
  1894. traverseTextNodes($('._FilterByTagsFrame_addTagLink'), rules18);
  1895.  
  1896. const rules19 = [
  1897. { match: 'Rating changes for last rounds are temporarily rolled back. They will be returned soon.', replace: '上一轮的评级变化暂时回滚。它们将很快恢复。' },
  1898. { match: 'Reminder: in case of any technical issues, you can use the lightweight website', replace: '提醒:如果出现任何技术问题,您可以使用轻量网站' },
  1899. { match: 'Please subscribe to the official Codeforces channel in Telegram via the link ', replace: '请通过链接订阅Codeforces的官方Telegram频道' }
  1900. ];
  1901. traverseTextNodes($('.alert'), rules19);
  1902.  
  1903. const rules20 = [
  1904. { match: 'Enter', replace: '登录(不可用)' },
  1905. { match: 'Register', replace: '注册(不可用)' },
  1906. { match: 'Contest rating', replace: '测试 rating' },
  1907. { match: 'Logout', replace: '退出登录(不可用)' }
  1908. ];
  1909. traverseTextNodes($('.lang-chooser'), rules20);
  1910.  
  1911. const rules21 = [
  1912. { match: 'Change photo', replace: '更换图片' },
  1913. { match: 'Contest rating', replace: '比赛Rating' },
  1914. { match: 'Contribution', replace: '贡献' },
  1915. { match: 'My friends', replace: '我的好友' },
  1916. { match: 'Change settings', replace: '改变设置' },
  1917. { match: 'Last visit', replace: '最后访问' },
  1918. { match: 'Registered', replace: '注册(不可用)于' },
  1919. { match: 'Blog entries', replace: '博客条目' },
  1920. { match: 'comments', replace: '评论' },
  1921. { match: 'Write new entry', replace: '编写新条目' },
  1922. { match: 'View my talks', replace: '查看我的私信' },
  1923. { match: 'Talks', replace: '私信' },
  1924. { match: 'Send message', replace: '发送消息' },
  1925. ];
  1926. traverseTextNodes($('.userbox'), rules21);
  1927.  
  1928. const rules22 = [
  1929. { match: 'Reset', replace: '重置' },
  1930. ];
  1931. traverseTextNodes($('#vote-reset-filterDifficultyLowerBorder'), rules22);
  1932. traverseTextNodes($('#vote-reset-filterDifficultyUpperBorder'), rules22);
  1933.  
  1934. const rules23 = [
  1935. { match: 'The problem statement has recently been changed.', replace: '题目描述最近已被更改。' },
  1936. { match: 'View the changes.', replace: '查看更改' },
  1937. ];
  1938. traverseTextNodes($('.alert.alert-info'), rules23);
  1939.  
  1940. const rules24 = [
  1941. { match: 'Fill in the form to login into Codeforces.', replace: '填写表单以登录(不可用)到Codeforces。' },
  1942. { match: 'You can use', replace: '你也可以使用' },
  1943. { match: 'as an alternative way to enter.', replace: '登录(不可用)' },
  1944. ];
  1945. traverseTextNodes($('.enterPage'), rules24);
  1946.  
  1947. const rules25 = [
  1948. { match: '\\* To view the complete list, click ', replace: '* 要查看完整列表,请点击' },
  1949. ];
  1950. traverseTextNodes($('.notice.small'), rules25);
  1951.  
  1952. const rules26 = [
  1953. { match: 'Contest type:', replace: '比赛类型:' },
  1954. { match: 'Rated:', replace: '已评级:' },
  1955. { match: 'Tried:', replace: '已尝试' },
  1956. { match: 'Substring:', replace: '关键字' },
  1957. ];
  1958. traverseTextNodes($('.setting-name'), rules26);
  1959.  
  1960. const rules27 = [
  1961. { match: 'Sort by:', replace: '排序依据:' },
  1962. { match: 'relevance', replace: '相关' },
  1963. { match: 'popularity', replace: '热度' },
  1964. { match: 'time', replace: '时间' },
  1965. ];
  1966. traverseTextNodes($('.by-form'), rules27);
  1967.  
  1968. // 元素选择替换
  1969. // 侧栏titled汉化
  1970. (function () {
  1971. var translations = {
  1972. "Pay attention": "→ 注意",
  1973. "Top rated": "→ 评级排行",
  1974. "Top contributors": "→ 贡献者排行",
  1975. "Find user": "→ 查找用户",
  1976. "Recent actions": "→ 最新动态",
  1977. "Training filter": "→ 过滤筛选",
  1978. "Find training": "→ 搜索比赛/问题",
  1979. "Virtual participation": "→ 什么是虚拟参赛",
  1980. "Contest materials": "→ 比赛相关资料",
  1981. "Settings": "→ 设置",
  1982. "Create Mashup Contest": "→ 克隆比赛到组合混搭",
  1983. "Clone Contest to Mashup": "→ 克隆比赛到组合混搭",
  1984. "Create Mashup Contest": "→ 创建混搭比赛",
  1985. "Submit": "→ 提交",
  1986. "Practice": "→ 练习",
  1987. "Problem tags": "→ 问题标签",
  1988. "Filter Problems": "→ 过滤问题",
  1989. "Attention": "→ 注意",
  1990. "Past contests filter": "→ 过去的比赛筛选",
  1991. "About Contest": "→ 关于比赛",
  1992. "Last submissions": "→ 提交历史",
  1993. "Streams": "→ 直播",
  1994. "Coach rights": "→ 教练权限",
  1995. "Advices to fill address": "→ 填写地址的建议",
  1996. "Hacks filter": "→ 黑客过滤器",
  1997. "Score table": "→ 评分表",
  1998. "Contests": "→ 比赛",
  1999. "History": "→ 编辑历史",
  2000. "Login into Codeforces": "登录(不可用) Codeforces",
  2001. };
  2002.  
  2003. $(".caption.titled").each(function () {
  2004. var tag = $(this).text();
  2005. for (var property in translations) {
  2006. if (tag.match(property)) {
  2007. $(this).addClass(property);
  2008. $(this).text(translations[property]);
  2009. break;
  2010. }
  2011. }
  2012. });
  2013. })();
  2014. // 题目Tag汉化
  2015. (function () {
  2016. var parentElement = $('._FilterByTagsFrame_addTagLabel');
  2017. var selectElement = parentElement.find('select');
  2018. var translations = {
  2019. "*combine tags by OR": "*按逻辑或组合我选择的标签",
  2020. "combine-tags-by-or": "*按逻辑或组合我选择的标签(combine-tags-by-or)",
  2021. "2-sat": "二分图可满足性问题(2-sat)",
  2022. "binary search": "二分搜索(binary search)",
  2023. "bitmasks": "位掩码(bitmasks)",
  2024. "brute force": "暴力枚举(brute force)",
  2025. "chinese remainder theorem": "中国剩余定理(chinese remainder theorem)",
  2026. "combinatorics": "组合数学(combinatorics)",
  2027. "constructive algorithms": "构造算法(constructive algorithms)",
  2028. "data structures": "数据结构(data structures)",
  2029. "dfs and similar": "深度优先搜索及其变种(dfs and similar)",
  2030. "divide and conquer": "分治算法(divide and conquer)",
  2031. "dp": "动态规划(dp)",
  2032. "dsu": "并查集(dsu)",
  2033. "expression parsing": "表达式解析(expression parsing)",
  2034. "fft": "快速傅里叶变换(fft)",
  2035. "flows": "流(flows)",
  2036. "games": "博弈论(games)",
  2037. "geometry": "计算几何(geometry)",
  2038. "graph matchings": "图匹配(graph matchings)",
  2039. "graphs": "图论(graphs)",
  2040. "greedy": "贪心策略(greedy)",
  2041. "hashing": "哈希表(hashing)",
  2042. "implementation": "实现问题,编程技巧,模拟(implementation)",
  2043. "interactive": "交互性问题(interactive)",
  2044. "math": "数学(math)",
  2045. "matrices": "矩阵(matrices)",
  2046. "meet-in-the-middle": "meet-in-the-middle算法(meet-in-the-middle)",
  2047. "number theory": "数论(number theory)",
  2048. "probabilities": "概率论(probabilities)",
  2049. "schedules": "调度算法(schedules)",
  2050. "shortest paths": "最短路算法(shortest paths)",
  2051. "sortings": "排序算法(sortings)",
  2052. "string suffix structures": "字符串后缀结构(string suffix structures)",
  2053. "strings": "字符串处理(strings)",
  2054. "ternary search": "三分搜索(ternary search)",
  2055. "trees": "树形结构(trees)",
  2056. "two pointers": "双指针算法(two pointers)"
  2057. };
  2058. selectElement.find("option").each(function () {
  2059. var optionValue = $(this).val();
  2060. if (translations[optionValue]) {
  2061. $(this).text(translations[optionValue]);
  2062. }
  2063. });
  2064. $("._FilterByTagsFrame_tagBoxCaption").each(function () {
  2065. var tag = $(this).text();
  2066. if (tag in translations) {
  2067. $(this).text(translations[tag]);
  2068. }
  2069. });
  2070. $(".notice").each(function () {
  2071. var tag = $(this).text();
  2072. if (tag in translations) {
  2073. $(this).text(translations[tag]);
  2074. }
  2075. });
  2076. $(".tag-box").each(function () {
  2077. var tag = $(this).text();
  2078. for (var property in translations) {
  2079. property = property.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
  2080. if (tag.match(property)) {
  2081. $(this).text(translations[property]);
  2082. break;
  2083. }
  2084. }
  2085. });
  2086. })();
  2087. // 题目过滤器选项汉化
  2088. (function () {
  2089. var parentElement = $('#gym-filter-form');
  2090. var selectElement = parentElement.find('div');
  2091. var translations = {
  2092. "Contest type:": "比赛类型:",
  2093. "ICPC region:": "ICPC地区:",
  2094. "Contest format:": "比赛形式:",
  2095. "Order by:": "排序方式:",
  2096. "Secondary order by:": "次要排序方式:",
  2097. "Hide, if participated:": "隐藏我参加过的:",
  2098. };
  2099. selectElement.find("label").each(function () {
  2100. var optionValue = $(this).text();
  2101. if (translations[optionValue]) {
  2102. $(this).text(translations[optionValue]);
  2103. }
  2104. });
  2105. translations = {
  2106. "Season:": "时间范围(年度)",
  2107. "Duration, hours:": "持续时间(小时):",
  2108. "Difficulty:": "难度:"
  2109. };
  2110. selectElement.each(function () {
  2111. var optionValue = $(this).text();
  2112. if (translations[optionValue]) {
  2113. $(this).text(translations[optionValue]);
  2114. }
  2115. });
  2116. })();
  2117. (function () {
  2118. var parentElement = $('.setting-value');
  2119. var selectElement = parentElement.find('select');
  2120. var translations = {
  2121. "Official ACM-ICPC Contest": "ICPC官方比赛",
  2122. "Official School Contest": "学校官方比赛",
  2123. "Opencup Contest": "Opencup比赛",
  2124. "School/University/City/Region Championship": "学校/大学/城市/地区锦标赛",
  2125. "Training Camp Contest": "训练营比赛",
  2126. "Official International Personal Contest": "官方国际个人赛",
  2127. "Training Contest": "训练比赛",
  2128. "ID_ASC": "创建时间(升序)",
  2129. "ID_DESC": "创建时间(降序)",
  2130. "RATING_ASC": "评分(升序)",
  2131. "RATING_DESC": "评分(降序)",
  2132. "DIFFICULTY_ASC": "难度(升序)",
  2133. "DIFFICULTY_DESC": "难度(降序)",
  2134. "START_TIME_ASC": "开始时间(升序)",
  2135. "START_TIME_DESC": "开始时间(降序)",
  2136. "DURATION_ASC": "持续时间(升序)",
  2137. "DURATION_DESC": "持续时间(降序)",
  2138. "POPULARITY_ASC": "热度(升序)",
  2139. "POPULARITY_DESC": "热度(降序)",
  2140. "UPDATE_TIME_ASC": "更新时间(升序)",
  2141. "UPDATE_TIME_DESC": "更新时间(降序)"
  2142. };
  2143. selectElement.find("option").each(function () {
  2144. var optionValue = $(this).val();
  2145. if (translations[optionValue]) {
  2146. $(this).text(translations[optionValue]);
  2147. }
  2148. });
  2149. parentElement = $('.setting-last-value');
  2150. selectElement = parentElement.find('select');
  2151. selectElement.find("option").each(function () {
  2152. var optionValue = $(this).val();
  2153. if (translations[optionValue]) {
  2154. $(this).text(translations[optionValue]);
  2155. }
  2156. });
  2157. })();
  2158. // 比赛过滤器选项汉化
  2159. (function () {
  2160. var parentElement = $('.options');
  2161. var selectElement = parentElement.find('li');
  2162. var translations = {
  2163. "Educational": "教育性",
  2164. "Global": "全球",
  2165. "VK Cup": "VK杯",
  2166. "Long Rounds": "长期回合",
  2167. "April Fools": "愚人节",
  2168. "Team Contests": "团队比赛",
  2169. "ICPC Scoring": "ICPC计分",
  2170. "Doesn't matter": "----",
  2171. "Any": "所有",
  2172. "Yes": "是",
  2173. "No": "否",
  2174. "No submission(s)": "无提交",
  2175. "Have submission(s)": "有提交",
  2176. "No solved problem(s)": "无解决问题",
  2177. "Have solved problem(s)": "有解决问题"
  2178. };
  2179. selectElement.find('label').each(function () {
  2180. var optionValue = $(this).text();
  2181. if (translations[optionValue]) {
  2182. $(this).text(translations[optionValue]);
  2183. }
  2184. });
  2185. $('.CaptionCont').find('span').each(function () {
  2186. var optionValue = $(this).text();
  2187. if (translations[optionValue]) {
  2188. $(this).text(translations[optionValue]);
  2189. }
  2190. });
  2191. })();
  2192. // 右侧sidebox通用汉化
  2193. (function () {
  2194. var parentElement = $('.sidebox');
  2195. var selectElement = parentElement.find('div');
  2196. var translations = {
  2197. "Show tags for unsolved problems": "显示未解决问题的标签",
  2198. "Hide solved problems": "隐藏已解决的问题",
  2199. };
  2200. selectElement.find("label").each(function () {
  2201. var optionValue = $(this).text();
  2202. if (translations[optionValue]) {
  2203. $(this).text(translations[optionValue]);
  2204. }
  2205. });
  2206. })();
  2207. // 表单字段名汉化
  2208. (function () {
  2209. var translations = {
  2210. "Problem:": "题目:",
  2211. "Language:": "语言:",
  2212. "Source code:": "源代码:",
  2213. "Or choose file:": "或者选择文件:",
  2214. "Choose file:": "选择文件:",
  2215. "Notice:": "注意:",
  2216. "virtual participation:": "虚拟参与:",
  2217. "Registration for the contest:": "比赛报名:",
  2218. "Take part:": "参与:",
  2219. "as individual participant:": "作为个人参与者:",
  2220. "as a team member:": "作为团队成员:",
  2221. "Virtual start time:": "虚拟开始时间:",
  2222. "Complete problemset:": "完整的问题集:",
  2223. "First name (English)": "名字(英文)",
  2224. "Last name (English)": "姓氏(英文)",
  2225. "First name (Native)": "名字(本地语言)",
  2226. "Last name (Native)": "姓氏(本地语言)",
  2227. "Birth date": "出生日期",
  2228. "Country": "国家",
  2229. "City": "城市",
  2230. "Organization": "组织",
  2231. "Handle/Email": "账号/邮箱",
  2232. "Password": "密码",
  2233. };
  2234. $(".field-name").each(function () {
  2235. var optionValue = $(this).text();
  2236. if (translations[optionValue]) {
  2237. $(this).text(translations[optionValue]);
  2238. }
  2239. });
  2240. })();
  2241. (function () {
  2242. var translations = {
  2243. "Terms of agreement:": "协议条款:",
  2244. "Choose team:": "选择团队:"
  2245. };
  2246. $(".field-name label").each(function () {
  2247. var optionValue = $(this).text();
  2248. if (translations[optionValue]) {
  2249. $(this).text(translations[optionValue]);
  2250. }
  2251. });
  2252. })();
  2253. (function () {
  2254. var translations = {
  2255. "Hide sidebar block \"Find user\"": "隐藏侧边栏块“查找用户”",
  2256. "Hide sidebar block \"Current user\"": "隐藏侧边栏块“当前用户”",
  2257. "Hide sidebar block \"Recent аctions\"": "隐藏侧边栏块“最新动态”",
  2258. "Hide sidebar block \"Favourite groups\"": "隐藏侧边栏块“收藏组”",
  2259. "Hide sidebar block \"Top contributors\"": "隐藏侧边栏块“贡献者排行”",
  2260. "Hide sidebar block \"Top rated\"": "隐藏侧边栏块“评级排行”",
  2261. "Hide sidebar block \"Streams\"": "隐藏侧边栏块“直播”",
  2262. "Old password": "旧密码",
  2263. "New password": "新密码",
  2264. "Confirm new password": "确认新密码",
  2265. "Contest email notification": "比赛邮件通知",
  2266. "Send email on new user talk": "在有新用户对话时发送电子邮件",
  2267. "Send email on new comment": "在有新评论时发送电子邮件",
  2268. "Hide contact information": "隐藏联系人信息",
  2269. "Remember me by Gmail, Facebook and etc": "通过 Gmail、Facebook 等记住我",
  2270. "Show tags for unsolved problems": "显示未解决问题的标签",
  2271. "Hide solved problems from problemset": "从问题集中隐藏已解决的问题",
  2272. "Hide low rated blogs": "隐藏评级较低的博客",
  2273. "Offer to publish great rating rises": "提供展示Rating显著提升的机会",
  2274. "Enforce https": "强制 HTTPS",
  2275. "Show private activity in the profile": "在个人资料中显示私人活动",
  2276. "Show diagnostics": "显示诊断信息"
  2277. };
  2278. $(".field-name").each(function () {
  2279. var tag = $(this).text();
  2280. for (var property in translations) {
  2281. property = property.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
  2282. if (tag.match(property)) {
  2283. $(this).text(translations[property]);
  2284. break;
  2285. }
  2286. }
  2287. });
  2288. })();
  2289. (function () {
  2290. var translations = {
  2291. "Postal/zip code": "邮政编码/邮编",
  2292. "Country (English)": "国家(英文)",
  2293. "State (English)": "州/省份(英文)",
  2294. "City (English)": "城市(英文)",
  2295. "Address (English)": "地址(英文)",
  2296. "Recipient (English)": "收件人姓名(英文)",
  2297. "Country (Native)": "国家(本地语言)",
  2298. "State (Native)": "州/省份(本地语言)",
  2299. "City (Native)": "城市(本地语言)",
  2300. "Address (Native)": "地址(本地语言)",
  2301. "Recipient (Native)": "收件人姓名(本地语言)",
  2302. "Phone": "电话",
  2303. "TON Wallet:": "TON 钱包:",
  2304. "Secret Code:": "验证码:"
  2305. };
  2306. $("td.field-name label").each(function () {
  2307. var optionValue = $(this).text();
  2308. if (translations[optionValue]) {
  2309. $(this).text(translations[optionValue]);
  2310. }
  2311. });
  2312. })();
  2313.  
  2314. // 按钮汉化input[type="submit"]
  2315. (function () {
  2316. var translations = {
  2317. "Register for virtual participation": "报名虚拟参赛",
  2318. "Register for practice": "登录(不可用)以开始练习",
  2319. "Apply": "应用",
  2320. "Register": "报名",
  2321. "Login": "登录(不可用)",
  2322. "Run": "运行",
  2323. "Start virtual contest": "开始虚拟参赛",
  2324. "Clone Contest": "克隆比赛",
  2325. "Submit": "提交",
  2326. "Save changes": "保存设置",
  2327. "Filter": "过滤",
  2328. "Find": "查找",
  2329. "Create Mashup Contest": "创建混搭比赛"
  2330. };
  2331. $('input[type="submit"]').each(function () {
  2332. var optionValue = $(this).val();
  2333. if (translations[optionValue]) {
  2334. $(this).val(translations[optionValue]);
  2335. }
  2336. });
  2337. })();
  2338. (function () {
  2339. var translations = {
  2340. "Reset": "重置",
  2341. };
  2342. $('input[type="button"]').each(function () {
  2343. var optionValue = $(this).val();
  2344. if (translations[optionValue]) {
  2345. $(this).val(translations[optionValue]);
  2346. }
  2347. });
  2348. })();
  2349.  
  2350. // 选项汉化input[type="radio"]
  2351. (function () {
  2352. var translations = {
  2353. "as individual participant": "个人",
  2354. "as a team member": "作为一个团队成员",
  2355. };
  2356. $('input[type="radio"]').each(function () {
  2357. var tag = $(this).parent().contents().filter(function () {
  2358. return this.nodeType === Node.TEXT_NODE;
  2359. });
  2360. for (var i = 0; i < tag.length; i++) {
  2361. var text = tag[i].textContent.trim();
  2362. if (translations.hasOwnProperty(text)) {
  2363. $(this).addClass(text);
  2364. tag[i].replaceWith(translations[text]);
  2365. break;
  2366. }
  2367. }
  2368. });
  2369. })();
  2370.  
  2371.  
  2372. // 杂项
  2373. (function () {
  2374. var translations = {
  2375. "(standard input\/output)": "标准输入/输出",
  2376. };
  2377. $("div.notice").each(function () {
  2378. var tag = $(this).children().eq(0).text();
  2379. for (var property in translations) {
  2380. if (tag.match(property)) {
  2381. $(this).children().eq(0).text(translations[property]);
  2382. break;
  2383. }
  2384. }
  2385. });
  2386. })();
  2387. (function () {
  2388. var translations = {
  2389. "Ask a question": "提一个问题",
  2390. };
  2391. $(".ask-question-link").each(function () {
  2392. var optionValue = $(this).text();
  2393. if (translations[optionValue]) {
  2394. $(this).text(translations[optionValue]);
  2395. }
  2396. });
  2397. })();
  2398.  
  2399. // 轻量站特殊
  2400. if (is_mSite) {
  2401. (function () {
  2402. var translations = {
  2403. "Announcements": "公告",
  2404. "Submissions": "提交记录",
  2405. "Contests": "比赛",
  2406. };
  2407. $(".caption").each(function () {
  2408. var optionValue = $(this).text();
  2409. if (translations[optionValue]) {
  2410. $(this).text(translations[optionValue]);
  2411. }
  2412. });
  2413. })();
  2414. }
  2415. };
  2416.  
  2417. // 配置管理函数
  2418. function setupConfigManagement(element, tempConfig, structure, configHTML, checkable) {
  2419. let counter = 0;
  2420. createControlBar();
  2421. createContextMenu();
  2422.  
  2423. // 键值对校验
  2424. function valiKeyValue(value) {
  2425. const keyValuePairs = value.split('\n');
  2426. const regex = /^[a-zA-Z0-9_-]+\s*:\s*[a-zA-Z0-9_-]+$/;
  2427. for (let i = 0; i < keyValuePairs.length; i++) {
  2428. if (!regex.test(keyValuePairs[i])) {
  2429. return false;
  2430. }
  2431. }
  2432. return true;
  2433. }
  2434.  
  2435. // 新增数据
  2436. function onAdd() {
  2437. const styleElement = createWindow();
  2438.  
  2439. const settingMenu = $("#config_edit_menu");
  2440. settingMenu.on("click", "#save", () => {
  2441. const config = {};
  2442. let allFieldsValid = true;
  2443. for (const key in structure) {
  2444. let value = $(key).val();
  2445. if (value || $(key).attr('require') === 'false') {
  2446. config[structure[key]] = $(key).val();
  2447. $(key).removeClass('is_null');
  2448. } else {
  2449. $(key).addClass('is_null');
  2450. allFieldsValid = false;
  2451. }
  2452. }
  2453.  
  2454. // 校验提示
  2455. for (let i = 0, len = checkable.length; i < len; i++) {
  2456. let value = $(checkable[i]).val();
  2457. if (value && !valiKeyValue(value)) {
  2458. if (!$(checkable[i]).prev('span.text-error').length) {
  2459. $(checkable[i]).before('<span class="text-error" style="color: red;">格式不符或存在非法字符</span>');
  2460. }
  2461. allFieldsValid = false;
  2462. } else {
  2463. $(checkable[i]).prev('span.text-error').remove();
  2464. }
  2465. }
  2466.  
  2467. if (!allFieldsValid) return;
  2468. tempConfig.configurations.push(config);
  2469.  
  2470. const list = $("#config_bar_ul");
  2471. createListItemElement(config[structure['#note']]).insertBefore($('#add_button'));
  2472.  
  2473. settingMenu.remove();
  2474. $(styleElement).remove();
  2475. });
  2476.  
  2477. settingMenu.on("click", ".btn-close", () => {
  2478. settingMenu.remove();
  2479. $(styleElement).remove();
  2480. });
  2481. }
  2482.  
  2483. // 编辑数据
  2484. function onEdit() {
  2485. const menu = $("#config_bar_menu");
  2486. menu.css({ display: "none" });
  2487.  
  2488. const list = $("#config_bar_ul");
  2489. const index = Array.from(list.children()).indexOf(this);
  2490.  
  2491. const styleElement = createWindow();
  2492.  
  2493. const settingMenu = $("#config_edit_menu");
  2494. const configAtIndex = tempConfig.configurations[index];
  2495.  
  2496. if (configAtIndex) {
  2497. for (const key in structure) {
  2498. $(key).val(configAtIndex[structure[key]]);
  2499. }
  2500. }
  2501.  
  2502. settingMenu.on("click", "#save", () => {
  2503. const config = {};
  2504. let allFieldsValid = true;
  2505. for (const key in structure) {
  2506. let value = $(key).val();
  2507. if (value || $(key).attr('require') === 'false') {
  2508. config[structure[key]] = $(key).val();
  2509. $(key).removeClass('is_null');
  2510. } else {
  2511. $(key).addClass('is_null');
  2512. allFieldsValid = false;
  2513. }
  2514. }
  2515.  
  2516. // 校验提示
  2517. for (let i = 0, len = checkable.length; i < len; i++) {
  2518. let value = $(checkable[i]).val();
  2519. if (value && !valiKeyValue(value)) {
  2520. if (!$(checkable[i]).prev('span.text-error').length) {
  2521. $(checkable[i]).before('<span class="text-error" style="color: red;">格式不符或存在非法字符</span>');
  2522. }
  2523. allFieldsValid = false;
  2524. } else {
  2525. $(checkable[i]).prev('span.text-error').remove();
  2526. }
  2527. }
  2528.  
  2529. if (!allFieldsValid) return;
  2530. tempConfig.configurations[index] = config;
  2531.  
  2532. settingMenu.remove();
  2533. $(styleElement).remove();
  2534. menu.css({ display: "none" });
  2535.  
  2536. list.children().eq(index).find("label").text(config.note);
  2537. });
  2538.  
  2539. // 关闭按钮
  2540. settingMenu.on("click", ".btn-close", () => {
  2541. settingMenu.remove();
  2542. $(styleElement).remove();
  2543. });
  2544. }
  2545.  
  2546. // 删除数据
  2547. function onDelete() {
  2548. const menu = $("#config_bar_menu");
  2549. menu.css({ display: "none" });
  2550.  
  2551. const list = $("#config_bar_ul");
  2552. const index = Array.from(list.children()).indexOf(this);
  2553.  
  2554. tempConfig.configurations.splice(index, 1);
  2555.  
  2556. list.children().eq(index).remove();
  2557. }
  2558.  
  2559. // 创建编辑窗口
  2560. function createWindow() {
  2561. const styleElement = GM_addStyle(darkenPageStyle2);
  2562. $("body").append(configHTML);
  2563. addDraggable($('#config_edit_menu'));
  2564. return styleElement;
  2565. }
  2566.  
  2567. // 创建控制面板
  2568. function createControlBar() {
  2569. $(element).append(`
  2570. <div id='configControlTip' style='color:red;'></div>
  2571. <div class='config_bar'>
  2572. <div class='config_bar_list' id='config_bar_list'>
  2573. <ul class='config_bar_ul' id='config_bar_ul'></ul>
  2574. </div>
  2575. </div>
  2576. `);
  2577. }
  2578.  
  2579. // 创建右键菜单
  2580. function createContextMenu() {
  2581. const menu = $("<div id='config_bar_menu' style='display: none;'></div>");
  2582. menu.html(`
  2583. <div class='config_bar_menu_item' id='config_bar_menu_edit'>修改</div>
  2584. <div class='config_bar_menu_item' id='config_bar_menu_delete'>删除</div>
  2585. `);
  2586. $("body").append(menu);
  2587. }
  2588.  
  2589. // 创建新的li元素
  2590. function createListItemElement(text) {
  2591. const li = $("<li></li>");
  2592. const radio = $("<input type='radio' name='config_item'></input>").appendTo(li);
  2593. radio.attr("value", counter).attr("id", counter++);
  2594. const label = $("<label class='config_bar_ul_li_text'></label>").text(text).attr("for", radio.attr("value")).appendTo(li);
  2595.  
  2596. // 添加右键菜单
  2597. li.on("contextmenu", function (event) {
  2598. event.preventDefault();
  2599. const menu = $("#config_bar_menu");
  2600. menu.css({ display: "block", left: event.pageX, top: event.pageY });
  2601.  
  2602. const deleteItem = $("#config_bar_menu_delete");
  2603. const editItem = $("#config_bar_menu_edit");
  2604.  
  2605. // 移除旧事件
  2606. deleteItem.off("click");
  2607. editItem.off("click");
  2608.  
  2609. deleteItem.on("click", onDelete.bind(this));
  2610. editItem.on("click", onEdit.bind(this));
  2611.  
  2612. $(document).one("click", (event) => {
  2613. if (!menu.get(0).contains(event.target)) {
  2614. menu.css({ display: "none" });
  2615. deleteItem.off("click", onDelete);
  2616. editItem.off("click", onEdit);
  2617. }
  2618. });
  2619. });
  2620.  
  2621.  
  2622. return li;
  2623. }
  2624.  
  2625. // 渲染列表
  2626. function renderList() {
  2627. const listContainer = $("#config_bar_list");
  2628. const list = $("#config_bar_ul");
  2629. list.empty();
  2630. tempConfig.configurations.forEach((item) => {
  2631. list.append(createListItemElement(item[structure['#note']]));
  2632. });
  2633.  
  2634. list.append(`
  2635. <li id='add_button'>
  2636. <span>+ 添加</span>
  2637. </li>
  2638. `);
  2639. const addItem = $('#add_button');
  2640. addItem.on("click", onAdd);
  2641. };
  2642.  
  2643. renderList();
  2644. return tempConfig;
  2645. }
  2646.  
  2647. const CFBetterSettingMenuHTML = `
  2648. <div class='CFBetter_setting_menu' id='CFBetter_setting_menu'>
  2649. <div class="tool-box">
  2650. <button class="btn-close">×</button>
  2651. </div>
  2652. <div class="CFBetter_setting_container">
  2653. <div class="CFBetter_setting_sidebar">
  2654. <ul>
  2655. <li><a href="#basic-settings" id="sidebar-basic-settings" class="active">基本设置</a></li>
  2656. <li><a href="#translation-settings" id="sidebar-translation-settings">翻译设置</a></li>
  2657. <li><a href="#clist_rating-settings" id="sidebar-clist_rating-settings">Clist设置</a></li>
  2658. <li><a href="#compatibility-settings" id="sidebar-compatibility-settings">兼容设置</a></li>
  2659. </ul>
  2660. </div>
  2661. <div class="CFBetter_setting_content">
  2662. <div id="basic-settings" class="settings-page active">
  2663. <h3>基本设置</h3>
  2664. <hr>
  2665. <div class='CFBetter_setting_list' style="padding: 0px 10px;">
  2666. <span id="darkMode_span">黑暗模式</span>
  2667. <div class="dark-mode-selection">
  2668. <label>
  2669. <input class="radio-input" type="radio" name="darkMode" value="dark" />
  2670. <span class="CFBetter_setting_menu_label_text">黑暗</span>
  2671. <span class="radio-icon"> </span>
  2672. </label>
  2673. <label>
  2674. <input checked="" class="radio-input" type="radio" name="darkMode" value="light" />
  2675. <span class="CFBetter_setting_menu_label_text">白天</span>
  2676. <span class="radio-icon"> </span>
  2677. </label>
  2678. <label>
  2679. <input class="radio-input" type="radio" name="darkMode" value="follow" />
  2680. <span class="CFBetter_setting_menu_label_text">跟随系统</span>
  2681. <span class="radio-icon"> </span>
  2682. </label>
  2683. </div>
  2684. </div>
  2685. <div class='CFBetter_setting_list'>
  2686. <label for="bottomZh_CN">界面汉化</label>
  2687. <input type="checkbox" id="bottomZh_CN" name="bottomZh_CN">
  2688. </div>
  2689. <div class='CFBetter_setting_list'>
  2690. <label for="showLoading">显示加载提示信息</label>
  2691. <div class="help_tip">
  2692. ${helpCircleHTML}
  2693. <div class="tip_text">
  2694. <p>当你开启 显示加载信息 时,每次加载页面时会在上方显示加载信息提示:“Codeforces Better! —— xxx”</p>
  2695. <p>这用于了解脚本当前的工作情况,<strong>如果你不想看到,可以选择关闭</strong></p>
  2696. <p><u>需要说明的是,如果你需要反馈脚本的任何加载问题,请开启该选项后再截图,以便于分析问题</u></p>
  2697. </div>
  2698. </div>
  2699. <input type="checkbox" id="showLoading" name="showLoading">
  2700. </div>
  2701. <div class='CFBetter_setting_list'>
  2702. <label for="hoverTargetAreaDisplay">显示目标区域范围</label>
  2703. <div class="help_tip">
  2704. `+ helpCircleHTML + `
  2705. <div class="tip_text">
  2706. <p>开启后当鼠标悬浮在 MD视图/复制/翻译 按钮上时,会显示其目标区域的范围</p>
  2707. </div>
  2708. </div>
  2709. <input type="checkbox" id="hoverTargetAreaDisplay" name="hoverTargetAreaDisplay">
  2710. </div>
  2711. <div class='CFBetter_setting_list'>
  2712. <label for="expandFoldingblocks">自动展开折叠块</label>
  2713. <input type="checkbox" id="expandFoldingblocks" name="expandFoldingblocks">
  2714. </div>
  2715. <div class='CFBetter_setting_list'>
  2716. <label for="renderPerfOpt">折叠块渲染优化</label>
  2717. <div class="help_tip">
  2718. `+ helpCircleHTML + `
  2719. <div class="tip_text">
  2720. <p>为折叠块元素添加 contain 约束</p>
  2721. <div style="border: 1px solid #795548; padding: 10px;">
  2722. <p>
  2723. contain: layout style;
  2724. </p>
  2725. </div>
  2726. <p>如果您的浏览器查看大量折叠块时比较卡顿,开启后<strong>可能</strong>会有一定程度的改善</p>
  2727. </div>
  2728. </div>
  2729. <input type="checkbox" id="renderPerfOpt" name="renderPerfOpt">
  2730. </div>
  2731. <div class='CFBetter_setting_list'>
  2732. <label for="commentPaging">评论区分页</label>
  2733. <div class="help_tip">
  2734. `+ helpCircleHTML + `
  2735. <div class="tip_text">
  2736. <p>对评论区分页显示,每页显示指定数量的<strong>主楼</strong></p>
  2737. </div>
  2738. </div>
  2739. <input type="checkbox" id="commentPaging" name="commentPaging">
  2740. </div>
  2741. <div class='CFBetter_setting_list'>
  2742. <label for="showJumpToLuogu">显示跳转到洛谷</label>
  2743. <div class="help_tip">
  2744. `+ helpCircleHTML + `
  2745. <div class="tip_text">
  2746. <p>洛谷OJ上收录了Codeforces的部分题目,一些题目有翻译和题解</p>
  2747. <p>开启显示后,如果当前题目被收录,则会在题目的右上角显示洛谷标志,</p>
  2748. <p>点击即可一键跳转到该题洛谷的对应页面。</strong></p>
  2749. </div>
  2750. </div>
  2751. <input type="checkbox" id="showJumpToLuogu" name="showJumpToLuogu">
  2752. </div>
  2753. <div class='CFBetter_setting_list'>
  2754. <label for="standingsRecolor">榜单重新着色</label>
  2755. <div class="help_tip">
  2756. `+ helpCircleHTML + `
  2757. <div class="tip_text">
  2758. <p>对于采用 Codeforces 赛制的比赛榜单</p>
  2759. <p>按照“得分/总分”所在的范围为分数重新渐变着色</p>
  2760. <p>范围:1~0.7~0.45~0 深绿色→浅橙色→深橙色→红色</p>
  2761. </div>
  2762. </div>
  2763. <input type="checkbox" id="standingsRecolor" name="standingsRecolor">
  2764. </div>
  2765. </div>
  2766. <div id="translation-settings" class="settings-page">
  2767. <h3>翻译设置</h3>
  2768. <hr>
  2769. <h4>首选项</h4>
  2770. <label>
  2771. <input type='radio' name='translation' value='deepl'>
  2772. <span class='CFBetter_setting_menu_label_text'>deepl翻译</span>
  2773. </label>
  2774. <label>
  2775. <input type='radio' name='translation' value='iflyrec'>
  2776. <span class='CFBetter_setting_menu_label_text'>讯飞听见翻译</span>
  2777. </label>
  2778. <label>
  2779. <input type='radio' name='translation' value='youdao'>
  2780. <span class='CFBetter_setting_menu_label_text'>有道翻译</span>
  2781. </label>
  2782. <label>
  2783. <input type='radio' name='translation' value='google'>
  2784. <span class='CFBetter_setting_menu_label_text'>Google翻译</span>
  2785. </label>
  2786. <label>
  2787. <input type='radio' name='translation' value='caiyun'>
  2788. <span class='CFBetter_setting_menu_label_text'>彩云小译翻译</span>
  2789. </label>
  2790. <label>
  2791. <input type='radio' name='translation' value='openai'>
  2792. <span class='CFBetter_setting_menu_label_text'>ChatGPT翻译
  2793. <div class="help_tip">
  2794. `+ helpCircleHTML + `
  2795. <div class="tip_text">
  2796. <p><b>请在下方添加并选定你想使用的配置信息</b></p>
  2797. <p>具体请阅读脚本页的介绍</p>
  2798. </div>
  2799. </div>
  2800. </span>
  2801. </label>
  2802. <div class='CFBetter_setting_menu_input' id='openai' style='display: none;'>
  2803. <div id="chatgpt-config"></div>
  2804. </div>
  2805. <h4>偏好</h4>
  2806. <div class='CFBetter_setting_list'>
  2807. <label for="comment_translation_choice" style="display: flex;">评论区翻译</label>
  2808. <select id="comment_translation_choice" name="comment_translation_choice">
  2809. <option value="0">跟随首选项</option>
  2810. <option value="deepl">deepl翻译</option>
  2811. <option value="iflyrec">讯飞听见翻译</option>
  2812. <option value="youdao">有道翻译</option>
  2813. <option value="google">Google翻译</option>
  2814. <option value="caiyun">彩云小译翻译</option>
  2815. <option value="openai">ChatGPT翻译</option>
  2816. </select>
  2817. </div>
  2818. <h4>高级</h4>
  2819. <div class='CFBetter_setting_list'>
  2820. <label for="comment_translation_mode" style="display: flex;">工作模式</label>
  2821. <div class="help_tip">
  2822. `+ helpCircleHTML + `
  2823. <div class="tip_text">
  2824. <p>你可以选择脚本的工作方式</p>
  2825. <p>○ 普通模式:会一次性翻译整个区域的内容</p>
  2826. <p>○ 分段模式:会对区域内的每一个&#60;&#112;&#47;&#62;和&#60;&#105;&#47;&#62;标签依次进行翻译</p>
  2827. <p>○ 选段模式:你可以自由点选页面上的任何&#60;&#112;&#47;&#62;和&#60;&#105;&#47;&#62;标签进行翻译</p>
  2828. <div style="color:#f44336;">
  2829. <p><u>注意:分段/选段模式会产生如下问题:</u></p>
  2830. <p>- 使得翻译接口无法知晓整个文本的上下文信息,会降低翻译质量。</p>
  2831. <p>- 会有<strong>部分内容不会被翻译/不能被选中</strong>,因为它们不是&#60;&#112;&#47;&#62;或&#60;&#105;&#47;&#62;元素</p>
  2832. </div>
  2833. </div>
  2834. </div>
  2835. <select id="comment_translation_mode" name="comment_translation_mode">
  2836. <option value="0">普通模式</option>
  2837. <option value="1">分段模式</option>
  2838. <option value="2">选段模式</option>
  2839. </select>
  2840. </div>
  2841. <div class='CFBetter_setting_list'>
  2842. <label for="translation_retransAction" style="display: flex;">重新翻译时</label>
  2843. <div class="help_tip">
  2844. `+ helpCircleHTML + `
  2845. <div class="tip_text">
  2846. <p>选择在重新翻译时是"关闭旧的结果"还是"收起旧的结果"</p>
  2847. </div>
  2848. </div>
  2849. <select id="translation_retransAction" name="translation_retransAction">
  2850. <option value=0>关闭旧的结果</option>
  2851. <option value=1>收起旧的结果</option>
  2852. </select>
  2853. </div>
  2854. <div class='CFBetter_setting_list'>
  2855. <label for='transWaitTime'>
  2856. <div style="display: flex;align-items: center;">
  2857. <span>等待间隔</span>
  2858. </div>
  2859. </label>
  2860. <div class="help_tip">
  2861. `+ helpCircleHTML + `
  2862. <div class="tip_text">
  2863. <p>设置在 分段/选段 模式中翻译两段间的等待间隔,建议 200 + 毫秒</p>
  2864. </div>
  2865. </div>
  2866. <input type='number' id='transWaitTime' class='no_default' placeholder='请输入' require = true>
  2867. <span>毫秒</span>
  2868. </div>
  2869. <div class='CFBetter_setting_list'>
  2870. <label for="translation_replaceSymbol" style="display: flex;">LaTeX替换符</label>
  2871. <div class="help_tip">
  2872. `+ helpCircleHTML + `
  2873. <div class="tip_text">
  2874. <p>脚本通过先取出所有的LaTeX公式,并使用替换符占位,来保证公式不会被翻译接口所破坏</p>
  2875. <p>对于各个翻译服务,不同的替换符本身遭到破坏的概率有所不同,具体请阅读脚本页的说明</p>
  2876. <p>注意:使用ChatGPT翻译时不需要上述操作, 因此不受此选项影响</p>
  2877. <p>具体您可以前往阅读脚本页的说明</p>
  2878. </div>
  2879. </div>
  2880. <select id="translation_replaceSymbol" name="translation_replaceSymbol">
  2881. <option value=2>使用{}</option>
  2882. <option value=1>使用【】</option>
  2883. <option value=3>使用[]</option>
  2884. </select>
  2885. </div>
  2886. </div>
  2887. <div id="clist_rating-settings" class="settings-page">
  2888. <h3>Clist设置</h3>
  2889. <hr>
  2890. <h4>基本</h4>
  2891. <div class='CFBetter_setting_list' style="background-color: #E0F2F1;border: 1px solid #009688;">
  2892. <div>
  2893. <p>注意:在不同页面工作所需要的凭证有所不同,具体请看对应选项的标注说明</p>
  2894. </div>
  2895. </div>
  2896. <div class='CFBetter_setting_list'>
  2897. <label for='clist_Authorization'>
  2898. <div style="display: flex;align-items: center;">
  2899. <span class="input_label">KEY:</span>
  2900. </div>
  2901. </label>
  2902. <div class="help_tip">
  2903. `+ helpCircleHTML + `
  2904. <div class="tip_text">
  2905. <p>格式样例:</p>
  2906. <div style="border: 1px solid #795548; padding: 10px;">
  2907. <p>ApiKey XXXXXXXXX</p>
  2908. </div>
  2909. </div>
  2910. </div>
  2911. <input type='text' id='clist_Authorization' class='no_default' placeholder='请输入KEY' require = true>
  2912. </div>
  2913. <hr>
  2914. <h4>显示Rating分</h4>
  2915. <div class='CFBetter_setting_list'>
  2916. <label for="showClistRating_contest"><span>比赛问题集页</span></label>
  2917. <div class="help_tip" style="margin-right: initial;">
  2918. `+ helpCircleHTML + `
  2919. <div class="tip_text">
  2920. <p>数据来源clist.by</p>
  2921. <p>您需要提供官方的api key</p>
  2922. <p>或让您的浏览器上的clist.by处于登录(不可用)状态(即cookie有效)</p>
  2923. </div>
  2924. </div>
  2925. <div class="badge">Cookie/API KEY</div>
  2926. <input type="checkbox" id="showClistRating_contest" name="showClistRating_contest">
  2927. </div>
  2928. <div class='CFBetter_setting_list'>
  2929. <label for="showClistRating_problem"><span>题目页</span></label>
  2930. <div class="help_tip" style="margin-right: initial;">
  2931. `+ helpCircleHTML + `
  2932. <div class="tip_text">
  2933. <p>需要让您的浏览器上的clist.by处于登录(不可用)状态(即cookie有效)才能正常工作</p>
  2934. </div>
  2935. </div>
  2936. <div class="badge">Cookie</div>
  2937. <input type="checkbox" id="showClistRating_problem" name="showClistRating_problem">
  2938. </div>
  2939. <div class='CFBetter_setting_list'>
  2940. <label for="showClistRating_problemset"><span>题单页</span></label>
  2941. <div class="help_tip" style="margin-right: initial;">
  2942. `+ helpCircleHTML + `
  2943. <div class="tip_text">
  2944. <p>需要让您的浏览器上的clist.by处于登录(不可用)状态(即cookie有效)才能正常工作</p>
  2945. </div>
  2946. </div>
  2947. <div class="badge">Cookie</div>
  2948. <input type="checkbox" id="showClistRating_problemset" name="showClistRating_problemset">
  2949. </div>
  2950. <hr>
  2951. <div class='CFBetter_setting_list'>
  2952. <label for="RatingHidden"><span>防剧透</span></label>
  2953. <div class="help_tip">
  2954. `+ helpCircleHTML + `
  2955. <div class="tip_text">
  2956. <p>只有当鼠标移动到Rating分展示区域上时才显示</p>
  2957. </div>
  2958. </div>
  2959. <input type="checkbox" id="RatingHidden" name="RatingHidden">
  2960. </div>
  2961. </div>
  2962. <div id="compatibility-settings" class="settings-page">
  2963. <h3>兼容设置</h3>
  2964. <hr>
  2965. <div class='CFBetter_setting_list'>
  2966. <label for="loaded"><span id="loaded_span">不等待页面资源加载</span></label>
  2967. <div class="help_tip">
  2968. `+ helpCircleHTML + `
  2969. <div class="tip_text">
  2970. <p>为了防止在页面资源未加载完成前(主要是各种js)执行脚本产生意外的错误,脚本默认会等待 window.onload 事件</p>
  2971. <p>如果您的页面上方的加载信息始终停留在:“等待页面资源加载”,即使页面已经完成加载</p>
  2972. <p><u>您首先应该确认是否是网络问题,</u></p>
  2973. <p>如果不是,那这可能是由于 window.onload 事件在您的浏览器中触发过早(早于DOMContentLoaded),</p>
  2974. <p>您可以尝试开启该选项来不再等待 window.onload 事件</p>
  2975. <p><u>注意:如果没有上述问题,请不要开启该选项</u></p>
  2976. </div>
  2977. </div>
  2978. <input type="checkbox" id="loaded" name="loaded">
  2979. </div>
  2980. </div>
  2981. </div>
  2982. </div>
  2983. `;
  2984.  
  2985. const chatgptConfigEditHTML = `
  2986. <div class='CFBetter_setting_menu' id='config_edit_menu'>
  2987. <div class="tool-box">
  2988. <button class="btn-close">×</button>
  2989. </div>
  2990. <h4>配置</h4>
  2991. <h5>基本</h5>
  2992. <hr>
  2993. <label for='note'>
  2994. <span class="input_label">备注:</span>
  2995. </label>
  2996. <input type='text' id='note' class='no_default' placeholder='请为该配置取一个备注名' require = true>
  2997. <label for='openai_model'>
  2998. <div style="display: flex;align-items: center;">
  2999. <span class="input_label">模型:</span>
  3000. <div class="help_tip">
  3001. `+ helpCircleHTML + `
  3002. <div class="tip_text">
  3003. <p>留空则默认为:gpt-3.5-turbo</p>
  3004. <p>模型列表请查阅<a target="_blank" href="https://platform.openai.com/docs/models">OpenAI官方文档</a></p>
  3005. <p><strong>此外,如果您使用的是服务商提供的代理API,请确认服务商是否支持对应模型</strong></p>
  3006. </div>
  3007. </div>
  3008. </div>
  3009. </label>
  3010. <input type='text' id='openai_model' placeholder='gpt-3.5-turbo' require = false>
  3011. <label for='openai_key'>
  3012. <div style="display: flex;align-items: center;">
  3013. <span class="input_label">KEY:</span>
  3014. <div class="help_tip">
  3015. `+ helpCircleHTML + `
  3016. <div class="tip_text">
  3017. <p>您需要输入自己的OpenAI key,<a target="_blank" href="https://platform.openai.com/account/usage">官网</a></p>
  3018. <p><b>如果您使用的是服务商提供的代理API,则应该填写服务商提供的 Key</b></p>
  3019. </div>
  3020. </div>
  3021. </div>
  3022. </label>
  3023. <input type='text' id='openai_key' class='no_default' placeholder='请输入KEY' require = true>
  3024. <label for='openai_proxy'>
  3025. <div style="display: flex;align-items: center;">
  3026. <span class="input_label">Proxy API:</span>
  3027. <div class="help_tip">
  3028. `+ helpCircleHTML + `
  3029. <div class="tip_text">
  3030. <p>留空则默认为OpenAI官方API</p>
  3031. <p>您也可以填写指定的API来代理访问OpenAIAPI,</p>
  3032. <p>如果您使用的是服务商提供的代理APIKEY,则这里应该填写其提供的<strong>完整</strong>API地址,详请阅读脚本说明</p>
  3033. <p><strong>由于您指定了自定义的APITampermonkey会对您的跨域请求进行警告,您需要自行授权</strong></p>
  3034. </div>
  3035. </div>
  3036. </div>
  3037. </label>
  3038. <input type='text' id='openai_proxy' placeholder='https://api.openai.com/v1/chat/completions' require = false>
  3039. <h5>高级</h5>
  3040. <hr>
  3041. <label for='_header'>
  3042. <div style="display: flex;align-items: center;">
  3043. <span class="input_label">自定义header</span>
  3044. <div class="help_tip">
  3045. `+ helpCircleHTML + `
  3046. <div class="tip_text">
  3047. <p>格式样例:</p>
  3048. <div style="border: 1px solid #795548; padding: 10px;">
  3049. <p>name1 : 123<br>name2 : cccc</p>
  3050. </div>
  3051. </div>
  3052. </div>
  3053. </div>
  3054. </label>
  3055. <textarea id="_header" placeholder='(选填)您可以在这里填写向请求header中额外添加的键值对' require = false></textarea>
  3056. <label for='_data'>
  3057. <div style="display: flex;align-items: center;">
  3058. <span class="input_label">自定义data</span>
  3059. <div class="help_tip">
  3060. `+ helpCircleHTML + `
  3061. <div class="tip_text">
  3062. <p>格式样例:</p>
  3063. <div style="border: 1px solid #795548; padding: 10px;">
  3064. <p>name1 : 123<br>name2 : cccc</p>
  3065. </div>
  3066. </div>
  3067. </div>
  3068. </div>
  3069. </label>
  3070. <textarea id="_data" placeholder='(选填)您可以在这里填写向请求data中额外添加的键值对' require = false></textarea>
  3071. <button id='save'>保存</button>
  3072. </div>
  3073. `;
  3074.  
  3075. // 配置改变保存确认
  3076. function saveConfirmation() {
  3077. return new Promise(resolve => {
  3078. const styleElement = GM_addStyle(darkenPageStyle2);
  3079. let htmlString = `
  3080. <div class="CFBetter_modal">
  3081. <h2>配置已更改,是否保存?</h2>
  3082. <div class="buttons">
  3083. <button id="cancelButton">不保存</button><button id="saveButton">保存</button>
  3084. </div>
  3085. </div>
  3086. `;
  3087. $('body').before(htmlString);
  3088. addDraggable($('.CFBetter_modal'));
  3089. $("#saveButton").click(function () {
  3090. $(styleElement).remove();
  3091. $('.CFBetter_modal').remove();
  3092. resolve(true);
  3093. });
  3094. $("#cancelButton").click(function () {
  3095. $(styleElement).remove();
  3096. $('.CFBetter_modal').remove();
  3097. resolve(false);
  3098. });
  3099. });
  3100. }
  3101.  
  3102. // 设置按钮面板
  3103. async function settingPanel() {
  3104. // 添加按钮
  3105. $("div[class='lang-chooser']").each(function () {
  3106. $(this).before(
  3107. "<button class='html2mdButton CFBetter_setting'>CodeforcesBetter设置</button>"
  3108. );
  3109. });
  3110. $("div[class='enter-or-register-box']").each(function () {
  3111. $(this).after(
  3112. "<button class='html2mdButton CFBetter_setting'>CodeforcesBetter设置</button>"
  3113. );
  3114. });
  3115.  
  3116. const $settingBtns = $(".CFBetter_setting");
  3117. $settingBtns.click(() => {
  3118. const styleElement = GM_addStyle(darkenPageStyle);
  3119. $settingBtns.prop("disabled", true).addClass("open");
  3120. $("body").append(CFBetterSettingMenuHTML);
  3121.  
  3122. // 窗口初始化
  3123. addDraggable($('#CFBetter_setting_menu'));
  3124.  
  3125. // help浮窗位置更新
  3126. $('.help-icon').hover(function (event) {
  3127. var menuOffset = $('#CFBetter_setting_menu').offset();
  3128. var mouseX = event.pageX - menuOffset.left;
  3129. var mouseY = event.pageY - menuOffset.top;
  3130.  
  3131. $('.tip_text').css({
  3132. 'top': mouseY,
  3133. 'left': mouseX
  3134. });
  3135. });
  3136.  
  3137. // 选项卡切换
  3138. $('.CFBetter_setting_sidebar a').click(function (event) {
  3139. event.preventDefault();
  3140. $('.CFBetter_setting_sidebar a').removeClass('active');
  3141. $(this).addClass('active');
  3142. $('.settings-page').removeClass('active');
  3143. const targetPageId = $(this).attr('href').substring(1);
  3144. $('#' + targetPageId).addClass('active');
  3145. });
  3146.  
  3147. const chatgptStructure = {
  3148. '#note': 'note',
  3149. '#openai_model': 'model',
  3150. '#openai_key': 'key',
  3151. '#openai_proxy': 'proxy',
  3152. '#_header': '_header',
  3153. '#_data': '_data',
  3154. }
  3155. const checkable = [
  3156. '#_header',
  3157. '#_data',
  3158. ]
  3159. let tempConfig = GM_getValue('chatgpt-config'); // 缓存配置信息
  3160. tempConfig = setupConfigManagement('#chatgpt-config', tempConfig, chatgptStructure, chatgptConfigEditHTML, checkable);
  3161.  
  3162. // 状态更新
  3163. $("#bottomZh_CN").prop("checked", GM_getValue("bottomZh_CN") === true);
  3164. $("input[name='darkMode'][value='" + darkMode + "']").prop("checked", true);
  3165. $("#showLoading").prop("checked", GM_getValue("showLoading") === true);
  3166. $("#expandFoldingblocks").prop("checked", GM_getValue("expandFoldingblocks") === true);
  3167. $("#renderPerfOpt").prop("checked", GM_getValue("renderPerfOpt") === true);
  3168. $("#commentPaging").prop("checked", GM_getValue("commentPaging") === true);
  3169. $("#standingsRecolor").prop("checked", GM_getValue("standingsRecolor") === true);
  3170. $("#showJumpToLuogu").prop("checked", GM_getValue("showJumpToLuogu") === true);
  3171. $("#loaded").prop("checked", GM_getValue("loaded") === true);
  3172. $("#hoverTargetAreaDisplay").prop("checked", GM_getValue("hoverTargetAreaDisplay") === true);
  3173. $("#showClistRating_contest").prop("checked", GM_getValue("showClistRating_contest") === true);
  3174. $("#showClistRating_problemset").prop("checked", GM_getValue("showClistRating_problemset") === true);
  3175. $("#showClistRating_problem").prop("checked", GM_getValue("showClistRating_problem") === true);
  3176. $("#RatingHidden").prop("checked", GM_getValue("RatingHidden") === true);
  3177. $("input[name='translation'][value='" + translation + "']").prop("checked", true);
  3178. $("input[name='translation']").css("color", "gray");
  3179. if (translation == "openai") {
  3180. $("#openai").show();
  3181. if (tempConfig) {
  3182. $("input[name='config_item'][value='" + tempConfig.choice + "']").prop("checked", true);
  3183. }
  3184. }
  3185. $('#comment_translation_mode').val(GM_getValue("commentTranslationMode"));
  3186. $('#comment_translation_choice').val(GM_getValue("commentTranslationChoice"));
  3187. $('#transWaitTime').val(GM_getValue("transWaitTime"));
  3188. $('#translation_replaceSymbol').val(GM_getValue("replaceSymbol"));
  3189. $('#translation_retransAction').val(GM_getValue("retransAction"));
  3190. $("#clist_Authorization").val(GM_getValue("clist_Authorization"));
  3191.  
  3192. // 翻译选择情况监听
  3193. $("input[name='translation']").change(function () {
  3194. var selected = $(this).val(); // 获取当前选中的值
  3195. if (selected === "openai") {
  3196. $("#openai").show();
  3197. if (tempConfig) {
  3198. $("input[name='config_item'][value='" + tempConfig.choice + "']").prop("checked", true);
  3199. }
  3200. } else {
  3201. $("#openai").hide();
  3202. }
  3203. });
  3204.  
  3205. // 配置选择情况监听
  3206. $("input[name='config_item']").change(function () {
  3207. var selected = $(this).val(); // 获取当前选中的值
  3208. tempConfig.choice = selected;
  3209. });
  3210.  
  3211. // 关闭
  3212. const $settingMenu = $(".CFBetter_setting_menu");
  3213. $settingMenu.on("click", ".btn-close", async () => {
  3214. const settings = {
  3215. bottomZh_CN: $("#bottomZh_CN").prop("checked"),
  3216. darkMode: $("input[name='darkMode']:checked").val(),
  3217. showLoading: $("#showLoading").prop("checked"),
  3218. hoverTargetAreaDisplay: $("#hoverTargetAreaDisplay").prop("checked"),
  3219. expandFoldingblocks: $("#expandFoldingblocks").prop("checked"),
  3220. renderPerfOpt: $("#renderPerfOpt").prop("checked"),
  3221. commentPaging: $("#commentPaging").prop("checked"),
  3222. standingsRecolor: $("#standingsRecolor").prop("checked"),
  3223. showJumpToLuogu: $("#showJumpToLuogu").prop("checked"),
  3224. loaded: $("#loaded").prop("checked"),
  3225. translation: $("input[name='translation']:checked").val(),
  3226. commentTranslationChoice: $('#comment_translation_choice').val(),
  3227. commentTranslationMode: $('#comment_translation_mode').val(),
  3228. transWaitTime: $('#transWaitTime').val(),
  3229. replaceSymbol: $('#translation_replaceSymbol').val(),
  3230. retransAction: $('#translation_retransAction').val(),
  3231. showClistRating_contest: $('#showClistRating_contest').prop("checked"),
  3232. showClistRating_problemset: $('#showClistRating_problemset').prop("checked"),
  3233. showClistRating_problem: $('#showClistRating_problem').prop("checked"),
  3234. RatingHidden: $('#RatingHidden').prop("checked"),
  3235. clist_Authorization: $('#clist_Authorization').val()
  3236. };
  3237.  
  3238. // 判断是否改变
  3239. let hasChange = false;
  3240. for (const [key, value] of Object.entries(settings)) {
  3241. if (!hasChange && GM_getValue(key) != value) hasChange = true;
  3242. }
  3243. if (!hasChange && JSON.stringify(GM_getValue('chatgpt-config')) != JSON.stringify(tempConfig)) hasChange = true;
  3244.  
  3245. if (hasChange) {
  3246. const shouldSave = await saveConfirmation();
  3247. if (shouldSave) {
  3248. // 数据校验
  3249. if (settings.translation === "openai") {
  3250. var selectedIndex = $('input[name="config_item"]:checked').closest('li').index();
  3251. if (selectedIndex === -1) {
  3252. $('#configControlTip').text('请选择一项配置!');
  3253. $('.CFBetter_setting_sidebar a').removeClass('active');
  3254. $('#sidebar-translation-settings').addClass('active');
  3255. $('.settings-page').removeClass('active');
  3256. $('#translation-settings').addClass('active');
  3257. return;
  3258. }
  3259. }
  3260.  
  3261. // 保存数据
  3262. let refreshPage = false; // 是否需要刷新页面
  3263. for (const [key, value] of Object.entries(settings)) {
  3264. if (!refreshPage && !(key == 'translation' || key == 'darkMode' ||
  3265. key == 'replaceSymbol' || key == 'commentTranslationChoice')) {
  3266. if (GM_getValue(key) != value) refreshPage = true;
  3267. }
  3268. GM_setValue(key, value);
  3269. }
  3270. GM_setValue('chatgpt-config', tempConfig);
  3271.  
  3272. if (refreshPage) location.reload();
  3273. else {
  3274. // 切换黑暗模式
  3275. if (darkMode != settings.darkMode) {
  3276. darkMode = settings.darkMode;
  3277. // 移除旧的事件监听器
  3278. changeEventListeners.forEach(listener => {
  3279. mediaQueryList.removeEventListener('change', listener);
  3280. });
  3281.  
  3282. if (darkMode == "follow") {
  3283. changeEventListeners.push(handleColorSchemeChange);
  3284. mediaQueryList.addEventListener('change', handleColorSchemeChange);
  3285. $('html').removeAttr('data-theme');
  3286. } else if (darkMode == "dark") {
  3287. $('html').attr('data-theme', 'dark');
  3288. } else {
  3289. $('html').attr('data-theme', 'light');
  3290. // 移除旧的事件监听器
  3291. const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
  3292. window.matchMedia('(prefers-color-scheme: dark)');
  3293. }
  3294. }
  3295. // 更新配置信息
  3296. translation = settings.translation;
  3297. replaceSymbol = settings.replaceSymbol;
  3298. commentTranslationChoice = settings.commentTranslationChoice;
  3299. if (settings.translation === "openai") {
  3300. var selectedIndex = $('#config_bar_ul li input[type="radio"]:checked').closest('li').index();
  3301. if (selectedIndex !== opneaiConfig.choice) {
  3302. opneaiConfig = GM_getValue("chatgpt-config");
  3303. const configAtIndex = opneaiConfig.configurations[selectedIndex];
  3304. openai_model = configAtIndex.model;
  3305. openai_key = configAtIndex.key;
  3306. openai_proxy = configAtIndex.proxy;
  3307. openai_header = configAtIndex._header ?
  3308. configAtIndex._header.split("\n").map(header => {
  3309. const [key, value] = header.split(":");
  3310. return { [key.trim()]: value.trim() };
  3311. }) : [];
  3312. openai_data = configAtIndex._data ?
  3313. configAtIndex._data.split("\n").map(header => {
  3314. const [key, value] = header.split(":");
  3315. return { [key.trim()]: value.trim() };
  3316. }) : [];
  3317. }
  3318. }
  3319. }
  3320. }
  3321. }
  3322.  
  3323. $settingMenu.remove();
  3324. $settingBtns.prop("disabled", false).removeClass("open");
  3325. $(styleElement).remove();
  3326. });
  3327. });
  3328. };
  3329.  
  3330. // html2md转换/处理规则
  3331. var turndownService = new TurndownService({ bulletListMarker: '-' });
  3332. var turndown = turndownService.turndown;
  3333.  
  3334. // 保留原始
  3335. turndownService.keep(['del']);
  3336.  
  3337. // 丢弃
  3338. turndownService.addRule('remove-by-class', {
  3339. filter: function (node) {
  3340. return node.classList.contains('sample-tests') ||
  3341. node.classList.contains('header') ||
  3342. node.classList.contains('overlay') ||
  3343. node.classList.contains('html2md-panel') ||
  3344. node.classList.contains('likeForm');
  3345. },
  3346. replacement: function (content, node) {
  3347. return "";
  3348. }
  3349. });
  3350. turndownService.addRule('remove-script', {
  3351. filter: function (node, options) {
  3352. return node.tagName.toLowerCase() == "script" && node.type.startsWith("math/tex");
  3353. },
  3354. replacement: function (content, node) {
  3355. return "";
  3356. }
  3357. });
  3358.  
  3359. // inline math
  3360. turndownService.addRule('inline-math', {
  3361. filter: function (node, options) {
  3362. return node.tagName.toLowerCase() == "span" && node.className == "MathJax";
  3363. },
  3364. replacement: function (content, node) {
  3365. var latex = $(node).next().text();
  3366. latex = latex.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  3367. return "$" + latex + "$";
  3368. }
  3369. });
  3370.  
  3371. // block math
  3372. turndownService.addRule('block-math', {
  3373. filter: function (node, options) {
  3374. return node.tagName.toLowerCase() == "div" && node.className == "MathJax_Display";
  3375. },
  3376. replacement: function (content, node) {
  3377. var latex = $(node).next().text();
  3378. latex = latex.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  3379. return "\n$$\n" + latex + "\n$$\n";
  3380. }
  3381. });
  3382.  
  3383. // texFontStyle
  3384. turndownService.addRule('texFontStyle', {
  3385. filter: function (node) {
  3386. return (
  3387. node.nodeName === 'SPAN' &&
  3388. node.classList.contains('tex-font-style-bf')
  3389. )
  3390. },
  3391. replacement: function (content) {
  3392. return '**' + content + '**'
  3393. }
  3394. })
  3395.  
  3396. // sectionTitle
  3397. turndownService.addRule('sectionTitle', {
  3398. filter: function (node) {
  3399. return (
  3400. node.nodeName === 'DIV' &&
  3401. node.classList.contains('section-title')
  3402. )
  3403. },
  3404. replacement: function (content) {
  3405. return '**' + content + '**'
  3406. }
  3407. })
  3408.  
  3409. // bordertable
  3410. turndownService.addRule('bordertable', {
  3411. filter: 'table',
  3412. replacement: function (content, node) {
  3413. if (node.classList.contains('bordertable')) {
  3414. var output = [],
  3415. thead = '',
  3416. trs = node.querySelectorAll('tr');
  3417. if (trs.length > 0) {
  3418. var ths = trs[0].querySelectorAll('td,th');
  3419. if (ths.length > 0) {
  3420. thead = '| ' + Array.from(ths).map(th => turndownService.turndown(th.innerHTML.trim())).join(' | ') + ' |\n'
  3421. + '| ' + Array.from(ths).map(() => ' --- ').join('|') + ' |\n';
  3422. }
  3423. }
  3424. var rows = node.querySelectorAll('tr');
  3425. Array.from(rows).forEach(function (row, i) {
  3426. if (i > 0) {
  3427. var cells = row.querySelectorAll('td,th');
  3428. var trow = '| ' + Array.from(cells).map(cell => turndownService.turndown(cell.innerHTML.trim())).join(' | ') + ' |';
  3429. output.push(trow);
  3430. }
  3431. });
  3432. return thead + output.join('\n');
  3433. } else {
  3434. return content;
  3435. }
  3436. }
  3437. });
  3438.  
  3439. // 随机数生成
  3440. function getRandomNumber(numDigits) {
  3441. let min = Math.pow(10, numDigits - 1);
  3442. let max = Math.pow(10, numDigits) - 1;
  3443. return Math.floor(Math.random() * (max - min + 1)) + min;
  3444. }
  3445.  
  3446. // 题目markdown转换/翻译面板
  3447. function addButtonPanel(parent, suffix, type, is_simple = false) {
  3448. let translateButtonText;
  3449. if (commentTranslationMode == "1") translateButtonText = "分段翻译";
  3450. else if (commentTranslationMode == "2") translateButtonText = "翻译选中";
  3451. else translateButtonText = "翻译";
  3452.  
  3453. let htmlString = `<div class='html2md-panel'>
  3454. <button class='html2mdButton' id='html2md-view${suffix}'>MarkDown视图</button>
  3455. <button class='html2mdButton' id='html2md-cb${suffix}'>Copy</button>
  3456. <button class='html2mdButton' id='translateButton${suffix}'>${translateButtonText}</button>
  3457. </div>`;
  3458. if (type === "this_level") {
  3459. $(parent).before(htmlString);
  3460. var block = $("#translateButton" + suffix).parent().next();
  3461. } else if (type === "child_level") {
  3462. $(parent).prepend(htmlString);
  3463. var block = $("#translateButton" + suffix).parent().parent();
  3464. }
  3465. if (is_simple) {
  3466. $('.html2md-panel').find('.html2mdButton#html2md-view' + suffix + ', .html2mdButton#html2md-cb' + suffix).remove();
  3467. }
  3468.  
  3469. if (block.css("display") === "none" || block.hasClass('ojbetter-alert')) $("#translateButton" + suffix).parent().remove();
  3470. }
  3471. function addButtonWithHTML2MD(parent, suffix, type) {
  3472. if (is_oldLatex || is_acmsguru) {
  3473. $("#html2md-view" + suffix).css({
  3474. "cursor": "not-allowed",
  3475. "background-color": "#ffffff",
  3476. "color": "#a8abb2",
  3477. "border": "1px solid #e4e7ed"
  3478. });
  3479. $("#html2md-view" + suffix).prop("disabled", true);
  3480. }
  3481. $(document).on("click", "#html2md-view" + suffix, debounce(function () {
  3482. var target, removedChildren = $();
  3483. if (type === "this_level") {
  3484. target = $("#html2md-view" + suffix).parent().next().get(0);
  3485. } else if (type === "child_level") {
  3486. target = $("#html2md-view" + suffix).parent().parent().get(0);
  3487. removedChildren = $("#html2md-view" + suffix).parent().parent().children(':first').detach();
  3488. }
  3489. if (target.viewmd) {
  3490. target.viewmd = false;
  3491. $(this).text("MarkDown视图");
  3492. $(this).removeClass("mdViewed");
  3493. $(target).html(target.original_html);
  3494. } else {
  3495. target.viewmd = true;
  3496. if (!target.original_html) {
  3497. target.original_html = $(target).html();
  3498. }
  3499. if (!target.markdown) {
  3500. target.markdown = turndownService.turndown($(target).html());
  3501. }
  3502. $(this).text("原始内容");
  3503. $(this).addClass("mdViewed");
  3504. $(target).html(`<span class="mdViewContent" oninput="$(this).parent().get(0).markdown=this.value;" style="width:auto; height:auto;">${target.markdown}</span>`);
  3505. }
  3506. // 恢复删除的元素
  3507. if (removedChildren) $(target).prepend(removedChildren);
  3508. }));
  3509.  
  3510. if (hoverTargetAreaDisplay && !is_oldLatex && !is_acmsguru) {
  3511. var previousCSS;
  3512. $(document).on("mouseover", "#html2md-view" + suffix, function () {
  3513. var target;
  3514.  
  3515. if (type === "this_level") {
  3516. target = $("#html2md-view" + suffix).parent().next().get(0);
  3517. } else if (type === "child_level") {
  3518. target = $("#html2md-view" + suffix).parent().parent().get(0);
  3519. }
  3520.  
  3521. $(target).append('<div class="overlay">目标转换区域</div>');
  3522.  
  3523. previousCSS = {
  3524. "position": $(target).css("position"),
  3525. "display": $(target).css("display")
  3526. };
  3527. $(target).css({
  3528. "position": "relative",
  3529. "display": "block"
  3530. });
  3531.  
  3532. $("#html2md-view" + suffix).parent().css({
  3533. "position": "relative",
  3534. "z-index": "400"
  3535. });
  3536. });
  3537.  
  3538. $(document).on("mouseout", "#html2md-view" + suffix, function () {
  3539. var target;
  3540.  
  3541. if (type === "this_level") {
  3542. target = $("#html2md-view" + suffix).parent().next().get(0);
  3543. } else if (type === "child_level") {
  3544. target = $("#html2md-view" + suffix).parent().parent().get(0);
  3545. }
  3546.  
  3547. $(target).find('.overlay').remove();
  3548. if (previousCSS) {
  3549. $(target).css(previousCSS);
  3550. }
  3551. $("#html2md-view" + suffix).parent().css({
  3552. "position": "static"
  3553. });
  3554. });
  3555. }
  3556. }
  3557.  
  3558. function addButtonWithCopy(parent, suffix, type) {
  3559. if (is_oldLatex || is_acmsguru) {
  3560. $("#html2md-cb" + suffix).css({
  3561. "cursor": "not-allowed",
  3562. "background-color": "#ffffff",
  3563. "color": "#a8abb2",
  3564. "border": "1px solid #e4e7ed"
  3565. });
  3566. $("#html2md-cb" + suffix).prop("disabled", true);
  3567. }
  3568. $(document).on("click", "#html2md-cb" + suffix, debounce(function () {
  3569. var target, removedChildren;
  3570. if (type === "this_level") {
  3571. target = $("#translateButton" + suffix).parent().next().eq(0).clone();
  3572. } else if (type === "child_level") {
  3573. target = $("#translateButton" + suffix).parent().parent().eq(0).clone();
  3574. $(target).children(':first').remove();
  3575. }
  3576. if ($(target).find('.mdViewContent').length <= 0) {
  3577. text = turndownService.turndown($(target).html());
  3578. } else {
  3579. text = $(target).find('.mdViewContent').text();
  3580. }
  3581. GM_setClipboard(text);
  3582. $(this).addClass("copied");
  3583. $(this).text("Copied");
  3584. // 更新复制按钮文本
  3585. setTimeout(() => {
  3586. $(this).removeClass("copied");
  3587. $(this).text("Copy");
  3588. }, 2000);
  3589. $(target).remove();
  3590. }));
  3591.  
  3592. if (hoverTargetAreaDisplay && !is_oldLatex && !is_acmsguru) {
  3593. var previousCSS;
  3594. $(document).on("mouseover", "#html2md-cb" + suffix, function () {
  3595. var target;
  3596.  
  3597. if (type === "this_level") {
  3598. target = $("#html2md-cb" + suffix).parent().next().get(0);
  3599. } else if (type === "child_level") {
  3600. target = $("#html2md-cb" + suffix).parent().parent().get(0);
  3601. }
  3602.  
  3603. $(target).append('<div class="overlay">目标复制区域</div>');
  3604. previousCSS = {
  3605. "position": $(target).css("position"),
  3606. "display": $(target).css("display")
  3607. };
  3608. $(target).css({
  3609. "position": "relative",
  3610. "display": "block"
  3611. });
  3612. $("#html2md-cb" + suffix).parent().css({
  3613. "position": "relative",
  3614. "z-index": "400"
  3615. })
  3616. });
  3617.  
  3618. $(document).on("mouseout", "#html2md-cb" + suffix, function () {
  3619. var target;
  3620.  
  3621. if (type === "this_level") {
  3622. target = $("#html2md-cb" + suffix).parent().next().get(0);
  3623. } else if (type === "child_level") {
  3624. target = $("#html2md-cb" + suffix).parent().parent().get(0);
  3625. }
  3626.  
  3627. $(target).find('.overlay').remove();
  3628. if (previousCSS) {
  3629. $(target).css(previousCSS);
  3630. }
  3631. $("#html2md-cb" + suffix).parent().css({
  3632. "position": "static"
  3633. })
  3634. });
  3635. }
  3636. }
  3637.  
  3638. async function addButtonWithTranslation(parent, suffix, type, is_comment = false) {
  3639. var resultStack = []; // 结果
  3640. $(document).on('click', '#translateButton' + suffix, debounce(async function () {
  3641. $(this).trigger('mouseout')
  3642. .removeClass("translated")
  3643. .text("翻译中")
  3644. .css("cursor", "not-allowed")
  3645. .prop("disabled", true);
  3646. var target, element_node, block, errerNum = 0;
  3647. if (type === "this_level") block = $("#translateButton" + suffix).parent().next();
  3648. else if (type === "child_level") block = $("#translateButton" + suffix).parent().parent();
  3649.  
  3650. // 重新翻译
  3651. if (resultStack) {
  3652. let pElements = block.find("p.block_selected:not(li p), li.block_selected");
  3653. for (let item of resultStack) {
  3654. if (retransAction == "0") {
  3655. // 选段翻译不直接移除旧结果
  3656. if (commentTranslationMode == "2") {
  3657. // 只移除即将要翻译的段的结果
  3658. if (pElements.is(item.panelDiv.prev())) {
  3659. if (item.translateDiv) $(item.translateDiv).remove();
  3660. if (item.panelDiv) $(item.panelDiv).remove();
  3661. if (!is_oldLatex && !is_acmsguru) {
  3662. if (item.copyDiv) $(item.copyDiv).remove();
  3663. }
  3664. }
  3665. } else {
  3666. if (item.translateDiv) $(item.translateDiv).remove();
  3667. if (item.panelDiv) $(item.panelDiv).remove();
  3668. if (!is_oldLatex && !is_acmsguru) {
  3669. if (item.copyDiv) $(item.copyDiv).remove();
  3670. }
  3671. $(block).find(".translate-problem-statement, .translate-problem-statement-panel").remove();
  3672. }
  3673. } else {
  3674. item.upButton.html(unfoldIcon);
  3675. $(item.translateDiv).css({
  3676. display: "none",
  3677. transition: "height 2s"
  3678. });
  3679. }
  3680. }
  3681.  
  3682. // 移除旧的事件
  3683. $(document).off("mouseover", "#translateButton" + suffix);
  3684. $(document).off("mouseout", "#translateButton" + suffix);
  3685. // 重新绑定悬停事件
  3686. if (hoverTargetAreaDisplay) bindHoverEvents(suffix, type);
  3687. }
  3688.  
  3689. if (commentTranslationMode == "1") {
  3690. // 分段翻译
  3691. var pElements = block.find("p:not(li p), li, .CFBetter_acmsguru");
  3692. for (let i = 0; i < pElements.length; i++) {
  3693. target = $(pElements[i]).eq(0).clone();
  3694. element_node = pElements[i];
  3695. if (type === "child_level") {
  3696. $(pElements[i]).append("<div></div>");
  3697. element_node = $(pElements[i]).find("div:last-child").get(0);
  3698. }
  3699. resultStack.push(await blockProcessing(target, element_node, $("#translateButton" + suffix), is_comment));
  3700.  
  3701. let topStack = resultStack[resultStack.length - 1];
  3702. if (topStack.status) errerNum += 1;
  3703. $(target).remove();
  3704. await new Promise(resolve => setTimeout(resolve, transWaitTime));
  3705. }
  3706. } else if (commentTranslationMode == "2") {
  3707. // 选段翻译
  3708. var pElements = block.find("p.block_selected:not(li p), li.block_selected, .CFBetter_acmsguru");
  3709. for (let i = 0; i < pElements.length; i++) {
  3710. target = $(pElements[i]).eq(0).clone();
  3711. element_node = pElements[i];
  3712. if (type === "child_level") {
  3713. $(pElements[i]).append("<div></div>");
  3714. element_node = $(pElements[i]).find("div:last-child").get(0);
  3715. }
  3716. resultStack.push(await blockProcessing(target, element_node, $("#translateButton" + suffix), is_comment));
  3717.  
  3718. let topStack = resultStack[resultStack.length - 1];
  3719. if (topStack.status) errerNum += 1;
  3720. $(target).remove();
  3721. await new Promise(resolve => setTimeout(resolve, transWaitTime));
  3722. }
  3723. block.find("p.block_selected:not(li p), li.block_selected").removeClass('block_selected');
  3724. } else {
  3725. // 普通翻译
  3726. target = block.eq(0).clone();
  3727. if (type === "child_level") $(target).children(':first').remove();
  3728. element_node = $(block).get(0);
  3729. if (type === "child_level") {
  3730. $(parent).append("<div></div>");
  3731. element_node = $(parent).find("div:last-child").get(0);
  3732. }
  3733. //是否跳过折叠块
  3734. if ($(target).find('.spoiler').length > 0) {
  3735. const shouldSkip = await skiFoldingBlocks();
  3736. if (shouldSkip) {
  3737. $(target).find('.spoiler').remove();
  3738. } else {
  3739. $(target).find('.html2md-panel').remove();
  3740. }
  3741. }
  3742. resultStack.push(await blockProcessing(target, element_node, $("#translateButton" + suffix), is_comment));
  3743.  
  3744. let topStack = resultStack[resultStack.length - 1];
  3745. if (topStack.status) errerNum += 1;
  3746. $(target).remove();
  3747. }
  3748. if (!errerNum) {
  3749. $(this).addClass("translated")
  3750. .text("已翻译")
  3751. .css("cursor", "pointer")
  3752. .removeClass("error")
  3753. .prop("disabled", false);
  3754. } else {
  3755. $(this).prop("disabled", false);
  3756. }
  3757.  
  3758. // 重新翻译
  3759. let currentText, is_error;
  3760. $(document).on("mouseover", "#translateButton" + suffix, function () {
  3761. currentText = $(this).text();
  3762. $(this).text("重新翻译");
  3763. if ($(this).hasClass("error")) {
  3764. is_error = true;
  3765. $(this).removeClass("error");
  3766. }
  3767. });
  3768.  
  3769. $(document).on("mouseout", "#translateButton" + suffix, function () {
  3770. $(this).text(currentText);
  3771. if (is_error) $(this).addClass("error");
  3772. });
  3773. }));
  3774.  
  3775. // 目标区域指示
  3776. function bindHoverEvents(suffix, type) {
  3777. var previousCSS;
  3778.  
  3779. $(document).on("mouseover", "#translateButton" + suffix, function () {
  3780. var target;
  3781.  
  3782. if (type === "this_level") {
  3783. target = $("#translateButton" + suffix).parent().next().get(0);
  3784. } else if (type === "child_level") {
  3785. target = $("#translateButton" + suffix).parent().parent().get(0);
  3786. }
  3787.  
  3788. $(target).append('<div class="overlay">目标翻译区域</div>');
  3789.  
  3790. previousCSS = {
  3791. "position": $(target).css("position"),
  3792. "display": $(target).css("display")
  3793. };
  3794. $(target).css({
  3795. "position": "relative",
  3796. "display": ($(target).hasClass('question-response')) ? "block" : $(target).css("display")
  3797. });
  3798.  
  3799. $("#translateButton" + suffix).parent().css({
  3800. "position": "relative",
  3801. "z-index": "400"
  3802. });
  3803. });
  3804.  
  3805. $(document).on("mouseout", "#translateButton" + suffix, function () {
  3806. var target;
  3807.  
  3808. if (type === "this_level") {
  3809. target = $("#translateButton" + suffix).parent().next().get(0);
  3810. } else if (type === "child_level") {
  3811. target = $("#translateButton" + suffix).parent().parent().get(0);
  3812. }
  3813.  
  3814. $(target).find('.overlay').remove();
  3815.  
  3816. if (previousCSS) {
  3817. $(target).css(previousCSS);
  3818. }
  3819.  
  3820. $("#translateButton" + suffix).parent().css({
  3821. "position": "static"
  3822. });
  3823. });
  3824. }
  3825.  
  3826. if (hoverTargetAreaDisplay) bindHoverEvents(suffix, type);
  3827.  
  3828. // 右键菜单
  3829. $(document).on('contextmenu', '#translateButton' + suffix, function (e) {
  3830. e.preventDefault();
  3831.  
  3832. // 是否为评论的翻译
  3833. let is_comment = false;
  3834. if ($("#translateButton" + suffix).parents('.comments').length > 0) is_comment = true;
  3835.  
  3836. // 移除旧的
  3837. if (!$(e.target).closest('.CFBetter_contextmenu').length) {
  3838. $('.CFBetter_contextmenu').remove();
  3839. }
  3840.  
  3841. var menu = $('<div class="CFBetter_contextmenu"></div>');
  3842. var translations = [
  3843. { value: 'deepl', name: 'deepl翻译' },
  3844. { value: 'iflyrec', name: '讯飞听见翻译' },
  3845. { value: 'youdao', name: '有道翻译' },
  3846. { value: 'google', name: 'Google翻译' },
  3847. { value: 'caiyun', name: '彩云小译翻译' },
  3848. { value: 'openai', name: 'ChatGPT翻译' }
  3849. ];
  3850. if (is_comment) {
  3851. var label = $('<label><input type="radio" name="translation" value="0"><span class="CFBetter_contextmenu_label_text">跟随首选项</span></label>');
  3852. menu.append(label);
  3853. }
  3854. translations.forEach(function (translation) {
  3855. var label = $(`<label><input type="radio" name="translation" value="${translation.value}">
  3856. <span class="CFBetter_contextmenu_label_text">${translation.name}</span></label>`);
  3857. menu.append(label);
  3858. });
  3859.  
  3860. // 初始化
  3861. if (is_comment) {
  3862. menu.find(`input[name="translation"][value="${commentTranslationChoice}"]`).prop('checked', true);
  3863. } else {
  3864. menu.find(`input[name="translation"][value="${translation}"]`).prop('checked', true);
  3865. }
  3866. menu.css({
  3867. top: e.pageY + 'px',
  3868. left: e.pageX + 'px'
  3869. }).appendTo('body');
  3870.  
  3871. $(document).one('change', 'input[name="translation"]', function () {
  3872. if (is_comment) {
  3873. commentTranslationChoice = $('input[name="translation"]:checked').val();
  3874. GM_setValue("commentTranslationChoice", commentTranslationChoice);
  3875. } else {
  3876. translation = $('input[name="translation"]:checked').val();
  3877. GM_setValue("translation", translation);
  3878. }
  3879. $('.CFBetter_contextmenu').remove();
  3880. });
  3881.  
  3882. // 点击区域外关闭菜单
  3883. function handleClick(event) {
  3884. if (!$(event.target).closest('.CFBetter_contextmenu').length) {
  3885. $('.CFBetter_contextmenu').remove();
  3886. $(document).off('change', 'input[name="translation"]');
  3887. } else {
  3888. $(document).one('click', handleClick);
  3889. }
  3890. }
  3891. $(document).one('click', handleClick);
  3892. });
  3893. }
  3894.  
  3895. // 块处理
  3896. async function blockProcessing(target, element_node, button, is_comment) {
  3897. if (is_oldLatex || is_acmsguru) {
  3898. $(target).find('.overlay').remove();
  3899. target.markdown = $(target).html();
  3900. } else if (!target.markdown) {
  3901. target.markdown = turndownService.turndown($(target).html());
  3902. }
  3903. const textarea = document.createElement('textarea');
  3904. textarea.value = target.markdown;
  3905. var result = await translateProblemStatement(textarea.value, element_node, $(button), is_comment);
  3906. if (result.status == 1) {
  3907. $(button).addClass("error")
  3908. .text("翻译中止")
  3909. .css("cursor", "pointer")
  3910. .prop("disabled", false);
  3911. $(result.translateDiv).remove();
  3912. $(target).remove();
  3913. } else if (result.status == 2) {
  3914. result.translateDiv.classList.add("error_translate");
  3915. $(button).addClass("error")
  3916. .text("翻译出错")
  3917. .css("cursor", "pointer")
  3918. .prop("disabled", false);
  3919. $(target).remove();
  3920. }
  3921. return result;
  3922. }
  3923.  
  3924. // 选段翻译支持
  3925. async function multiChoiceTranslation() {
  3926. GM_addStyle(`
  3927. .topic .content .ttypography {
  3928. overflow: initial;
  3929. }
  3930. `);
  3931.  
  3932. $(document).on('click', 'p, li:not(:has(.comment)), .CFBetter_acmsguru', function (e) {
  3933. let $this = $(this);
  3934. e.stopPropagation();
  3935. if ($this.hasClass('block_selected')) {
  3936. $this.removeClass('block_selected');
  3937. // 移除对应的按钮
  3938. $('.CFBetter_MiniTranslateButton').remove("#translateButton_selected_" + $this.attr('CFBetter_p_id'));
  3939. } else {
  3940. let id = getRandomNumber(8);
  3941. $this.attr('CFBetter_p_id', id);
  3942. $this.addClass('block_selected');
  3943. // 添加按钮
  3944. let menu = $(`<div class="CFBetter_MiniTranslateButton" id='translateButton_selected_${id}'>${translateIcon}</div>`)
  3945. .css({
  3946. left: $($this).outerWidth(true) + $($this).position().left + 10 + 'px',
  3947. });
  3948. $this.before(menu);
  3949.  
  3950. $("#translateButton_selected_" + id).click(async function () {
  3951. // 处理旧的结果
  3952. if ($this.attr('translated')) {
  3953. let result = $this.data("resultData");
  3954. if (retransAction == "0") {
  3955. if (result.translateDiv) $(result.translateDiv).remove();
  3956. if (result.panelDiv) $(result.panelDiv).remove();
  3957. if (!is_oldLatex && !is_acmsguru) {
  3958. if (result.copyDiv) $(result.copyDiv).remove();
  3959. }
  3960. } else {
  3961. result.upButton.html(unfoldIcon);
  3962. $(result.translateDiv).css({
  3963. display: "none",
  3964. transition: "height 2s"
  3965. });
  3966. }
  3967. }
  3968. // 翻译
  3969. let target = $this.eq(0).clone();
  3970. let result = await blockProcessing(target, $this.eq(0), $("#translateButton_selected_" + id), false);
  3971. $this.data("resultData", result);
  3972. $this.removeClass('block_selected');
  3973. // 移除对应的按钮
  3974. $('.CFBetter_MiniTranslateButton').remove("#translateButton_selected_" + id);
  3975. $this.attr('translated', '1'); // 标记已翻译
  3976. });
  3977. }
  3978. });
  3979. }
  3980.  
  3981. // 为acmsguru题面重新划分div
  3982. function acmsguruReblock() {
  3983. if (commentTranslationMode == '0') {
  3984. // 普通模式下的划分方式
  3985. var html = $('.ttypography').children().html();
  3986. var separator = /(<div align="left" style="margin-top: 1\.0em;"><b>.*?<\/b><\/div>)/g;
  3987. var result = html.split(separator); // 分割代码
  3988. var outputHtml = '';
  3989. var header = '';
  3990. for (var i = 0; i < result.length; i++) {
  3991. if (separator.test(result[i])) {
  3992. header = result[i];
  3993. continue;
  3994. }
  3995. outputHtml += '<div class="ttypography">' + header + result[i] + '</div>';
  3996. header = '';
  3997. }
  3998. $('.ttypography').html(outputHtml);
  3999. }
  4000. else {
  4001. // 分段/选段模式下的划分方式
  4002. $('.ttypography').children().each(function () {
  4003. var html = $(this).html();
  4004. var replacedHtml = html.replace(/(?:<\/div>|<br><br>)(?<text>[\s\S]+?)(?=<br><br>)/g,
  4005. '<div align="left" class="CFBetter_acmsguru" >$<text></div>');
  4006. $(this).html(replacedHtml);
  4007. });
  4008. }
  4009. }
  4010.  
  4011. function addConversionButton() {
  4012. // 题目页添加按钮
  4013. if (window.location.href.includes("problem")) {
  4014. var exContentsPageClasses = ["sample-tests",];
  4015. $('.problem-statement').children('div').each(function () {
  4016. var className = $(this).attr('class');
  4017. if (!exContentsPageClasses.includes(className)) {
  4018. var id = "_problem_" + getRandomNumber(8);
  4019. addButtonPanel(this, id, "this_level");
  4020. addButtonWithHTML2MD(this, id, "this_level");
  4021. addButtonWithCopy(this, id, "this_level");
  4022. addButtonWithTranslation(this, id, "this_level");
  4023. }
  4024. });
  4025. }
  4026. // 添加按钮到ttypography部分
  4027. $(".ttypography").each(function () {
  4028. // 是否为评论
  4029. let is_comment = false;
  4030. if ($(this).parents('.comments').length > 0) is_comment = true;
  4031. // 题目页特判
  4032. if (!$(this).parent().hasClass('problemindexholder') || is_acmsguru) {
  4033. let id = "_comment_" + getRandomNumber(8);
  4034. addButtonPanel(this, id, "this_level");
  4035. addButtonWithHTML2MD(this, id, "this_level");
  4036. addButtonWithCopy(this, id, "this_level");
  4037. addButtonWithTranslation(this, id, "this_level", is_comment);
  4038. }
  4039. });
  4040.  
  4041. // 添加按钮到spoiler部分
  4042. $('.spoiler-content').each(function () {
  4043. if ($(this).find('.html2md-panel').length === 0) {
  4044. let id = "_spoiler_" + getRandomNumber(8);
  4045. addButtonPanel(this, id, "child_level");
  4046. addButtonWithHTML2MD(this, id, "child_level");
  4047. addButtonWithCopy(this, id, "child_level");
  4048. addButtonWithTranslation(this, id, "child_level");
  4049. }
  4050. });
  4051.  
  4052. // 添加按钮到titled部分
  4053. (function () {
  4054. var elements = [".Virtual.participation", ".Attention", ".Practice"];//只为部分titled添加
  4055. $.each(elements, function (index, value) {
  4056. $(value).each(function () {
  4057. let id = "_titled_" + getRandomNumber(8);
  4058. var $nextDiv = $(this).next().children().get(0);
  4059. addButtonPanel($nextDiv, id, "child_level", true);
  4060. addButtonWithTranslation($nextDiv, id, "child_level");
  4061. });
  4062. });
  4063. })();
  4064. if (is_mSite) {
  4065. $("div[class='_IndexPage_notice']").each(function () {
  4066. let id = "_titled_" + getRandomNumber(8);
  4067. addButtonPanel(this, id, "this_level", true);
  4068. addButtonWithTranslation(this, id, "this_level");
  4069. });
  4070. }
  4071.  
  4072. // 添加按钮到比赛QA部分
  4073. $(".question-response").each(function () {
  4074. let id = "_question_" + getRandomNumber(8);
  4075. addButtonPanel(this, id, "this_level", true);
  4076. addButtonWithTranslation(this, id, "this_level");
  4077. });
  4078. if (is_mSite) {
  4079. $("div._ProblemsPage_announcements table tbody tr:gt(0)").each(function () {
  4080. var $nextDiv = $(this).find("td:first");
  4081. let id = "_question_" + getRandomNumber(8);
  4082. addButtonPanel($nextDiv, id, "this_level", true);
  4083. addButtonWithTranslation($nextDiv, id, "this_level");
  4084. });
  4085. }
  4086.  
  4087. // 添加按钮到弹窗confirm-proto部分
  4088. $(".confirm-proto").each(function () {
  4089. let id = "_titled_" + getRandomNumber(8);
  4090. var $nextDiv = $(this).children().get(0);
  4091. addButtonPanel($nextDiv, id, "this_level", true);
  4092. addButtonWithTranslation($nextDiv, id, "this_level");
  4093. });
  4094.  
  4095. // 添加按钮到_CatalogHistorySidebarFrame_item部分
  4096. $("._CatalogHistorySidebarFrame_item").each(function () {
  4097. let id = "_history_sidebar_" + getRandomNumber(8);
  4098. addButtonPanel(this, id, "this_level", true);
  4099. addButtonWithTranslation(this, id, "this_level");
  4100. });
  4101.  
  4102. $(".problem-lock-link").on("click", function () {
  4103. $(".popup .content div").each(function () {
  4104. let id = "_popup_" + getRandomNumber(8);
  4105. addButtonPanel(this, id, "this_level", true);
  4106. addButtonWithTranslation(this, id, "this_level");
  4107. });
  4108. });
  4109.  
  4110. // 添加按钮到弹窗alert部分
  4111. $(".alert:not(.CFBetter_alert)").each(function () {
  4112. let id = "_alert_" + getRandomNumber(8);
  4113. addButtonPanel(this, id, "this_level", true);
  4114. addButtonWithTranslation(this, id, "this_level");
  4115. });
  4116.  
  4117. // 添加按钮到talk-text部分
  4118. $(".talk-text").each(function () {
  4119. let id = "_talk-text_" + getRandomNumber(8);
  4120. addButtonPanel(this, id, "child_level", true);
  4121. addButtonWithTranslation(this, id, "child_level");
  4122. });
  4123. };
  4124.  
  4125. //弹窗翻译
  4126. function alertZh() {
  4127. var _alert = window.alert;
  4128. window.alert = async function (msg) {
  4129. _alert(msg + "\n=========翻译=========\n" + await translate_deepl(msg));
  4130. return true;
  4131. }
  4132. };
  4133.  
  4134. // 折叠块
  4135. function ExpandFoldingblocks() {
  4136. $('.spoiler').addClass('spoiler-open');
  4137. $('.spoiler-content').attr('style', '');
  4138. };
  4139.  
  4140. // 折叠块渲染优化
  4141. function RenderPerfOpt() {
  4142. GM_addStyle(`
  4143. .spoiler-content {
  4144. contain: layout style;
  4145. }
  4146. `);
  4147. // return new Promise(function (resolve) {
  4148. // var currentIndex = 0;
  4149. // var delay = 50;
  4150. // var maxDelay = 1000;
  4151.  
  4152. // var elements = $('.spoiler-content');
  4153. // var batchSize = 10;
  4154. // var initialDelay = 50;
  4155.  
  4156. // function processBatch(callback) {
  4157. // var endIndex = currentIndex + batchSize;
  4158. // for (var i = currentIndex; i < endIndex; i++) {
  4159. // if (i >= elements.length) {
  4160. // callback();
  4161. // resolve();
  4162. // return;
  4163. // }
  4164. // var element = elements.eq(i);
  4165. // var height = element.outerHeight();
  4166. // element.css('contain-intrinsic-size', `auto ${height}px`);
  4167. // }
  4168.  
  4169. // currentIndex += batchSize;
  4170.  
  4171. // // 延时
  4172. // delay *= 2;
  4173. // if (delay >= maxDelay) delay = initialDelay;
  4174.  
  4175. // setTimeout(function () {
  4176. // processBatch(callback); // 递归
  4177. // }, delay);
  4178. // }
  4179.  
  4180. // processBatch(function () {
  4181. // GM_addStyle(`
  4182. // .spoiler-content {
  4183. // contain: layout style;
  4184. // }
  4185. // `);
  4186. // });
  4187. // });
  4188. }
  4189.  
  4190. // 分页
  4191. function CommentPagination() {
  4192. GM_addStyle(`
  4193. .comments > .comment {
  4194. display: none;
  4195. }
  4196. #next-page-btn, #prev-page-btn {
  4197. display: none;
  4198. }
  4199. #jump-input, #items-per-page{
  4200. height: 22px;
  4201. border: 1px solid #dcdfe6;
  4202. border-radius: 0.3rem;
  4203. }
  4204. #jump-input:focus-visible{
  4205. border-style: solid;
  4206. border-color: #3f51b5;
  4207. outline: none;
  4208. }
  4209. `);
  4210. $('.comments').after(`
  4211. <div id="pagBar" style="display: flex; align-items: center; justify-content: center; color: #606266;">
  4212. <label for="items-per-page">每页展示主楼数:</label>
  4213. <select id="items-per-page" style="margin-right: 15px;">
  4214. <option value="5">5</option>
  4215. <option value="10">10</option>
  4216. <option value="20">20</option>
  4217. </select>
  4218. <div class="paging" style="margin-right: 15px;">
  4219. <span id="current-page">1</span> / <span id="total-pages"></span>
  4220. </div>
  4221. <input type="text" id="jump-input" placeholder="跳转到页码">
  4222. <button type="button" id="jump-btn" class="html2mdButton">跳转</button>
  4223. <button id="prev-page-btn" class="html2mdButton">上一页</button>
  4224. <button id="next-page-btn" class="html2mdButton">下一页</button>
  4225. </div>
  4226. `);
  4227.  
  4228. let batchSize = 5;
  4229. let elements = $(".comments > .comment").slice(0, -1);
  4230. let start = 0;
  4231. let end = batchSize;
  4232. let currentPage = 1;
  4233. let displayedIndexes = []; // 存储已显示元素的索引
  4234.  
  4235. function showBatch(start, end) {
  4236. // 隐藏上一页
  4237. for (var i = 0; i < displayedIndexes.length; i++) {
  4238. elements.eq(displayedIndexes[i]).hide();
  4239. }
  4240.  
  4241. displayedIndexes = [];
  4242.  
  4243. // 显示当前页
  4244. elements.slice(start, end).each(function (index) {
  4245. $(this).show();
  4246. displayedIndexes.push(start + index);
  4247. });
  4248.  
  4249. // 更新页码和翻页按钮
  4250. $("#current-page").text(currentPage);
  4251. $("#total-pages").text(Math.ceil(elements.length / batchSize));
  4252.  
  4253. if (currentPage === 1) $("#prev-page-btn").hide();
  4254. else $("#prev-page-btn").show();
  4255.  
  4256. if (end >= elements.length) $("#next-page-btn").hide();
  4257. else $("#next-page-btn").show();
  4258. }
  4259.  
  4260. // 初始化
  4261. var commentID = null;
  4262. var pageURL = window.location.href;
  4263. if (pageURL.includes("#comment-")) {
  4264. // 带评论区锚点的链接
  4265. var startIndex = pageURL.lastIndexOf("#comment-") + 9;
  4266. commentID = pageURL.substring(startIndex);
  4267. var indexInComments = null;
  4268. $(".comments > .comment").each(function (index) {
  4269. $(this).find(".comment-table").each(function () {
  4270. var tableCommentID = $(this).attr("commentid");
  4271. if (tableCommentID === commentID) {
  4272. indexInComments = index;
  4273. return false;
  4274. }
  4275. });
  4276. });
  4277. let page = Math.ceil((indexInComments + 1) / batchSize);
  4278. currentPage = !page ? 1 : page;
  4279. showBatch((currentPage - 1) * batchSize, currentPage * batchSize);
  4280. setTimeout(function () {
  4281. window.location.href = pageURL;
  4282. }, 1000);
  4283. } else {
  4284. showBatch(0, batchSize);
  4285. }
  4286.  
  4287. $("#prev-page-btn").on("click", function () {
  4288. var itemsPerPage = parseInt($("#items-per-page").val());
  4289. start = (currentPage - 2) * itemsPerPage;
  4290. end = (currentPage - 1) * itemsPerPage;
  4291. currentPage--;
  4292. showBatch(start, end);
  4293. });
  4294.  
  4295. $("#next-page-btn").on("click", function () {
  4296. var itemsPerPage = parseInt($("#items-per-page").val());
  4297. start = currentPage * itemsPerPage;
  4298. end = (currentPage + 1) * itemsPerPage;
  4299. currentPage++;
  4300. showBatch(start, end);
  4301. });
  4302.  
  4303. $("#jump-btn").on("click", function () {
  4304. var inputPage = parseInt($("#jump-input").val());
  4305.  
  4306. if (inputPage >= 1 && inputPage <= Math.ceil(elements.length / parseInt($("#items-per-page").val()))) {
  4307. var itemsPerPage = parseInt($("#items-per-page").val());
  4308. start = (inputPage - 1) * itemsPerPage;
  4309. end = inputPage * itemsPerPage;
  4310. currentPage = inputPage; // 更新当前页码
  4311. showBatch(start, end);
  4312. }
  4313. });
  4314.  
  4315. $("#items-per-page").on("change", function () {
  4316. batchSize = parseInt($(this).val());
  4317. let page = Math.ceil(end / batchSize);
  4318. currentPage = !page ? 1 : page;
  4319. let maxPage = Math.ceil(elements.length / batchSize);
  4320. if (currentPage > maxPage) currentPage = maxPage;
  4321. showBatch((currentPage - 1) * batchSize, currentPage * batchSize);
  4322. });
  4323. }
  4324.  
  4325. // 跳转洛谷
  4326. function getProblemId(url) {
  4327. const regex = url.includes('/contest/')
  4328. ? /\/contest\/(\d+)\/problem\/([A-Za-z\d]+)/
  4329. : /\/problemset\/problem\/(\d+)\/([A-Za-z\d]+)/;
  4330. const matchResult = url.match(regex);
  4331. return matchResult && matchResult.length >= 3 ? `${matchResult[1]}${matchResult[2]}` : '';
  4332. };
  4333.  
  4334. async function CF2luogu() {
  4335. const url = window.location.href;
  4336. const problemId = getProblemId(url);
  4337. const checkLinkExistence = (url) => {
  4338. return new Promise((resolve, reject) => {
  4339. GM.xmlHttpRequest({
  4340. method: "GET",
  4341. url,
  4342. headers: { "Range": "bytes=0-9999" }, // 获取前10KB数据
  4343. onload(response) {
  4344. if (response.responseText.match(/题目未找到/g)) {
  4345. resolve(false);
  4346. } else {
  4347. resolve(true);
  4348. }
  4349. },
  4350. onerror(error) {
  4351. reject(error);
  4352. }
  4353. });
  4354. });
  4355. };
  4356.  
  4357. let panelElement;
  4358. if ($('#CF2luoguPanel').length > 0) {
  4359. panelElement = $('#CF2luoguPanel');
  4360. } else {
  4361. panelElement = $("<div>")
  4362. .addClass("html2md-panel")
  4363. .attr("id", "CF2luoguPanel")
  4364. .insertBefore('.problemindexholder');
  4365. }
  4366.  
  4367. const LuoguUrl = `https://www.luogu.com.cn/problem/CF${problemId}`;
  4368. const result = await checkLinkExistence(LuoguUrl);
  4369. if (problemId && result) {
  4370. const problemLink = $("<a>")
  4371. .attr("id", "problemLink")
  4372. .attr("href", LuoguUrl)
  4373. .attr("target", "_blank")
  4374. .html(`<button style="height: 25px;" class="html2mdButton"><img style="width:45px; margin-right:2px;" src="https://cdn.luogu.com.cn/fe/logo.png"></button>`);
  4375. panelElement.append(problemLink);
  4376. }
  4377. }
  4378.  
  4379. // RatingClass
  4380. const ratingClassMap = {
  4381. 0: "rating_by_clist_color0",
  4382. 1200: "rating_by_clist_color1",
  4383. 1400: "rating_by_clist_color2",
  4384. 1600: "rating_by_clist_color3",
  4385. 1900: "rating_by_clist_color4",
  4386. 2100: "rating_by_clist_color5",
  4387. 2300: "rating_by_clist_color6",
  4388. 2400: "rating_by_clist_color7",
  4389. 2600: "rating_by_clist_color8",
  4390. 3000: "rating_by_clist_color9"
  4391. };
  4392. const cssMap = {
  4393. "rating_by_clist_color0": "#cccccc",
  4394. "rating_by_clist_color1": "#73e473",
  4395. "rating_by_clist_color2": "#77ddbb",
  4396. "rating_by_clist_color3": "#aaaaff",
  4397. "rating_by_clist_color4": "#ff88ff",
  4398. "rating_by_clist_color5": "#ffcc88",
  4399. "rating_by_clist_color6": "#ffbb55",
  4400. "rating_by_clist_color7": "#ff7777",
  4401. "rating_by_clist_color8": "#ff3333",
  4402. "rating_by_clist_color9": "#aa0000"
  4403. };
  4404. // cookie有效性检查
  4405. async function checkCookie(isContest = false) {
  4406. let ok = false, congested = false;
  4407. await new Promise((resolve, reject) => {
  4408. GM_xmlhttpRequest({
  4409. method: "GET",
  4410. url: "https://clist.by:443/api/v3/contest/?limit=1&resource_id=1",
  4411. onload: function (response) {
  4412. if (response.status === 200) ok = true;
  4413. resolve();
  4414. },
  4415. onerror: function (response) {
  4416. console.warn("访问clist.by出现错误,请稍后再试");
  4417. congested = true;
  4418. resolve();
  4419. }
  4420. });
  4421. });
  4422. if (isContest && !ok && !congested) {
  4423. await new Promise((resolve, reject) => {
  4424. GM_xmlhttpRequest({
  4425. method: "GET",
  4426. url: "https://clist.by:443/api/v3/contest/?limit=1&resource_id=1",
  4427. headers: {
  4428. "Authorization": clist_Authorization
  4429. },
  4430. onload: function (response) {
  4431. if (response.status === 200) ok = true;
  4432. resolve();
  4433. },
  4434. onerror: function (response) {
  4435. console.warn("访问clist.by出现错误,请稍后再试");
  4436. resolve();
  4437. }
  4438. });
  4439. });
  4440. }
  4441. if (!ok) {
  4442. var state = congested ? `当前访问Clist.by网络拥堵,请求已中断,请稍后再重试` :
  4443. `当前浏览器的Clist.by登录(不可用)Cookie可能已失效,请打开<a target="_blank" href="https://clist.by/">Clist.by</a>重新登录(不可用)
  4444. <br>说明:脚本的Clist Rating分显示实现依赖于Clist.by的登录(不可用)用户Cookie信息,
  4445. <br>脚本不会获取您在Clist.by站点上的具体Cookie信息,具体请阅读脚本页的说明`;
  4446. var newElement = $("<div></div>")
  4447. .addClass("alert alert-error ojbetter-alert").html(`Codeforces Better! —— ${state}`)
  4448. .css({ "margin": "1em", "text-align": "center", "position": "relative" });
  4449. $(".menu-box:first").next().after(newElement);
  4450. }
  4451. return ok;
  4452. }
  4453. // 创建css
  4454. function creatRatingCss(hasborder = true) {
  4455. let dynamicCss = "";
  4456. let hiddenCss = RatingHidden ? ":hover" : "";
  4457. for (let cssClass in cssMap) {
  4458. dynamicCss += "." + cssClass + hiddenCss + " {\n";
  4459. let border = hasborder ? ` border: 1px solid ${cssMap[cssClass]};\n` : ` border: 1px solid #dcdfe6;\n`;
  4460. dynamicCss += ` color: ${cssMap[cssClass]};\n${border}}\n`;
  4461. }
  4462. GM_addStyle(dynamicCss);
  4463. }
  4464. // 模拟请求获取
  4465. async function getRating(problem, problem_url, contest = null) {
  4466. problem = problem.replace(/\([\s\S]*?\)/g, '').replace(/^\s+|\s+$/g, '');
  4467. return new Promise((resolve, reject) => {
  4468. const queryString = `search=${problem}&resource=1`;
  4469. GM_xmlhttpRequest({
  4470. method: 'GET',
  4471. url: `https://clist.by/problems/?${queryString}`,
  4472. responseType: 'html',
  4473. onload: function (response) {
  4474. const html = response.responseText;
  4475. var cleanedHtml = html.replace(/src=(.|\s)*?"/g, '');
  4476. const trs = $(cleanedHtml).find('table').find('tbody tr');
  4477. let records = [];
  4478. trs.each(function (index) {
  4479. const rating = $(this).find('.problem-rating-column').text().trim();
  4480. const link = $(this).find('.problem-name-column').find('a').eq(1).attr('href');
  4481. var contests = [];
  4482. $(this).find('.problem-name-column').find('.pull-right a[title], .pull-right span[title]').each(function () {
  4483. var value = $(this).attr('title');
  4484. if (value) {
  4485. value = value.replace(/<br\/?><\/a>/g, '');
  4486. contests.push(value);
  4487. }
  4488. });
  4489. records.push({ rating: rating, link: link, contests: contests });
  4490. });
  4491. for (let record of records) {
  4492. let link;
  4493. if (typeof record.link !== 'undefined') link = record.link.replace(/http:/g, 'https:');
  4494. if (link == problem_url || link == problem_url + '/') {
  4495. resolve({
  4496. rating: parseInt(record.rating),
  4497. problem: problem
  4498. });
  4499. return;
  4500. } else if (contest != null) {
  4501. for (let item of record.contests) {
  4502. if (contest == item) {
  4503. resolve({
  4504. rating: parseInt(record.rating),
  4505. problem: problem
  4506. });
  4507. return;
  4508. }
  4509. }
  4510. }
  4511. }
  4512. reject('\n' + problem + '未找到该题目的数据\n');
  4513. },
  4514. onerror: function (response) {
  4515. reject(problem + '发生了错误!');
  4516. }
  4517. });
  4518. });
  4519. }
  4520. // contest页显示Rating
  4521. async function showRatingByClist_contest() {
  4522. if (!await checkCookie(true)) return;
  4523. creatRatingCss();
  4524.  
  4525. var clist_event = $('#sidebar').children().first().find('.rtable th').first().text();
  4526. var problemsMap = new Map();
  4527. await new Promise((resolve, reject) => {
  4528. GM_xmlhttpRequest({
  4529. method: "GET",
  4530. url: "https://clist.by/api/v3/contest/?limit=1&resource_id=1&with_problems=true&event=" + encodeURIComponent(clist_event),
  4531. headers: {
  4532. "Authorization": clist_Authorization
  4533. },
  4534. onload: function (response) {
  4535. var data = JSON.parse(response.responseText);
  4536. var objects = data.objects;
  4537. if (objects.length > 0) {
  4538. var problems = objects[0].problems;
  4539. for (var i = 0; i < problems.length; i++) {
  4540. var problem = problems[i];
  4541. problemsMap.set(problem.url, problem.rating);
  4542. }
  4543. resolve();
  4544. }
  4545. }
  4546. });
  4547. });
  4548.  
  4549. $('.datatable .id.left').each(function () {
  4550. let href = 'https://codeforces.com' + $(this).find('a').attr('href');
  4551. if (problemsMap.has(href)) {
  4552. var rating = problemsMap.get(href);
  4553. let className = "rating_by_clist_color9";
  4554. let keys = Object.keys(ratingClassMap);
  4555. for (let i = 0; i < keys.length; i++) {
  4556. if (rating < keys[i]) {
  4557. className = ratingClassMap[keys[i - 1]];
  4558. break;
  4559. }
  4560. }
  4561. $(this).find('a').after(`<div class="ratingBadges ${className}"><span class="rating">${rating}</span></div>`);
  4562. }
  4563. });
  4564. }
  4565. // problemset页显示Rating
  4566. async function showRatingByClist_problemset() {
  4567. if (!await checkCookie()) return;
  4568. creatRatingCss();
  4569.  
  4570. const $problems = $('.problems');
  4571. const $trs = $problems.find('tbody tr:gt(0)');
  4572.  
  4573. for (let i = 0; i < $trs.length; i += 3) {
  4574. const promises = [];
  4575. const endIndex = Math.min(i + 3, $trs.length);
  4576.  
  4577. for (let j = i; j < endIndex; j++) {
  4578. const $tds = $($trs[j]).find('td');
  4579. let problem = $($tds[1]).find('a:first').text();
  4580. let problem_url = $($tds[1]).find('a').attr('href');
  4581. problem_url = problem_url.replace(/^\/problemset\/problem\/(\d+)\/(\w+)/, 'https://codeforces.com/contest/$1/problem/$2');
  4582.  
  4583. promises.push(getRating(problem, problem_url).catch(error => console.warn(error)));
  4584. }
  4585.  
  4586. const results = await Promise.all(promises);
  4587.  
  4588. for (let j = i; j < endIndex; j++) {
  4589. const result = results[j - i];
  4590. if (result == undefined) continue;
  4591. let className = "rating_by_clist_color9";
  4592. let keys = Object.keys(ratingClassMap);
  4593. for (let k = 0; k < keys.length; k++) {
  4594. if (result.rating < keys[k]) {
  4595. className = ratingClassMap[keys[k - 1]];
  4596. break;
  4597. }
  4598. }
  4599.  
  4600. const $tds = $($trs[j]).find('td');
  4601. $($tds[0]).find('a').after(`<div class="ratingBadges ${className}"><span class="rating">${result.rating}</span></div>`);
  4602. }
  4603.  
  4604. // 延时100毫秒
  4605. // await new Promise(resolve => setTimeout(resolve, 100));
  4606. }
  4607. }
  4608. // problem页显示Rating
  4609. async function showRatingByClist_problem() {
  4610. if (!await checkCookie()) return;
  4611. creatRatingCss(false);
  4612.  
  4613. // 题目名
  4614. let problem = $('.header .title').eq(0).text().replace(/[\s\S]*?. /, '');
  4615. if (is_acmsguru) problem = $('h4').eq(0).text().replace(/[\s\S]*?. /, '');
  4616.  
  4617. // 题目链接
  4618. let problem_url = window.location.href;
  4619. if (problem_url.includes('/contest/')) {
  4620. problem_url = problem_url.replace(/\/contest\/(\d+)\/problem\/(\w+)[^\w]*/, '/contest/$1/problem/$2');
  4621. } else {
  4622. problem_url = problem_url.replace(/\/problemset\/problem\/(\d+)\/(\w+)/, '/contest/$1/problem/$2');
  4623. }
  4624. if (is_mSite) problem_url = problem_url.replace(/\/\/(\w+).codeforces.com/, '//codeforces.com'); // 轻量站
  4625.  
  4626. // 比赛名
  4627. let contest = $('#sidebar').children().first().find('.rtable th').first().text();
  4628.  
  4629. let result;
  4630. try {
  4631. result = await getRating(problem, problem_url, contest);
  4632. } catch (error) {
  4633. console.warn(error);
  4634. return;
  4635. }
  4636.  
  4637. let className = "rating_by_clist_color9";
  4638. let keys = Object.keys(ratingClassMap);
  4639. for (let i = 0; i < keys.length; i++) {
  4640. if (result.rating < keys[i]) {
  4641. className = ratingClassMap[keys[i - 1]];
  4642. break;
  4643. }
  4644. }
  4645. const RatingHtml = $(`<a id="problemLink" href="https://clist.by/problems/?search=${result.problem}&resource=1" target="_blank">
  4646. <button style="height: 25px;" class="html2mdButton ratingBadges ${className}">
  4647. ${clistIcon}<span style="padding: 1px 0px 0px 5px;">${result.rating}</span></button>
  4648. </a>`);
  4649. if ($('#CF2luoguPanel').length > 0) {
  4650. $('#CF2luoguPanel').append(RatingHtml);
  4651. } else {
  4652. const panelElement = $("<div>")
  4653. .addClass("html2md-panel")
  4654. .attr("id", "CF2luoguPanel");
  4655. if (is_mSite) {
  4656. panelElement.insertBefore('.problem-statement');
  4657. } else {
  4658. panelElement.insertBefore('.problemindexholder');
  4659. }
  4660. panelElement.append(RatingHtml);
  4661. }
  4662. }
  4663.  
  4664. // cf赛制榜单重新着色
  4665. function recolorStandings() {
  4666. function getColorValue(value) {
  4667. value = Math.max(0, Math.min(1, value));
  4668.  
  4669. const scale = chroma.scale(['#b71c1c', '#ff9800', '#ffc107', '#00aa00']).mode('lch').domain([0, 0.45, 0.7, 1]);
  4670. return scale(value).hex();
  4671. }
  4672. var maxScores = $('.standings tr:first th:nth-child(n+5)')
  4673. .map(function () {
  4674. return $(this).find('span').text();
  4675. })
  4676. .get();
  4677. $('.standings tr:not(:first):not(:last)').each(function () {
  4678. var thElements = $(this).find('td:nth-child(n+5)');
  4679. thElements.each(function (index) {
  4680. var spanElement = $(this).find('span:first');
  4681. var value = parseInt(spanElement.text());
  4682. if (value <= 0 || /[a-zA-Z]/.test(maxScores[index])) return;
  4683. var colorValue = getColorValue(value / maxScores[index]);
  4684. spanElement.css('color', colorValue);
  4685. });
  4686. });
  4687. }
  4688.  
  4689. // 等待LaTeX渲染队列全部完成
  4690. function waitUntilIdleThenDo(callback) {
  4691. var intervalId = setInterval(function () {
  4692. var queue = MathJax.Hub.queue;
  4693. if (queue.pending === 0 && queue.running === 0) {
  4694. clearInterval(intervalId);
  4695. callback();
  4696. }
  4697. }, 100);
  4698. }
  4699.  
  4700. // 字数超限确认
  4701. function showWordsExceededDialog(button, textLength, realTextLength) {
  4702. return new Promise(resolve => {
  4703. const styleElement = GM_addStyle(darkenPageStyle);
  4704. $(button).removeClass("translated");
  4705. $(button).text("字数超限");
  4706. $(button).css("cursor", "not-allowed");
  4707. $(button).prop("disabled", true);
  4708. let htmlString = `
  4709. <div class="CFBetter_modal">
  4710. <h2>字符数超限! </h2>
  4711. <p>即将翻译的内容共 <strong>${realTextLength}</strong> 字符</p>
  4712. <p>这超出了当前翻译服务的 <strong>${textLength}</strong> 字符上限,请更换翻译服务,或在设置面板中开启“分段翻译”</p>
  4713.  
  4714. <div style="display:flex; padding:5px 0px; align-items: center;">
  4715. `+ helpCircleHTML + `
  4716. <p>
  4717. 注意,可能您选择了错误的翻译按钮<br>
  4718. 由于实现方式,区域中会出现多个翻译按钮,请点击更小的子区域中的翻译按钮
  4719. </p>
  4720. </div>
  4721. <p>您确定要继续翻译吗?</p>
  4722. <div class="buttons">
  4723. <button id="continueButton">继续</button><button id="cancelButton">取消</button>
  4724. </div>
  4725. </div>
  4726. `;
  4727. $('body').before(htmlString);
  4728. $("#continueButton").click(function () {
  4729. $(styleElement).remove();
  4730. $('.CFBetter_modal').remove();
  4731. resolve(true);
  4732. });
  4733. $("#cancelButton").click(function () {
  4734. $(styleElement).remove();
  4735. $('.CFBetter_modal').remove();
  4736. resolve(false);
  4737. });
  4738. });
  4739. }
  4740.  
  4741. //跳过折叠块确认
  4742. function skiFoldingBlocks() {
  4743. return new Promise(resolve => {
  4744. const styleElement = GM_addStyle(darkenPageStyle);
  4745. let htmlString = `
  4746. <div class="CFBetter_modal">
  4747. <h2>是否跳过折叠块?</h2>
  4748. <p></p>
  4749. <div style="display:grid; padding:5px 0px; align-items: center;">
  4750. <p>
  4751. 即将翻译的区域中包含折叠块,折叠块可能是代码,通常不需要翻译,现在您需要选择是否跳过这些折叠块,
  4752. </p>
  4753. <p>
  4754. 如果其中有您需要翻译的折叠块,可以稍后再单独点击这些折叠块内的翻译按钮进行翻译
  4755. </p>
  4756. </div>
  4757. <p>要跳过折叠块吗?(建议选择跳过)</p>
  4758. <div class="buttons">
  4759. <button id="cancelButton">否</button><button id="skipButton">跳过</button>
  4760. </div>
  4761. </div>
  4762. `;
  4763. $('body').before(htmlString);
  4764. $("#skipButton").click(function () {
  4765. $(styleElement).remove();
  4766. $('.CFBetter_modal').remove();
  4767. resolve(true);
  4768. });
  4769. $("#cancelButton").click(function () {
  4770. $(styleElement).remove();
  4771. $('.CFBetter_modal').remove();
  4772. resolve(false);
  4773. });
  4774. });
  4775. }
  4776.  
  4777. // latex替换
  4778. function replaceBlock(text, matches, replacements) {
  4779. try {
  4780. for (let i = 0; i < matches.length; i++) {
  4781. let match = matches[i];
  4782. let replacement = '';
  4783. if (replaceSymbol === "1") {
  4784. replacement = `【${i + 1}】`;
  4785. } else if (replaceSymbol === "2") {
  4786. replacement = `{${i + 1}}`;
  4787. } else if (replaceSymbol === "3") {
  4788. replacement = `[${i + 1}]`;
  4789. }
  4790. text = text.replace(match, replacement);
  4791. replacements[replacement] = match;
  4792. }
  4793. } catch (e) { }
  4794. return text;
  4795. }
  4796.  
  4797. // latex还原
  4798. function recoverBlock(translatedText, matches, replacements) {
  4799. for (let i = 0; i < matches.length; i++) {
  4800. let match = matches[i];
  4801. let replacement = replacements[`【${i + 1}】`] || replacements[`[${i + 1}]`] || replacements[`{${i + 1}}`];
  4802.  
  4803. let latexMatch = '(?<latex_block>\\$\\$(\\\\.|[^\\$])*?\\$\\$)|(?<latex_inline>\\$(\\\\.|[^\\$])*?\\$)|';
  4804.  
  4805. let regex = new RegExp(latexMatch + `【\\s*${i + 1}\\s*】|\\[\\s*${i + 1}\\s*\\]|{\\s*${i + 1}\\s*}`, 'g');
  4806. translatedText = translatedText.replace(regex, function (match, ...args) {
  4807. // LaTeX中的不替换
  4808. const groups = args[args.length - 1]; // groups是replace方法的最后一个参数
  4809. if (groups.latex_block || groups.latex_inline) return match;
  4810. // 没有空格则加一个
  4811. const offset = args[args.length - 3]; // offset是replace方法的倒数第三个参数
  4812. let leftSpace = "", rightSpace = "";
  4813. if (!/\s/.test(translatedText[offset - 1])) leftSpace = " ";
  4814. if (!/\s/.test(translatedText[offset + match.length])) rightSpace = " ";
  4815. return leftSpace + replacement + rightSpace;
  4816. });
  4817.  
  4818. regex = new RegExp(latexMatch + `【\\s*${i + 1}(?![】\\d])|(?<![【\\d])${i + 1}\\s*】|\\[\\s*${i + 1}(?![\\]\\d])|(?<![\\[\\d])${i + 1}\\s*\\]|{\\s*${i + 1}(?![}\\d])|(?<![{\\d])${i + 1}\\s*}`, 'g');
  4819. translatedText = translatedText.replace(regex, function (match, ...args) {
  4820. // LaTeX中的不替换
  4821. const groups = args[args.length - 1];
  4822. if (groups.latex_block || groups.latex_inline) return match;
  4823. // 没有空格则加一个
  4824. const offset = args[args.length - 3];
  4825. let leftSpace = "", rightSpace = "";
  4826. if (!/\s/.test(translatedText[offset - 1])) leftSpace = " ";
  4827. if (!/\s/.test(translatedText[offset + match.length])) rightSpace = " ";
  4828. return leftSpace + replacement + rightSpace;
  4829. });
  4830. }
  4831. return translatedText;
  4832. }
  4833.  
  4834. // 翻译框/翻译处理器
  4835. var translatedText = "";
  4836. async function translateProblemStatement(text, element_node, button, is_comment) {
  4837. let status = 0;
  4838. let id = getRandomNumber(8);
  4839. let matches = [];
  4840. let replacements = {};
  4841. let translationService = {
  4842. "deepl": "DeepL",
  4843. "iflyrec": "讯飞听见",
  4844. "youdao": "有道",
  4845. "google": "Google",
  4846. "caiyun": "彩云小译",
  4847. "openai": "ChatGPT"
  4848. };
  4849. // 创建元素并放在element_node的后面
  4850. const translateDiv = $('<div>').attr('id', id).addClass('translate-problem-statement');
  4851. const spanElement = $('<span>');
  4852. translateDiv.append(spanElement);
  4853. $(element_node).after(translateDiv);
  4854.  
  4855. // panel
  4856. var panelDiv = $('<div>').addClass('translate-problem-statement-panel');
  4857. // 信息
  4858. var topText;
  4859. if (is_comment && commentTranslationChoice != "0") topText = $('<div>').text(translationService[commentTranslationChoice] + ' 翻译').addClass('topText');
  4860. else topText = $('<div>').text(translationService[translation] + ' 翻译').addClass('topText');
  4861. panelDiv.append(topText);
  4862. // 右侧
  4863. var rightDiv = $('<div>').css('display', 'flex');
  4864. panelDiv.append(rightDiv);
  4865. var copyButton = $('<div>').html(copyIcon).addClass('borderlessButton');
  4866. rightDiv.append(copyButton);
  4867. var upButton = $('<div>').html(putawayIcon).addClass('borderlessButton');
  4868. rightDiv.append(upButton);
  4869. var closeButton = $('<div>').html(closeIcon).addClass('borderlessButton');
  4870. rightDiv.append(closeButton);
  4871.  
  4872. panelDiv.insertBefore(translateDiv);
  4873.  
  4874. // 收起按钮
  4875. upButton.on("click", function () {
  4876. if (upButton.html() === putawayIcon) {
  4877. upButton.html(unfoldIcon);
  4878. $(translateDiv).css({
  4879. display: "none",
  4880. transition: "height 2s"
  4881. });
  4882. } else {
  4883. // 执行收起操作
  4884. upButton.html(putawayIcon);
  4885. $(translateDiv).css({
  4886. display: "",
  4887. transition: "height 2s"
  4888. });
  4889. }
  4890. });
  4891.  
  4892. // 关闭按钮
  4893. closeButton.on("click", function () {
  4894. $(translateDiv).remove();
  4895. $(panelDiv).remove();
  4896. });
  4897.  
  4898. // 替换latex公式
  4899. if (is_oldLatex) {
  4900. let regex = /<span\s+class="tex-span">.*?<\/span>/gi;
  4901. matches = matches.concat(text.match(regex));
  4902. text = replaceBlock(text, matches, replacements);
  4903. text = text.replace(/<p>(.*?)<\/p>/g, "$1\n\n"); // <p/>标签换为换行
  4904. } else if (is_acmsguru) {
  4905. let regex = /<i>.*?<\/i>|<sub>.*?<\/sub>|<sup>.*?<\/sup>|<pre>.*?<\/pre>/gi;
  4906. matches = matches.concat(text.match(regex));
  4907. text = replaceBlock(text, matches, replacements);
  4908. } else if (translation != "openai") {
  4909. // 使用GPT翻译时不必替换latex公式
  4910. let regex = /\$\$(\\.|[^\$])*?\$\$|\$(\\.|[^\$])*?\$/g;
  4911. matches = matches.concat(text.match(regex));
  4912. text = replaceBlock(text, matches, replacements);
  4913. }
  4914. // 字符数上限
  4915. const translationLimits = {
  4916. deepl: 5000,
  4917. iflyrec: 2000,
  4918. youdao: 600,
  4919. google: 5000,
  4920. caiyun: 5000
  4921. };
  4922. if (translationLimits.hasOwnProperty(translation) && text.length > translationLimits[translation]) {
  4923. const shouldContinue = await showWordsExceededDialog(button, translationLimits[translation], text.length);
  4924. if (!shouldContinue) {
  4925. status = 1;
  4926. return {
  4927. translateDiv: translateDiv,
  4928. status: status
  4929. };
  4930. }
  4931. }
  4932. // 翻译
  4933. async function translate(translation) {
  4934. try {
  4935. if (translation == "deepl") {
  4936. translateDiv.html(`正在使用 ${translationService[translation]} 翻译中……请稍等`);
  4937. translatedText = await translate_deepl(text);
  4938. } else if (translation == "iflyrec") {
  4939. translateDiv.html(`正在使用 ${translationService[translation]} 翻译中……请稍等`);
  4940. translatedText = await translate_iflyrec(text);
  4941. } else if (translation == "youdao") {
  4942. translateDiv.html(`正在使用 ${translationService[translation]} 翻译中……请稍等`);
  4943. translatedText = await translate_youdao_mobile(text);
  4944. } else if (translation == "google") {
  4945. translateDiv.html(`正在使用 ${translationService[translation]} 翻译中……请稍等`);
  4946. translatedText = await translate_gg(text);
  4947. } else if (translation == "caiyun") {
  4948. translateDiv.html(`正在使用 ${translationService[translation]} 翻译中……请稍等`);
  4949. await translate_caiyun_startup();
  4950. translatedText = await translate_caiyun(text);
  4951. } else if (translation == "openai") {
  4952. translateDiv.html("正在使用 ChatGPT 翻译中……" +
  4953. "<br><br>应用的配置:" + opneaiConfig.configurations[opneaiConfig.choice].note +
  4954. "<br><br>使用 ChatGPT 翻译需要很长的时间,请耐心等待");
  4955. translatedText = await translate_openai(text);
  4956. }
  4957. if (/^翻译出错/.test(translatedText)) status = 2;
  4958. } catch (error) {
  4959. status = 2;
  4960. translatedText = error;
  4961. }
  4962. }
  4963. if (is_comment && commentTranslationChoice != "0") await translate(commentTranslationChoice);
  4964. else await translate(translation);
  4965.  
  4966. // 还原latex公式
  4967. translatedText = translatedText.replace(/】\s*【/g, '】 【');
  4968. translatedText = translatedText.replace(/\]\s*\[/g, '] [');
  4969. translatedText = translatedText.replace(/\}\s*\{/g, '} {');
  4970. if (is_oldLatex) {
  4971. translatedText = translatedText.replace(/(.+?)(\n\n|$)/g, "<p>$1</p>"); // 还原为<p/>标签
  4972. translatedText = recoverBlock(translatedText, matches, replacements);
  4973. } else if (is_acmsguru) {
  4974. translatedText = recoverBlock(translatedText, matches, replacements);
  4975. } else if (translation != "openai") {
  4976. translatedText = recoverBlock(translatedText, matches, replacements);
  4977. }
  4978.  
  4979. // 结果复制按钮
  4980. if (!is_oldLatex && !is_acmsguru) {
  4981. // 创建一个隐藏的元素来保存 translatedText 的值
  4982. var textElement = document.createElement("div");
  4983. textElement.style.display = "none";
  4984. textElement.textContent = translatedText;
  4985. translateDiv.parent().insertBefore(textElement, translateDiv);
  4986.  
  4987. // 复制按钮
  4988. copyButton.on("click", function () {
  4989. var translatedText = textElement.textContent;
  4990. GM_setClipboard(translatedText);
  4991. copyButton.html(copyedIcon);
  4992. copyButton.css({ 'fill': '#8bc34a' });
  4993. // 复制提示
  4994. setTimeout(() => {
  4995. copyButton.html(copyIcon);
  4996. copyButton.css({ 'fill': '' });
  4997. }, 2000);
  4998. });
  4999. }
  5000.  
  5001. // 转义LaTex中的特殊符号
  5002. if (!is_oldLatex && !is_acmsguru) {
  5003. const escapeRules = [
  5004. { pattern: /(?<!\\)>(?!\s)/g, replacement: " &gt; " }, // >符号
  5005. { pattern: /(?<!\\)</g, replacement: " &lt; " }, // <符号
  5006. { pattern: /(?<!\\)\*/g, replacement: " &#42; " }, // *符号
  5007. { pattern: /(?<!\\)_/g, replacement: " &#95; " }, // _符号
  5008. { pattern: /(?<!\\)\\\\(?=\s)/g, replacement: "\\\\\\\\" }, // \\符号
  5009. { pattern: /(?<!\\)\\(?![\\a-zA-Z0-9])/g, replacement: "\\\\" }, // \符号
  5010. ];
  5011.  
  5012. let latexMatches = [...translatedText.matchAll(/\$\$([\s\S]*?)\$\$|\$(.*?)\$|\$([\s\S]*?)\$/g)];
  5013.  
  5014. for (const match of latexMatches) {
  5015. const matchedText = match[0];
  5016. var escapedText = matchedText;
  5017.  
  5018. for (const rule of escapeRules) {
  5019. escapedText = escapedText.replaceAll(rule.pattern, rule.replacement);
  5020. }
  5021. escapedText = escapedText.replace(/\$\$/g, "$$$$$$$$");// $$符号(因为后面需要作为replacement)
  5022. translatedText = translatedText.replace(matchedText, escapedText);
  5023. }
  5024. }
  5025.  
  5026. // 使符合mathjx的转换语法
  5027. const mathjaxRuleMap = [
  5028. { pattern: /\$/g, replacement: "$$$$$$" }, // $$ 行间
  5029. ];
  5030. mathjaxRuleMap.forEach(({ pattern, replacement }) => {
  5031. translatedText = translatedText.replace(pattern, replacement);
  5032. });
  5033.  
  5034. // markdown修正
  5035. const mdRuleMap = [
  5036. { pattern: /(\s_[\u4e00-\u9fa5]+_)([\u4e00-\u9fa5]+)/g, replacement: "$1 $2" }, // 斜体
  5037. { pattern: /(_[\u4e00-\u9fa5]+_\s)([\u4e00-\u9fa5]+)/g, replacement: " $1$2" },
  5038. { pattern: /(_[\u4e00-\u9fa5]+_)([\u4e00-\u9fa5]+)/g, replacement: " $1 $2" },
  5039. { pattern: /(([\s\S]*?))/g, replacement: "($1)" }, // 中文()
  5040. // { pattern: /:/g, replacement: ":" }, // 中文:
  5041. { pattern: /\*\* (.*?) \*\*/g, replacement: "\*\*$1\*\*" } // 加粗
  5042. ];
  5043. mdRuleMap.forEach(({ pattern, replacement }) => {
  5044. translatedText = translatedText.replace(pattern, replacement);
  5045. });
  5046.  
  5047. // 更新
  5048. if (is_oldLatex || is_acmsguru) {
  5049. // oldlatex
  5050. translatedText = $.parseHTML(translatedText);
  5051. translateDiv.empty().append($(translatedText));
  5052. return {
  5053. translateDiv: translateDiv,
  5054. status: status,
  5055. copyDiv: textElement,
  5056. panelDiv: panelDiv,
  5057. upButton: upButton
  5058. };
  5059. } else {
  5060. // 渲染MarkDown
  5061. var md = window.markdownit();
  5062. var html = md.render(translatedText);
  5063. translateDiv.html(html);
  5064. // 渲染Latex
  5065. MathJax.Hub.Queue(["Typeset", MathJax.Hub, translateDiv.get(0)]);
  5066.  
  5067. return {
  5068. translateDiv: translateDiv,
  5069. status: status,
  5070. copyDiv: textElement,
  5071. panelDiv: panelDiv,
  5072. upButton: upButton
  5073. };
  5074. }
  5075.  
  5076. }
  5077.  
  5078. // ChatGPT
  5079. async function translate_openai(raw) {
  5080. var openai_retext = "";
  5081. var data;
  5082. if (is_oldLatex || is_acmsguru) {
  5083. data = {
  5084. model: (openai_model !== null && openai_model !== "") ? openai_model : 'gpt-3.5-turbo',
  5085. messages: [{
  5086. role: "user",
  5087. content: "请将下面的文本翻译为中文,这是一道编程竞赛题描述的一部分,注意术语的翻译,注意保持其中的【】、HTML标签本身以及其中的内容不翻译不变动,你只需要回复翻译后的内容即可,不要回复任何其他内容:\n\n" + raw
  5088. }],
  5089. temperature: 0.7,
  5090. ...Object.assign({}, ...openai_data)
  5091. };
  5092. } else {
  5093. data = {
  5094. model: (openai_model !== null && openai_model !== "") ? openai_model : 'gpt-3.5-turbo',
  5095. messages: [{
  5096. role: "user",
  5097. content: "请将下面的文本翻译为中文,这是一道编程竞赛题描述的一部分,注意术语的翻译,注意保持其中的latex公式不翻译,你只需要回复翻译后的内容即可,不要回复任何其他内容:\n\n" + raw
  5098. }],
  5099. temperature: 0.7
  5100. };
  5101. };
  5102. return new Promise(function (resolve, reject) {
  5103. GM_xmlhttpRequest({
  5104. method: 'POST',
  5105. url: (openai_proxy !== null && openai_proxy !== "") ? openai_proxy : 'https://api.openai.com/v1/chat/completions',
  5106.  
  5107. data: JSON.stringify(data),
  5108. headers: {
  5109. 'Content-Type': 'application/json',
  5110. 'Authorization': 'Bearer ' + openai_key,
  5111. ...Object.assign({}, ...openai_header)
  5112. },
  5113. responseType: 'json',
  5114. onload: function (response) {
  5115. if (!response.response) {
  5116. reject("发生了未知的错误,如果你启用了代理API,请确认是否填写正确,并确保代理能够正常工作。\n\n如果无法解决,请前往 https://gf.qytechs.cn/zh-CN/scripts/465777/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  5117. }
  5118. else if (!response.response.choices || response.response.choices.length < 1 || !response.response.choices[0].message) {
  5119. resolve("翻译出错,请重试\n\n如果无法解决,请前往 https://gf.qytechs.cn/zh-CN/scripts/465777/feedback 反馈 \n\n报错信息:" + JSON.stringify(response.response, null, '\n'));
  5120. } else {
  5121. openai_retext = response.response.choices[0].message.content;
  5122. resolve(openai_retext);
  5123. }
  5124. },
  5125. onerror: function (response) {
  5126. reject("发生了未知的错误,请确认你是否能正常访问OpenAi的接口,如果使用代理API,请检查是否正常工作\n\n如果无法解决,请前往 https://gf.qytechs.cn/zh-CN/scripts/465777/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  5127. },
  5128. });
  5129. });
  5130. }
  5131.  
  5132. //--谷歌翻译--start
  5133. async function translate_gg(raw) {
  5134. return new Promise((resolve, reject) => {
  5135. const url = 'https://translate.google.com/m';
  5136. const params = `tl=zh-CN&q=${encodeURIComponent(raw)}`;
  5137.  
  5138. GM_xmlhttpRequest({
  5139. method: 'GET',
  5140. url: `${url}?${params}`,
  5141. onload: function (response) {
  5142. const html = response.responseText;
  5143. const translatedText = $(html).find('.result-container').text();
  5144. resolve(translatedText);
  5145. },
  5146. onerror: function (response) {
  5147. reject("发生了未知的错误,请确认你是否能正常访问Google翻译,\n\n如果无法解决,请前往 https://gf.qytechs.cn/zh-CN/scripts/465777/feedback 反馈 请注意打码报错信息的敏感部分\n\n响应报文:" + JSON.stringify(response))
  5148. }
  5149. });
  5150. });
  5151. }
  5152. //--谷歌翻译--end
  5153.  
  5154. //--有道翻译m--start
  5155. async function translate_youdao_mobile(raw) {
  5156. const options = {
  5157. method: "POST",
  5158. url: 'http://m.youdao.com/translate',
  5159. data: "inputtext=" + encodeURIComponent(raw) + "&type=AUTO",
  5160. anonymous: true,
  5161. headers: {
  5162. "Content-Type": "application/x-www-form-urlencoded",
  5163. 'Host': 'm.youdao.com',
  5164. 'Origin': 'http://m.youdao.com',
  5165. 'Referer': 'http://m.youdao.com/translate',
  5166. }
  5167. }
  5168. return await BaseTranslate('有道翻译mobile', raw, options, res => /id="translateResult">\s*?<li>([\s\S]*?)<\/li>\s*?<\/ul/.exec(res)[1])
  5169. }
  5170. //--有道翻译m--end
  5171.  
  5172. //--彩云翻译--start
  5173. async function translate_caiyun_startup() {
  5174. const browser_id = CryptoJS.MD5(Math.random().toString()).toString();
  5175. sessionStorage.setItem('caiyun_id', browser_id);
  5176. const options = {
  5177. method: "POST",
  5178. url: 'https://api.interpreter.caiyunai.com/v1/user/jwt/generate',
  5179. headers: {
  5180. "Content-Type": "application/json",
  5181. "X-Authorization": "token:qgemv4jr1y38jyq6vhvi",
  5182. "Origin": "https://fanyi.caiyunapp.com",
  5183. },
  5184. data: JSON.stringify({ browser_id }),
  5185. }
  5186. const res = await Request(options);
  5187. sessionStorage.setItem('caiyun_jwt', JSON.parse(res.responseText).jwt);
  5188. }
  5189.  
  5190. async function translate_caiyun(raw) {
  5191. const source = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
  5192. const dic = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"].reduce((dic, current, index) => { dic[current] = source[index]; return dic }, {});
  5193. // 解码
  5194. const decodeUnicode = str => {
  5195. const decoder = new TextDecoder();
  5196. const data = Uint8Array.from(atob(str), c => c.charCodeAt(0));
  5197. return decoder.decode(data);
  5198. };
  5199. const decoder = line => decodeUnicode([...line].map(i => dic[i] || i).join(""));
  5200. const options = {
  5201. method: "POST",
  5202. url: 'https://api.interpreter.caiyunai.com/v1/translator',
  5203. data: JSON.stringify({
  5204. "source": raw.split('\n'),
  5205. "trans_type": "auto2zh",
  5206. "detect": true,
  5207. "browser_id": sessionStorage.getItem('caiyun_id')
  5208. }),
  5209. headers: {
  5210. "X-Authorization": "token:qgemv4jr1y38jyq6vhvi",
  5211. "T-Authorization": sessionStorage.getItem('caiyun_jwt')
  5212. }
  5213. }
  5214. return await BaseTranslate('彩云小译', raw, options, res => JSON.parse(res).target.map(decoder).join('\n'))
  5215. }
  5216. //--彩云翻译--end
  5217.  
  5218. //--Deepl翻译--start
  5219. function getTimeStamp(iCount) {
  5220. const ts = Date.now();
  5221. if (iCount !== 0) {
  5222. iCount = iCount + 1;
  5223. return ts - (ts % iCount) + iCount;
  5224. } else {
  5225. return ts;
  5226. }
  5227. }
  5228.  
  5229. async function translate_deepl(raw) {
  5230. const id = (Math.floor(Math.random() * 99999) + 100000) * 1000;
  5231. const data = {
  5232. jsonrpc: '2.0',
  5233. method: 'LMT_handle_texts',
  5234. id,
  5235. params: {
  5236. splitting: 'newlines',
  5237. lang: {
  5238. source_lang_user_selected: 'auto',
  5239. target_lang: 'ZH',
  5240. },
  5241. texts: [{
  5242. text: raw,
  5243. requestAlternatives: 3
  5244. }],
  5245. timestamp: getTimeStamp(raw.split('i').length - 1)
  5246. }
  5247. }
  5248. let postData = JSON.stringify(data);
  5249. if ((id + 5) % 29 === 0 || (id + 3) % 13 === 0) {
  5250. postData = postData.replace('"method":"', '"method" : "');
  5251. } else {
  5252. postData = postData.replace('"method":"', '"method": "');
  5253. }
  5254. const options = {
  5255. method: 'POST',
  5256. url: 'https://www2.deepl.com/jsonrpc',
  5257. data: postData,
  5258. headers: {
  5259. 'Content-Type': 'application/json',
  5260. 'Host': 'www2.deepl.com',
  5261. 'Origin': 'https://www.deepl.com',
  5262. 'Referer': 'https://www.deepl.com/',
  5263. },
  5264. anonymous: true,
  5265. nocache: true,
  5266. }
  5267. return await BaseTranslate('Deepl翻译', raw, options, res => JSON.parse(res).result.texts[0].text)
  5268. }
  5269.  
  5270. //--Deepl翻译--end
  5271.  
  5272. //--讯飞听见翻译--end
  5273. async function translate_iflyrec(text) {
  5274. const options = {
  5275. method: "POST",
  5276. url: 'https://www.iflyrec.com/TranslationService/v1/textTranslation',
  5277. data: JSON.stringify({
  5278. "from": "2",
  5279. "to": "1",
  5280. "contents": [{
  5281. "text": text,
  5282. "frontBlankLine": 0
  5283. }]
  5284. }),
  5285. anonymous: true,
  5286. headers: {
  5287. 'Content-Type': 'application/json',
  5288. 'Origin': 'https://www.iflyrec.com',
  5289. },
  5290. responseType: "json",
  5291. };
  5292. return await BaseTranslate('讯飞翻译', text, options, res => JSON.parse(res).biz[0].translateResult.replace(/\\n/g, "\n\n"));
  5293. }
  5294. //--讯飞听见翻译--end
  5295.  
  5296. //--异步请求包装工具--start
  5297. async function PromiseRetryWrap(task, options, ...values) {
  5298. const { RetryTimes, ErrProcesser } = options || {};
  5299. let retryTimes = RetryTimes || 5;
  5300. const usedErrProcesser = ErrProcesser || (err => { throw err });
  5301. if (!task) return;
  5302. while (true) {
  5303. try {
  5304. return await task(...values);
  5305. } catch (err) {
  5306. if (!--retryTimes) {
  5307. console.warn(err);
  5308. return usedErrProcesser(err);
  5309. }
  5310. }
  5311. }
  5312. }
  5313.  
  5314. async function BaseTranslate(name, raw, options, processer) {
  5315. let errtext;
  5316. const toDo = async () => {
  5317. var tmp;
  5318. try {
  5319. const data = await Request(options);
  5320. tmp = data.responseText;
  5321. let result = await processer(tmp);
  5322. return result;
  5323. } catch (err) {
  5324. errtext = tmp;
  5325. throw {
  5326. responseText: tmp,
  5327. err: err
  5328. }
  5329. }
  5330. }
  5331. return await PromiseRetryWrap(toDo, { RetryTimes: 3, ErrProcesser: () => "翻译出错,请查看报错信息,并重试或更换翻译接口\n\n如果无法解决,请前往 https://gf.qytechs.cn/zh-CN/scripts/465777/feedback 反馈 请注意打码报错信息的敏感部分\n\n报错信息:" + errtext })
  5332. }
  5333.  
  5334. function Request(options) {
  5335. return new Promise((reslove, reject) => GM_xmlhttpRequest({ ...options, onload: reslove, onerror: reject }))
  5336. }
  5337.  
  5338. //--异步请求包装工具--end
  5339.  
  5340. // 开始
  5341. document.addEventListener("DOMContentLoaded", function () {
  5342. function checkJQuery(retryDelay) {
  5343. if (typeof jQuery === 'undefined') {
  5344. console.warn("JQuery未加载," + retryDelay + "毫秒后重试");
  5345. setTimeout(function () {
  5346. var newRetryDelay = Math.min(retryDelay * 2, 2000);
  5347. checkJQuery(newRetryDelay);
  5348. }, retryDelay);
  5349. } else {
  5350. init();
  5351. ShowAlertMessage();
  5352. settingPanel();
  5353. checkScriptVersion();
  5354. toZH_CN();
  5355. var newElement = $("<div></div>").addClass("alert alert-info CFBetter_alert")
  5356. .html(`Codeforces Better! —— 正在等待页面资源加载……`)
  5357. .css({
  5358. "margin": "1em",
  5359. "text-align": "center",
  5360. "font-weight": "600",
  5361. "position": "relative"
  5362. });
  5363.  
  5364. async function processPage() {
  5365. if (showLoading) newElement.html('Codeforces Better! —— 正在等待LaTeX渲染队列全部完成……');
  5366. await waitUntilIdleThenDo(async function () {
  5367. if (showJumpToLuogu && is_problem) CF2luogu();
  5368.  
  5369. Promise.resolve()
  5370. .then(() => {
  5371. if (showLoading && expandFoldingblocks) newElement.html('Codeforces Better! —— 正在展开折叠块……');
  5372. return delay(100).then(() => { if (expandFoldingblocks) ExpandFoldingblocks() });
  5373. })
  5374. .then(() => {
  5375. if (showLoading && commentPaging) newElement.html('Codeforces Better! —— 正在对评论区分页……');
  5376. return delay(100).then(() => { if (commentPaging) CommentPagination() });
  5377. })
  5378. .then(() => {
  5379. if (showLoading && is_acmsguru) newElement.html('Codeforces Better! —— 正在为acmsguru题面重新划分div……');
  5380. return delay(100).then(() => { if (is_acmsguru) acmsguruReblock() });
  5381. })
  5382. .then(() => {
  5383. if (showLoading) newElement.html('Codeforces Better! —— 正在加载按钮……');
  5384. return delay(100).then(() => addConversionButton());
  5385. })
  5386. .then(() => {
  5387. if (showLoading && commentTranslationMode == "2") newElement.html('Codeforces Better! —— 正在加载选段翻译……');
  5388. return delay(100).then(() => { if (commentTranslationMode == "2") multiChoiceTranslation() });
  5389. })
  5390. .then(async () => {
  5391. if (showLoading && renderPerfOpt) newElement.html('Codeforces Better! —— 正在优化折叠块渲染……');
  5392. await delay(100);
  5393. if (renderPerfOpt) await RenderPerfOpt();
  5394. })
  5395. .then(async () => {
  5396. if (showLoading && standingsRecolor && is_cfStandings) newElement.html('Codeforces Better! —— 正在为榜单重新着色……');
  5397. await delay(100);
  5398. if (standingsRecolor && is_cfStandings) await recolorStandings();
  5399. })
  5400. .then(async () => {
  5401. await delay(100);
  5402. if (showLoading && showClistRating_contest && is_contest) {
  5403. newElement.html('Codeforces Better! —— 正在加载Clist数据……');
  5404. await showRatingByClist_contest();
  5405. }
  5406. if (showLoading && showClistRating_problemset && is_problemset) {
  5407. newElement.html('Codeforces Better! —— 正在加载Clist数据……');
  5408. await showRatingByClist_problemset();
  5409. }
  5410. if (showLoading && showClistRating_problem && is_problem) {
  5411. newElement.html('Codeforces Better! —— 正在加载Clist数据……');
  5412. await showRatingByClist_problem();
  5413. }
  5414. })
  5415. .then(() => {
  5416. alertZh();
  5417. if (showLoading) {
  5418. newElement.html('Codeforces Better! —— 加载已完成');
  5419. newElement.removeClass('alert-info').addClass('alert-success');
  5420. setTimeout(function () {
  5421. newElement.remove();
  5422. }, 3000);
  5423. }
  5424. })
  5425. .catch((error) => {
  5426. console.warn(error);
  5427. });
  5428. });
  5429. }
  5430.  
  5431. function delay(ms) {
  5432. return new Promise((resolve) => setTimeout(resolve, ms));
  5433. }
  5434.  
  5435. if (showLoading) {
  5436. if (is_mSite) $("header").after(newElement);
  5437. else $(".menu-box:first").next().after(newElement);
  5438. }
  5439.  
  5440. if (loaded) {
  5441. processPage();
  5442. } else {
  5443. // 页面完全加载完成后执行
  5444. window.onload = function () {
  5445. processPage();
  5446. };
  5447. }
  5448. }
  5449. }
  5450. checkJQuery(50);
  5451. });
  5452.  
  5453. // 配置自动迁移代码(将在10个小版本后移除-1.66)
  5454. if (GM_getValue("openai_key") || GM_getValue("api2d_key")) {
  5455. const newConfig = { "choice": -1, "configurations": [] };
  5456. if (GM_getValue("openai_key")) {
  5457. let config1 = {
  5458. "note": "我的配置1",
  5459. "model": GM_getValue("openai_model") || "",
  5460. "key": GM_getValue("openai_key"),
  5461. "proxy": GM_getValue("openai_proxy") || "",
  5462. "_header": "",
  5463. "_data": ""
  5464. }
  5465. if (GM_getValue("translation") === "openai") newConfig.choice = 0;
  5466. newConfig.configurations.push(config1);
  5467. }
  5468. if (GM_getValue("api2d_key")) {
  5469. let config2 = {
  5470. "note": "api2d",
  5471. "model": GM_getValue("api2d_model"),
  5472. "key": GM_getValue("api2d_key"),
  5473. "proxy": GM_getValue("api2d_request_entry") + '/v1/chat/completions',
  5474. "_header": GM_getValue("x_api2d_no_cache") ? "" : " x-api2d-no-cache : 1",
  5475. "_data": ""
  5476. }
  5477. if (GM_getValue("translation") === "api2d") {
  5478. if (GM_getValue("openai_key")) newConfig.choice = 1;
  5479. else newConfig.choice = 0;
  5480. }
  5481. newConfig.configurations.push(config2);
  5482. }
  5483. GM_setValue("chatgpt-config", newConfig);
  5484. const keysToDelete = ["openai_key", "openai_model", "openai_proxy", "api2d_key", "api2d_model", "api2d_request_entry", "x_api2d_no_cache", "showOpneAiAdvanced"];
  5485. keysToDelete.forEach(key => {
  5486. if (GM_getValue(key) != undefined) GM_deleteValue(key);
  5487. });
  5488. if (GM_getValue("translation") === "api2d") GM_setValue("translation", "openai");
  5489. location.reload();
  5490. }
  5491. // 配置自动迁移代码(将在10个小版本后移除-1.71)
  5492. if (GM_getValue("darkMode") === true || GM_getValue("darkMode") === false) {
  5493. GM_setValue("darkMode", "follow");
  5494. location.reload();
  5495. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址