Codeforces Better!

Codeforces界面汉化、黑暗模式支持、题目翻译,markdown视图,一键复制题目,跳转到洛谷、评论区分页

当前为 2023-09-24 提交的版本,查看 最新版本

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