Codeforces Better!

Codeforces界面汉化、题目翻译,markdown视图,一键复制题目,跳转到洛谷

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

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