Codeforces Better!

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

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

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

QingJ © 2025

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