Atcoder Better!

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

As of 2023-08-13. See the latest version.

  1. // ==UserScript==
  2. // @name Atcoder Better!
  3. // @namespace https://greatest.deepsurf.us/users/747162
  4. // @version 1.08
  5. // @description Atcoder界面汉化、题目翻译,markdown视图,一键复制题目,跳转到洛谷
  6. // @author 北极小狐
  7. // @match https://atcoder.jp/*
  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 greatest.deepsurf.us
  15. // @connect *
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_info
  18. // @grant GM_setValue
  19. // @grant GM_getValue
  20. // @grant GM_addStyle
  21. // @grant GM_setClipboard
  22. // @icon https://aowuucdn.oss-cn-beijing.aliyuncs.com/atcoder.png
  23. // @require https://cdn.staticfile.org/turndown/7.1.2/turndown.min.js
  24. // @require https://cdn.staticfile.org/markdown-it/13.0.1/markdown-it.min.js
  25. // @license MIT
  26. // @compatible Chrome
  27. // @compatible Firefox
  28. // @compatible Edge
  29. // ==/UserScript==
  30.  
  31. // 状态与初始化
  32. const getGMValue = (key, defaultValue) => {
  33. const value = GM_getValue(key);
  34. if (value === undefined || value === "") {
  35. GM_setValue(key, defaultValue);
  36. return defaultValue;
  37. }
  38. return value;
  39. };
  40.  
  41. const bottomZh_CN = getGMValue("bottomZh_CN", true);
  42. const translation = getGMValue("translation", "deepl");
  43. const enableSegmentedTranslation = getGMValue("enableSegmentedTranslation", false);
  44. const showJumpToLuogu = getGMValue("showJumpToLuogu", true);
  45. const showLoading = getGMValue("showLoading", true);
  46. const loaded = getGMValue("loaded", false);
  47. const hoverTargetAreaDisplay = getGMValue("hoverTargetAreaDisplay", false);
  48. //openai
  49. const openai_model = getGMValue("openai_model", "gpt-3.5-turbo");
  50. var showOpneAiAdvanced = getGMValue("showOpneAiAdvanced", false);
  51. // api2d
  52. const api2d_model = getGMValue("api2d_model", "gpt-3.5-turbo");
  53. const api2d_request_entry = getGMValue("api2d_request_entry", "https://openai.api2d.net");
  54. var x_api2d_no_cache = getGMValue("x_api2d_no_cache", true);
  55.  
  56. // 常量
  57. 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>';
  58. 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: 9999; }`;
  59.  
  60. // 样式
  61. GM_addStyle(`
  62. :root {
  63. --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";
  64. }
  65. span.mdViewContent {
  66. white-space: pre-wrap;
  67. }
  68. /*翻译区域提示*/
  69. .overlay {
  70. pointer-events: none;
  71. position: absolute;
  72. top: 0;
  73. left: 0;
  74. width: 100%;
  75. height: 100%;
  76. background: repeating-linear-gradient(135deg, #97e7cacc, #97e7cacc 30px, #e9fbf1cc 0px, #e9fbf1cc 55px);
  77. border-radius: 5px;
  78. display: flex;
  79. align-items: center;
  80. justify-content: center;
  81. color: #00695C;
  82. font-size: 16px;
  83. font-weight: bold;
  84. text-shadow: 0px 0px 2px #edfcf4;
  85. }
  86. /*翻译div*/
  87. .translate-problem-statement {
  88. justify-items: start;
  89. letter-spacing: 1.8px;
  90. color: #059669;
  91. background-color: #f9f9fa;
  92. border: 1px solid #10b981;
  93. border-radius: 0.3rem;
  94. padding: 5px;
  95. margin: 10px 0px;
  96. width: 100%;
  97. box-sizing: border-box;
  98. font-size: 13px;
  99. }
  100. .translate-problem-statement.error_translate {
  101. color: red;
  102. border-color: red;
  103. }
  104.  
  105. .translate-problem-statement h2, .translate-problem-statement h3 {
  106. font-size: 16px;
  107. }
  108.  
  109. .translate-problem-statement ul {
  110. line-height: 100%;
  111. }
  112.  
  113. .translate-problem-statement a {
  114. color: #10b981;
  115. font-weight: 600;
  116. background: 0 0;
  117. text-decoration: none;
  118. }
  119. .translate-problem-statement p {
  120. font-size: 14px !important;
  121. }
  122. .translate-problem-statement img {
  123. max-width: 100.0%;
  124. max-height: 100.0%;
  125. }
  126.  
  127. .translate-problem-statement .katex {
  128. font-size: 14px;
  129. }
  130. .translate-problem-statement a:hover {
  131. text-decoration: revert;
  132. }
  133. .html2md-panel {
  134. display: flex;
  135. justify-content: flex-end;
  136. }
  137. .html2md-panel a {
  138. text-decoration: none;
  139. }
  140. button.html2mdButton {
  141. display: flex;
  142. align-items: center;
  143. cursor: pointer;
  144. background-color: #ffffff;
  145. color: #606266;
  146. height: 22px;
  147. width: auto;
  148. font-size: 13px;
  149. border-radius: 0.3rem;
  150. padding: 1px 5px;
  151. margin: 5px;
  152. border: 1px solid #dcdfe6;
  153. }
  154. button.html2mdButton:hover {
  155. color: #409eff;
  156. border-color: #409eff;
  157. }
  158. button.html2mdButton.copied {
  159. background-color: #f0f9eb;
  160. color: #67c23e;
  161. border: 1px solid #b3e19d;
  162. }
  163. button.html2mdButton.mdViewed {
  164. background-color: #fdf6ec;
  165. color: #e6a23c;
  166. border: 1px solid #f3d19e;
  167. }
  168. button.html2mdButton.error {
  169. background-color: #fef0f0;
  170. color: #f56c6c;
  171. border: 1px solid #fab6b6;
  172. }
  173. button.translated {
  174. cursor: not-allowed;
  175. background-color: #f0f9eb;
  176. color: #67c23e;
  177. border: 1px solid #b3e19d;
  178. }
  179. button.html2mdButton.reTranslation {
  180. background-color: #f4f4f5;
  181. color: #909399;
  182. border: 1px solid #c8c9cc;
  183. }
  184. .translate-problem-statement table {
  185. border: 1px #ccc solid !important;
  186. margin: 1.5em 0 !important;
  187. color: #059669 !important;
  188. }
  189. .translate-problem-statement table thead th {
  190. border: 1px #ccc solid !important;
  191. color: #059669 !important;
  192. }
  193. .translate-problem-statement table td {
  194. border-right: 1px solid #ccc;
  195. border-top: 1px solid #ccc;
  196. padding: 0.7143em 0.5em;
  197. }
  198. .translate-problem-statement table th {
  199. padding: 0.7143em 0.5em;
  200. }
  201. .translate-problem-statement p:not(:first-child) {
  202. margin: 1.5em 0 0;
  203. }
  204. /*设置面板*/
  205. header .enter-or-register-box, header .languages {
  206. position: absolute;
  207. right: 170px;
  208. }
  209. button.html2mdButton.AtBetter_setting {
  210. float: right;
  211. height: 30px;
  212. background: #3c5a7f;
  213. color: white;
  214. margin: 10px;
  215. border: 0px;
  216. }
  217.  
  218. button.html2mdButton.AtBetter_setting.open {
  219. background-color: #e6e6e61f;
  220. color: #727378;
  221. cursor: not-allowed;
  222. }
  223. #AtBetter_setting_menu {
  224. z-index: 9999;
  225. box-shadow: 0px 0px 0px 4px #ffffff;
  226. display: grid;
  227. position: fixed;
  228. top: 50%;
  229. left: 50%;
  230. width: 500px;
  231. max-height: 90vh;
  232. overflow-y: auto;
  233. transform: translate(-50%, -50%);
  234. border-radius: 6px;
  235. background-color: #edf1ff;
  236. border-collapse: collapse;
  237. border: 1px solid #ffffff;
  238. color: #697e91;
  239. font-family: var(--vp-font-family-base);
  240. padding: 10px 20px 20px 20px;
  241. }
  242. #AtBetter_setting_menu h3 {
  243. margin-top: 10px;
  244. }
  245. #AtBetter_setting_menu hr {
  246. border: none;
  247. height: 1px;
  248. background-color: #ccc;
  249. margin: 10px 0;
  250. }
  251. /*设置面板-关闭按钮*/
  252. #AtBetter_setting_menu .tool-box {
  253. position: absolute;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. width: 2.5rem;
  258. height: 2.5rem;
  259. top: 3px;
  260. right: 3px;
  261. }
  262.  
  263. #AtBetter_setting_menu .btn-close {
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. text-align: center;
  268. padding: 10px !important;
  269. width: 1px;
  270. height: 1px !important;
  271. color: transparent;
  272. font-size: 0;
  273. cursor: pointer;
  274. background-color: #ff000080;
  275. border: none;
  276. border-radius: 10px;
  277. transition: .15s ease all;
  278. }
  279.  
  280. #AtBetter_setting_menu .btn-close:hover {
  281. width: 20px;
  282. height: 20px !important;
  283. font-size: 17px;
  284. color: #ffffff;
  285. background-color: #ff0000cc;
  286. box-shadow: 0 5px 5px 0 #00000026;
  287. }
  288.  
  289. #AtBetter_setting_menu .btn-close:active {
  290. width: .9rem;
  291. height: .9rem;
  292. font-size: 1px;
  293. color: #ffffffde;
  294. --shadow-btn-close: 0 3px 3px 0 #00000026;
  295. box-shadow: var(--shadow-btn-close);
  296. }
  297.  
  298. /*设置面板-checkbox*/
  299. #AtBetter_setting_menu input[type=checkbox]:focus {
  300. outline: 0px;
  301. }
  302.  
  303. #AtBetter_setting_menu input[type="checkbox"] {
  304. margin: 0px;
  305. appearance: none;
  306. -webkit-appearance: none;
  307. width: 40px;
  308. height: 20px !important;
  309. border: 1.5px solid #D7CCC8;
  310. padding: 0px !important;
  311. border-radius: 20px;
  312. background: #efebe978;
  313. position: relative;
  314. box-sizing: border-box;
  315. }
  316.  
  317. #AtBetter_setting_menu input[type="checkbox"]::before {
  318. content: "";
  319. width: 14px;
  320. height: 14px;
  321. background: #D7CCC8;
  322. border: 1.5px solid #BCAAA4;
  323. border-radius: 50%;
  324. position: absolute;
  325. top: 0;
  326. left: 0;
  327. transform: translate(2%, 2%);
  328. transition: all 0.3s ease-in-out;
  329. -webkit-box-sizing: content-box;
  330. -moz-box-sizing: content-box;
  331. box-sizing: content-box;
  332. }
  333.  
  334. #AtBetter_setting_menu input[type="checkbox"]::after {
  335. 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");
  336. position: absolute;
  337. top: 0;
  338. left: 24px;
  339. }
  340.  
  341. #AtBetter_setting_menu input[type="checkbox"]:checked {
  342. border: 1.5px solid #C5CAE9;
  343. background: #E8EAF6;
  344. }
  345.  
  346. #AtBetter_setting_menu input[type="checkbox"]:checked::before {
  347. background: #C5CAE9;
  348. border: 1.5px solid #7986CB;
  349. transform: translate(122%, 2%);
  350. transition: all 0.3s ease-in-out;
  351. }
  352.  
  353. #AtBetter_setting_menu input[type="text"]:focus-visible{
  354. border-width: 0.2vh;
  355. border-style: solid;
  356. border-color: #8bb2d9;
  357. outline: -webkit-focus-ring-color auto 0px;
  358. }
  359.  
  360. #AtBetter_setting_menu input[type="checkbox"]:checked::after {
  361. 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");
  362. position: absolute;
  363. top: 1.5px;
  364. left: 4.5px;
  365. }
  366.  
  367. #AtBetter_setting_menu label {
  368. font-size: 16px;
  369. font-weight: initial;
  370. margin-bottom: 0px;
  371. }
  372.  
  373. .AtBetter_setting_list {
  374. display: flex;
  375. align-items: center;
  376. padding: 10px;
  377. margin: 5px 0px;
  378. background-color: #ffffff;
  379. border-bottom: 1px solid #c9c6c696;
  380. border-radius: 8px;
  381. justify-content: space-between;
  382. }
  383.  
  384. /*设置面板-radio*/
  385. #AtBetter_setting_menu>label {
  386. display: flex;
  387. list-style-type: none;
  388. padding-inline-start: 0px;
  389. overflow-x: auto;
  390. max-width: 100%;
  391. margin: 0px;
  392. align-items: center;
  393. margin: 3px 0px;
  394. }
  395.  
  396. .AtBetter_setting_menu_label_text {
  397. display: flex;
  398. border: 1px dashed #00aeeccc;
  399. height: 20px;
  400. width: 100%;
  401. color: gray;
  402. font-weight: 300;
  403. font-size: 14px;
  404. letter-spacing: 2px;
  405. padding: 7px;
  406. align-items: center;
  407. -webkit-box-sizing: content-box;
  408. -moz-box-sizing: content-box;
  409. box-sizing: content-box;
  410. }
  411.  
  412. input[type="radio"]:checked+.AtBetter_setting_menu_label_text {
  413. background: #41e49930;
  414. border: 1px solid green;
  415. color: green;
  416. font-weight: 500;
  417. }
  418.  
  419. #AtBetter_setting_menu>label input[type="radio"] {
  420. -webkit-appearance: none;
  421. appearance: none;
  422. list-style: none;
  423. padding: 0px !important;
  424. margin: 0px;
  425. }
  426.  
  427. #AtBetter_setting_menu input[type="text"] {
  428. display: block;
  429. height: 25px !important;
  430. width: 100%;
  431. background-color: #ffffff;
  432. color: #727378;
  433. font-size: 12px;
  434. border-radius: 0.3rem;
  435. padding: 1px 5px !important;
  436. box-sizing: border-box;
  437. margin: 5px 0px 5px 0px;
  438. border: 1px solid #00aeeccc;
  439. box-shadow: 0 0 1px #0000004d;
  440. }
  441.  
  442. .AtBetter_setting_menu_input {
  443. width: 100%;
  444. display: grid;
  445. margin-top: 5px;
  446. }
  447.  
  448. #AtBetter_setting_menu #save {
  449. cursor: pointer;
  450. display: inline-flex;
  451. padding: 0.5rem 1rem;
  452. background-color: #1aa06d;
  453. color: #ffffff;
  454. font-size: 1rem;
  455. line-height: 1.5rem;
  456. font-weight: 500;
  457. justify-content: center;
  458. width: 100%;
  459. border-radius: 0.375rem;
  460. border: none;
  461. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  462. }
  463. #AtBetter_setting_menu button#debug_button.debug_button {
  464. width: 18%;
  465. }
  466.  
  467. #AtBetter_setting_menu span.tip {
  468. color: #999;
  469. font-size: 12px;
  470. font-weight: 500;
  471. padding: 5px 0px;
  472. }
  473. /*设置面板-tip*/
  474. .help_tip {
  475. margin-right: auto;
  476. }
  477. span.input_label {
  478. font-size: 14px;
  479. }
  480. .help_tip .tip_text {
  481. display: none;
  482. position: absolute;
  483. color: #697e91;
  484. font-weight: 400;
  485. font-size: 14px;
  486. letter-spacing: 0px;
  487. background-color: #ffffff;
  488. padding: 10px;
  489. margin: 5px 0px;
  490. border-radius: 4px;
  491. border: 1px solid #e4e7ed;
  492. box-shadow: 0px 0px 12px rgba(0, 0, 0, .12);
  493. z-index: 999;
  494. }
  495. .help_tip .tip_text p {
  496. margin-bottom: 5px;
  497. }
  498. .help_tip .tip_text:before {
  499. content: "";
  500. position: absolute;
  501. top: -20px;
  502. right: -10px;
  503. bottom: -10px;
  504. left: -10px;
  505. z-index: -1;
  506. }
  507. .help-icon {
  508. display: flex;
  509. cursor: help;
  510. width: 15px;
  511. color: #b4b9d4;
  512. margin-left: 5px;
  513. }
  514. #AtBetter_setting_menu .AtBetter_setting_menu_label_text .help_tip .help-icon {
  515. color: #7fbeb2;
  516. }
  517. .help_tip .help-icon:hover + .tip_text, .help_tip .tip_text:hover {
  518. display: block;
  519. cursor: help;
  520. width: 250px;
  521. }
  522.  
  523. /*设置面板-展开*/
  524. #is_showOpneAiAdvanced{
  525. width: 100%;
  526. background-color: aliceblue;
  527. padding: 8px;
  528. box-sizing: border-box;
  529. border-radius: 10px;
  530. }
  531. /*确认弹窗*/
  532. .wordsExceeded {
  533. z-index: 99999;
  534. box-shadow: 0px 0px 5px 1px rgb(0 0 0 / 10%), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  535. display: grid;
  536. position: fixed;
  537. top: 50%;
  538. left: 50%;
  539. transform: translate(-50%, -50%);
  540. border-radius: 4px;
  541. background-color: #ffffff;
  542. border: 1px solid #e4e7ed;
  543. color: #697e91;
  544. font-family: var(--vp-font-family-base);
  545. padding: 10px 20px 20px 20px;
  546. }
  547. .wordsExceeded button {
  548. display: inline-flex;
  549. justify-content: center;
  550. align-items: center;
  551. line-height: 1;
  552. white-space: nowrap;
  553. cursor: pointer;
  554. text-align: center;
  555. box-sizing: border-box;
  556. outline: none;
  557. transition: .1s;
  558. user-select: none;
  559. vertical-align: middle;
  560. -webkit-appearance: none;
  561. height: 24px;
  562. padding: 5px 11px;
  563. font-size: 12px;
  564. border-radius: 4px;
  565. color: #ffffff;
  566. background: #409eff;
  567. border-color: #409eff;
  568. border: none;
  569. margin-right: 12px;
  570. }
  571. .wordsExceeded button:hover{
  572. background-color:#79bbff;
  573. }
  574. .wordsExceeded .help-icon {
  575. margin: 0px 8px 0px 0px;
  576. height: 1em;
  577. width: 1em;
  578. line-height: 1em;
  579. display: inline-flex;
  580. justify-content: center;
  581. align-items: center;
  582. position: relative;
  583. fill: currentColor;
  584. font-size: inherit;
  585. }
  586. .wordsExceeded p {
  587. margin: 5px 0px;
  588. }
  589. /*更新检查*/
  590. div#update_panel {
  591. z-index: 9999;
  592. position: fixed;
  593. top: 50%;
  594. left: 50%;
  595. width: 240px;
  596. transform: translate(-50%, -50%);
  597. box-shadow: 0px 0px 4px 0px #0000004d;
  598. padding: 10px 20px 20px 20px;
  599. color: #444242;
  600. background-color: #f5f5f5;
  601. border: 1px solid #848484;
  602. border-radius: 8px;
  603. }
  604. div#update_panel #updating {
  605. cursor: pointer;
  606. display: inline-flex;
  607. padding: 0px;
  608. background-color: #1aa06d;
  609. color: #ffffff;
  610. font-size: 1rem;
  611. line-height: 1.5rem;
  612. font-weight: 500;
  613. justify-content: center;
  614. width: 100%;
  615. border-radius: 0.375rem;
  616. border: none;
  617. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  618. }
  619. div#update_panel #updating a {
  620. text-decoration: none;
  621. color: white;
  622. display: flex;
  623. position: inherit;
  624. top: 0;
  625. left: 0;
  626. width: 100%;
  627. height: 22px;
  628. font-size: 14px;
  629. justify-content: center;
  630. align-items: center;
  631. }
  632. #skip_menu {
  633. display: flex;
  634. margin-top: 10px;
  635. justify-content: flex-end;
  636. align-items: center;
  637. }
  638. #skip_menu .help_tip {
  639. margin-right: 5px;
  640. margin-left: -5px;
  641. }
  642. #skip_menu .help-icon {
  643. color: #f44336;
  644. }
  645. `);
  646.  
  647. // 获取cookie
  648. function getCookie(name) {
  649. const cookies = document.cookie.split(";");
  650. for (let i = 0; i < cookies.length; i++) {
  651. const cookie = cookies[i].trim();
  652. const [cookieName, cookieValue] = cookie.split("=");
  653.  
  654. if (cookieName === name) {
  655. return decodeURIComponent(cookieValue);
  656. }
  657. }
  658. return "";
  659. }
  660.  
  661. // 防抖函数
  662. function debounce(callback) {
  663. let timer;
  664. let immediateExecuted = false;
  665. const delay = 500;
  666. return function () {
  667. clearTimeout(timer);
  668. if (!immediateExecuted) { callback.call(this); immediateExecuted = true; }
  669. timer = setTimeout(() => { immediateExecuted = false; }, delay);
  670. };
  671. }
  672.  
  673. // 更新检查
  674. (function checkScriptVersion() {
  675. function compareVersions(version1 = "0", version2 = "0") {
  676. const v1Array = String(version1).split(".");
  677. const v2Array = String(version2).split(".");
  678. const minLength = Math.min(v1Array.length, v2Array.length);
  679. let result = 0;
  680. for (let i = 0; i < minLength; i++) {
  681. const curV1 = Number(v1Array[i]);
  682. const curV2 = Number(v2Array[i]);
  683. if (curV1 > curV2) {
  684. result = 1;
  685. break;
  686. } else if (curV1 < curV2) {
  687. result = -1;
  688. break;
  689. }
  690. }
  691. if (result === 0 && v1Array.length !== v2Array.length) {
  692. const v1IsBigger = v1Array.length > v2Array.length;
  693. const maxLenArray = v1IsBigger ? v1Array : v2Array;
  694. for (let i = minLength; i < maxLenArray.length; i++) {
  695. const curVersion = Number(maxLenArray[i]);
  696. if (curVersion > 0) {
  697. v1IsBigger ? result = 1 : result = -1;
  698. break;
  699. }
  700. }
  701. }
  702. return result;
  703. }
  704.  
  705. GM_xmlhttpRequest({
  706. method: "GET",
  707. url: "https://greatest.deepsurf.us/zh-CN/scripts/471106.json",
  708. timeout: 10 * 1e3,
  709. onload: function (response) {
  710. const scriptData = JSON.parse(response.responseText);
  711. const skipUpdate = getCookie("skipUpdate");
  712.  
  713. if (
  714. scriptData.name === GM_info.script.name &&
  715. compareVersions(scriptData.version, GM_info.script.version) === 1 &&
  716. skipUpdate !== "true"
  717. ) {
  718. const styleElement = GM_addStyle(darkenPageStyle);
  719. $("body").append(`
  720. <div id='update_panel'>
  721. <h3>${GM_info.script.name}有新版本!</h3>
  722. <hr>
  723. <div class='update_panel_menu'>
  724. <span class ='tip'>版本信息:${GM_info.script.version} ${scriptData.version}</span>
  725. </div>
  726. <br>
  727. <div id="skip_menu">
  728. <div class="help_tip">
  729. `+ helpCircleHTML + `
  730. <div class="tip_text">
  731. <p><b>更新遇到了问题?</b></p>
  732. <p>由于 Greasyfork 平台的原因,当新版本刚发布时,点击 Greasyfork 上的更新按钮<u>可能</u>会出现<u>实际更新/安装的却是上一个版本</u>的情况</p>
  733. <p>通常你只需要稍等几分钟,然后再次前往更新/安装即可</p>
  734. <p>你也可以<u>点击下方按钮,在本次浏览器会话期间将不再提示更新</u></p>
  735. <button id='skip_update' class='html2mdButton'>暂不更新</button>
  736. </div>
  737. </div>
  738. <button id='updating'><a target="_blank" href="${scriptData.url}">更新</a></button>
  739. </div>
  740. </div>
  741. `);
  742.  
  743. $("#skip_update").click(function () {
  744. document.cookie = "skipUpdate=true; expires=session; path=/";
  745. styleElement.remove();
  746. $("#update_panel").remove();
  747. });
  748. }
  749. }
  750. });
  751.  
  752. })();
  753.  
  754. // 汉化替换
  755. (function () {
  756. if (!bottomZh_CN) return;
  757.  
  758. // 文本节点遍历替换
  759. $(document).ready(function () {
  760. function traverseTextNodes(node, rules) {
  761. if (!node) return;
  762. if (node.nodeType === Node.TEXT_NODE) {
  763. rules.forEach(rule => {
  764. const regex = new RegExp(rule.match, 'g');
  765. node.textContent = node.textContent.replace(regex, rule.replace);
  766. });
  767. } else {
  768. $(node).contents().each((_, child) => traverseTextNodes(child, rules));
  769. }
  770. }
  771.  
  772. // 严格
  773. function strictTraverseTextNodes(node, rules) {
  774. if (!node) return;
  775. if (node.nodeType === Node.TEXT_NODE) {
  776. const nodeText = node.textContent.trim();
  777. rules.forEach(rule => {
  778. if (nodeText === rule.match) {
  779. node.textContent = rule.replace;
  780. }
  781. });
  782. } else {
  783. $(node).contents().each((_, child) => strictTraverseTextNodes(child, rules));
  784. }
  785. }
  786.  
  787. const rules1 = [
  788. { match: 'Present Contests', replace: '目前的比赛' },
  789. { match: 'Past Contests', replace: '过去的比赛' },
  790. { match: 'Top', replace: '首页' },
  791. { match: 'Tasks', replace: '问题集' },
  792. { match: 'Clarifications', replace: '问题答疑' },
  793. { match: 'Submit', replace: '提交' },
  794. { match: 'Results', replace: '结果' },
  795. { match: 'All Submissions', replace: '所有提交' },
  796. { match: 'My Submissions', replace: '我的提交' },
  797. { match: 'My Score', replace: '我的得分' },
  798. { match: 'Virtual Standings', replace: '虚拟排名' },
  799. { match: 'Standings', replace: '排名' },
  800. { match: 'Custom Test', replace: '自定义测试' },
  801. { match: 'Editorial', replace: '题解' },
  802. { match: 'Discuss', replace: '讨论' },
  803. { match: 'Algorithm', replace: '算法' },
  804. { match: 'Heuristic', replace: '启发式' },
  805. { match: 'Active Users', replace: '活跃用户' },
  806. { match: 'All Users', replace: '所有用户' },
  807. { match: 'Profile', replace: '个人资料' },
  808. { match: 'Competition History', replace: '比赛记录' },
  809. { match: 'General Settings', replace: '常规设置' },
  810. { match: 'Settings', replace: '设置' },
  811. { match: 'Change/Verify Email address', replace: '更改/验证电子邮件地址' },
  812. { match: 'Remind Username', replace: '提醒用户名' },
  813. { match: 'Change Username', replace: '更改用户名' },
  814. { match: 'Delete Account', replace: '删除账户' },
  815. { match: 'Change Photo', replace: '更改照片' },
  816. { match: 'Change Password', replace: '更改密码' },
  817. { match: 'Manage Fav', replace: '管理收藏' },
  818. { match: 'Other', replace: '其他' },
  819. { match: 'Remind Username', replace: '提醒用户名' },
  820. { match: 'Change Username', replace: '更改用户名' },
  821. { match: 'Delete Account', replace: '删除账户' }
  822. ];
  823. traverseTextNodes($('.nav'), rules1);
  824.  
  825. const rules2 = [
  826. { match: 'My Profile', replace: '个人资料' },
  827. { match: 'General Settings', replace: '常规设置' },
  828. { match: 'Change Photo', replace: '更改照片' },
  829. { match: 'Change Password', replace: '更改密码' },
  830. { match: 'Manage Fav', replace: '管理收藏' },
  831. { match: 'Sign Out', replace: '退出登录' }
  832. ];
  833. traverseTextNodes($('.dropdown-menu'), rules2);
  834.  
  835. const rules3 = [
  836. { match: 'Search in Archive', replace: '搜索存档' },
  837. { match: 'Permanent Contests', replace: '永久比赛' },
  838. { match: 'Upcoming Contests', replace: '即将举行的比赛' },
  839. { match: 'Recent Contests', replace: '最近的比赛' },
  840. { match: 'Ranking', replace: '排行' },
  841. { match: 'Contest Archive', replace: '比赛档案' },
  842. { match: 'Information', replace: '信息' },
  843. { match: 'About the situation where it is difficult to access the contest site', replace: '关于难以访问比赛网站的情况' },
  844. ];
  845. traverseTextNodes($('.panel-title'), rules3);
  846. traverseTextNodes($('.h3'), rules3);
  847. strictTraverseTextNodes($('h3'), rules3);
  848.  
  849. const rules4 = [
  850. { match: 'Rated Range', replace: '限定范围' },
  851. { match: 'Category', replace: '类别' },
  852. { match: 'Search', replace: '搜索' }
  853. ];
  854. traverseTextNodes($('.filter-body-heading'), rules4);
  855.  
  856. const rules5 = [
  857. { match: 'Current Password', replace: '当前密码' },
  858. { match: 'New Password', replace: '新密码' },
  859. { match: 'Confirm Password', replace: '确认密码' },
  860. { match: 'Update', replace: '更新' },
  861. { match: 'Contest Name', replace: '比赛名称' },
  862. { match: 'Username', replace: '用户名' },
  863. { match: 'Password', replace: '密码' },
  864. { match: 'Sign In', replace: '登录' },
  865. { match: 'Sign Up', replace: '注册' },
  866. { match: 'Nickname', replace: '昵称' },
  867. { match: 'Country/Region', replace: '国家/地区' },
  868. { match: 'Birth Year', replace: '出生年份' },
  869. { match: 'Affiliation', replace: '机构' },
  870. { match: 'Email Notifications', replace: '邮件通知' },
  871. { match: 'New Email address', replace: '新电子邮件地址' },
  872. { match: 'Request Email address verify', replace: '请求电子邮件地址验证' },
  873. { match: 'I agree.', replace: '我同意。' },
  874. { match: 'Do you live in Japan?', replace: '您是否居住在日本?' },
  875. { match: 'Family Name', replace: '姓氏' },
  876. { match: 'First Name', replace: '名字' },
  877. { match: 'Category', replace: '分类' },
  878. { match: 'College Students (Master or Doctor cource)', replace: '大学生(硕士或博士课程)' },
  879. { match: 'College Students', replace: '大学生' },
  880. { match: 'Technical college/Vocational school/Short-term university', replace: '技术学院/职业学校/短期大学' },
  881. { match: 'High school', replace: '高中' },
  882. { match: 'Junior high school', replace: '初中' },
  883. { match: 'Office worker', replace: '上班族' },
  884. { match: 'Other', replace: '其他' },
  885. { match: 'Organization Name \\(Company Name or School Name\\)', replace: '组织名称(公司名称或学校名称)' },
  886. { match: 'Depertment \\(For Students\\)', replace: '部门(适用于学生)' },
  887. { match: 'Do you have any intention or plan to find a job or change jobs in 2023 or 2024?', replace: '您是否有意向或计划在2023年或2024年找工作或换工作?' },
  888. { match: 'Graduation Schedule', replace: '毕业时间表' },
  889. { match: "I'm already employed.", replace: '我已经就业了。' },
  890. { match: 'Later years', replace: '以后的几年' },
  891. { match: 'I am interested in going into the digital area of Toyota Motor Corporation\'s operations.', replace: '我对加入丰田汽车公司的数字领域感兴趣。' },
  892. { match: 'Toyota is currently actively recruiting engineers. Would you like to be considered?', replace: '丰田目前正在积极招聘工程师。您有兴趣被考虑吗?' },
  893. { match: 'I\'d like to talk to you first.', replace: '我想先和您交谈。' },
  894. { match: 'Department name', replace: '部门名称' },
  895. { match: 'What kind of work do you currently do?', replace: '您目前从事什么样的工作?' },
  896. { match: 'How can the Algorithms Group of the Digital Transformation Office help\\?', replace: '数字转型办公室的算法组可以如何帮助您?' }
  897. ];
  898. traverseTextNodes($('.form-group'), rules5);
  899.  
  900. const rules6 = [
  901. { match: 'Unofficial(unrated)', replace: '非官方(无评级)' },
  902. { match: 'Sponsored Parallel(rated)', replace: '赞助平行(有评级)' },
  903. { match: 'Sponsored Parallel(unrated)', replace: '赞助平行(无评级)' },
  904. { match: 'Sponsored Heuristic Contest', replace: '启发式赞助比赛' },
  905. { match: 'All', replace: '全部' },
  906. { match: 'AtCoder Typical Contest', replace: 'AtCoder 经典比赛' },
  907. { match: 'PAST Archive', replace: 'PAST 比赛归档' },
  908. { match: 'JOI Archive', replace: 'JOI 比赛归档' },
  909. { match: 'Sponsored Tournament', replace: '赞助比赛' },
  910. { match: 'Sponsored ABC', replace: '赞助 ABC' },
  911. { match: 'Sponsored ARC', replace: '赞助 ARC' },
  912. { match: 'Heuristic Contest', replace: '启发式比赛' }
  913. ];
  914. strictTraverseTextNodes($('#category-btn-group'), rules6);
  915.  
  916. const rules7 = [
  917. { match: 'Task', replace: '任务' },
  918. { match: 'Language', replace: '语言' },
  919. { match: 'Source Code', replace: '源代码' },
  920. { match: 'Standard Input', replace: '标准输入' },
  921. { match: 'Standard Output', replace: '标准输出' },
  922. { match: 'Standard Error', replace: '标准错误' },
  923. ];
  924. traverseTextNodes($('.control-label'), rules7);
  925.  
  926. const rules8 = [
  927. { match: 'Permanent Contests', replace: '永久比赛' },
  928. { match: 'Upcoming Contests', replace: '即将举行的比赛' },
  929. { match: 'Recent Contests', replace: '最近的比赛' }
  930. ];
  931. traverseTextNodes($('h4'), rules8);
  932.  
  933. const rules9 = [
  934. { match: 'Open File', replace: '打开文件' },
  935. { match: 'Toggle Editor', replace: '切换编辑器' },
  936. { match: 'Auto Height', replace: '自动调整高度' }
  937. ];
  938. traverseTextNodes($('.editor-buttons'), rules9);
  939.  
  940. const rules10 = [
  941. { match: 'Register', replace: '报名' },
  942. { match: 'Virtual Participation', replace: '虚拟参加' }
  943. ];
  944. traverseTextNodes($('.btn'), rules10);
  945.  
  946. const rules11 = [
  947. { match: 'Home', replace: '主页' },
  948. { match: 'Contest', replace: '比赛' },
  949. { match: 'Ranking', replace: '排名' },
  950. { match: 'Sign Up', replace: '注册' },
  951. { match: 'Sign In', replace: '登录' },
  952. ];
  953. strictTraverseTextNodes($('#navbar-collapse'), rules11);
  954. });
  955. })();
  956.  
  957. // 设置面板
  958. $(document).ready(function () {
  959. var htmlContent = "<button class='html2mdButton AtBetter_setting'>AtcoderBetter设置</button>";
  960. $('#navbar-collapse > ul:nth-child(2) > li:last-child').after("<li class='dropdown'>" + htmlContent + "</li>");
  961. });
  962.  
  963. $(document).ready(function () {
  964. const $settingBtns = $(".AtBetter_setting");
  965. $settingBtns.click(() => {
  966. const styleElement = GM_addStyle(darkenPageStyle);
  967. $settingBtns.prop("disabled", true).addClass("open");
  968. $("body").append(`
  969. <div id='AtBetter_setting_menu'>
  970. <div class="tool-box">
  971. <button class="btn-close">×</button>
  972. </div>
  973. <h4>基本设置</h4>
  974. <hr>
  975. <div class='AtBetter_setting_list'>
  976. <label for="bottomZh_CN">界面汉化</label>
  977. <input type="checkbox" id="bottomZh_CN" name="bottomZh_CN">
  978. </div>
  979. <div class='AtBetter_setting_list'>
  980. <label for="showLoading">显示加载信息</label>
  981. <div class="help_tip">
  982. `+ helpCircleHTML + `
  983. <div class="tip_text">
  984. <p>当你开启 显示加载信息 时,每次加载页面时会在上方显示加载信息提示:“Atcoder Better! —— xxx”</p>
  985. <p>这用于了解脚本当前的工作情况,<strong>如果你不想看到,可以选择关闭</strong></p>
  986. <p><u>需要说明的是,如果你需要反馈脚本的任何加载问题,请开启该选项后再截图,以便于分析问题</u></p>
  987. </div>
  988. </div>
  989. <input type="checkbox" id="showLoading" name="showLoading">
  990. </div>
  991. <div class='AtBetter_setting_list'>
  992. <label for="showLoading">显示目标区域范围</label>
  993. <div class="help_tip">
  994. `+ helpCircleHTML + `
  995. <div class="tip_text">
  996. <p>开启后当鼠标悬浮在 MD视图/复制/翻译 按钮上时,会显示其目标区域的范围</p>
  997. </div>
  998. </div>
  999. <input type="checkbox" id="hoverTargetAreaDisplay" name="hoverTargetAreaDisplay">
  1000. </div>
  1001. <div class='AtBetter_setting_list'>
  1002. <label for="enableSegmentedTranslation">分段翻译</label>
  1003. <div class="help_tip">
  1004. `+ helpCircleHTML + `
  1005. <div class="tip_text">
  1006. <p>分段翻译会对区域内的每一个&#60;&#112;&#47;&#62;和&#60;&#105;&#47;&#62;标签依次进行翻译,</p>
  1007. <p>这通常在翻译<strong>长篇博客</strong>或者<strong>超长的题目</strong>时很有用。</p>
  1008. <p><u>注意:开启分段翻译会产生如下问题:</u></p>
  1009. <p>- 使得翻译接口无法知晓整个文本的上下文信息,会降低翻译质量。</p>
  1010. <p>- 会有<strong>部分内容不会被翻译</strong>,因为它们不是&#60;&#112;&#47;&#62;或&#60;&#105;&#47;&#62;标签</p>
  1011. </div>
  1012. </div>
  1013. <input type="checkbox" id="enableSegmentedTranslation" name="enableSegmentedTranslation">
  1014. </div>
  1015. <div class='AtBetter_setting_list'>
  1016. <label for="showJumpToLuogu">显示跳转到洛谷</label>
  1017. <div class="help_tip">
  1018. `+ helpCircleHTML + `
  1019. <div class="tip_text">
  1020. <p>洛谷OJ上收录了Atcoder的部分题目,一些题目有翻译和题解</p>
  1021. <p>开启显示后,如果当前题目被收录,则会在题目的右上角显示洛谷标志,</p>
  1022. <p>点击即可一键跳转到该题洛谷的对应页面。</strong></p>
  1023. </div>
  1024. </div>
  1025. <input type="checkbox" id="showJumpToLuogu" name="showJumpToLuogu">
  1026. </div>
  1027. <div class='AtBetter_setting_list'>
  1028. <label for="loaded"><span style="font-size: 14px;">兼容选项-不等待页面资源加载</span></label>
  1029. <div class="help_tip">
  1030. `+ helpCircleHTML + `
  1031. <div class="tip_text">
  1032. <p>为了防止在页面资源未加载完成前(主要是各种js)执行脚本产生意外的错误,脚本默认会等待 window.onload 事件</p>
  1033. <p>如果您的页面上方的加载信息始终停留在:“等待页面资源加载”,</p>
  1034. <p><u>您首先应该确认是否是网络问题,</u></p>
  1035. <p>如果页面实际已经加载完成,那这可能是由于 window.onload 事件在您的浏览器中触发过早(早于document.ready),</p>
  1036. <p>您可以尝试开启该选项来不再等待 window.onload 事件</p>
  1037. <p><u>注意:如果没有上述问题,请不要开启该选项</u></p>
  1038. </div>
  1039. </div>
  1040. <input type="checkbox" id="loaded" name="loaded">
  1041. </div>
  1042. <h4>翻译设置</h4>
  1043. <hr>
  1044. <label>
  1045. <input type='radio' name='translation' value='deepl'>
  1046. <span class='AtBetter_setting_menu_label_text'>deepl翻译</span>
  1047. </label>
  1048. <label>
  1049. <input type='radio' name='translation' value='youdao'>
  1050. <span class='AtBetter_setting_menu_label_text'>有道翻译</span>
  1051. </label>
  1052. <label>
  1053. <input type='radio' name='translation' value='google'>
  1054. <span class='AtBetter_setting_menu_label_text'>Google翻译</span>
  1055. </label>
  1056. <label>
  1057. <input type='radio' name='translation' value='openai'>
  1058. <span class='AtBetter_setting_menu_label_text'>使用ChatGPT翻译(API)
  1059. <div class="help_tip">
  1060. `+ helpCircleHTML + `
  1061. <div class="tip_text">
  1062. <p><b>请确保你能够正常访问OpenAIapi</b></p>
  1063. <p>Atcoder Better!默认使用 gpt-3.5-turbo 模型进行翻译,脚本的所有请求均在本地完成</p>
  1064. <p>你需要输入自己的OpenAI KEY,<a target="_blank" href="https://platform.openai.com/account/usage">官网</a></p>
  1065. </div>
  1066. </div>
  1067. </span>
  1068. </label>
  1069. <label>
  1070. <input type='radio' name='translation' value='api2d'>
  1071. <span class='AtBetter_setting_menu_label_text'>使用api2d翻译(API)
  1072. <div class="help_tip">
  1073. `+ helpCircleHTML + `
  1074. <div class="tip_text">
  1075. <p>api2d是国内的一家提供代理直连访问OpenAIapi的服务商,相当于OpenAIapi的套壳</p>
  1076. <p>Atcoder Better!默认使用 gpt-3.5-turbo 模型进行翻译,脚本的所有请求均在本地完成</p>
  1077. <p>你需要输入自己的api2d KEY,<a target="_blank" href="https://api2d.com/profile">官网</a></p>
  1078. </div>
  1079. </div>
  1080. </span>
  1081. </label>
  1082. <div class='AtBetter_setting_menu_input' id='openai' style='display: none;'>
  1083. <label for='openai_model'>
  1084. <div style="display: flex;align-items: center;">
  1085. <span class="input_label">模型:</span>
  1086. <div class="help_tip">
  1087. `+ helpCircleHTML + `
  1088. <div class="tip_text">
  1089. <p>默认为:gpt-3.5-turbo</p>
  1090. <p>如需更换,请查阅<a target="_blank" href="https://platform.openai.com/docs/models">官方文档</a></p>
  1091. <p><strong>如果你使用的是服务商提供的代理API,请确认服务商是否支持对应模型</strong></p>
  1092. </div>
  1093. </div>
  1094. </div>
  1095. </label>
  1096. <input type='text' id='openai_model'>
  1097. <label for='openai_key'>
  1098. <span class="input_label">KEY:</span>
  1099. </label>
  1100. <input type='text' id='openai_key'>
  1101. <div class='AtBetter_setting_list'>
  1102. <label for="showOpneAiAdvanced">使用代理API</label>
  1103. <div class="help_tip">
  1104. `+ helpCircleHTML + `
  1105. <div class="tip_text">
  1106. <p>使用你指定的API来代理访问OpenAI进行翻译,脚本的所有请求均在本地完成</p>
  1107. <p>如果你使用的是OpenAI的官方KEY,建议你自建代理,而不是使用他人公开的代理,那是危险的</p>
  1108. <p>如果你使用的是服务商提供的代理和KEY,则这里应该填写其提供的<strong>完整</strong>API地址,<br>
  1109. 这里以<a target="_blank" href="https://console.closeai-asia.com/">CloseAI</a>为例,其提供了API Base: https://api.closeai-proxy.xyz,<br>
  1110. 那么这里实际应该填写的就是https://api.closeai-proxy.xyz/v1/chat/\ncompletions,而上面的KEY则应该填写CloseAI提供的API Key</p>
  1111. <p><strong>由于你指定了自定义的APITampermonkey会对你的跨域请求进行警告,请自行授权</strong></p>
  1112. </div>
  1113. </div>
  1114. <input type="checkbox" id="showOpneAiAdvanced" name="showOpneAiAdvanced">
  1115. </div>
  1116. <div id="is_showOpneAiAdvanced">
  1117. <label for='openai_proxy'>
  1118. <span class="input_label">Proxy API:</span>
  1119. </label>
  1120. <input type='text' id='openai_proxy'>
  1121. </div>
  1122. </div>
  1123. <div class='AtBetter_setting_menu_input' id='api2d' style='display: none;'>
  1124. <label for='api2d_model'>
  1125. <div style="display: flex;align-items: center;">
  1126. <span class="input_label">模型:</span>
  1127. <div class="help_tip">
  1128. `+ helpCircleHTML + `
  1129. <div class="tip_text">
  1130. <p>默认为:gpt-3.5-turbo</p>
  1131. <p>如需更换,请查阅<a target="_blank" href="https://api2d.com/wiki/doc">官方文档</a></p>
  1132. </div>
  1133. </div>
  1134. </div>
  1135. </label>
  1136. <input type='text' id='api2d_model'>
  1137. <label for='api2d_key'>
  1138. <span class="input_label">KEY:</span>
  1139. </label>
  1140. <input type='text' id='api2d_key'>
  1141. <label for='api2d_request_entry'>
  1142. <div style="display: flex;align-items: center;">
  1143. <span class="input_label">请求入口:</span>
  1144. <div class="help_tip">
  1145. `+ helpCircleHTML + `
  1146. <div class="tip_text">
  1147. <p>如果发现请求报错超时未响应,请查看<a target="_blank" href="https://api2d.com/wiki/doc">官方文档</a>以及<a target="_blank" href="https://support.qq.com/product/544571">API2D反馈论坛</a>尝试更换请求入口</p>
  1148. <p>默认为:https://openai.api2d.net</p>
  1149. <p>注意格式,末尾没有“斜杠/”</p>
  1150. </div>
  1151. </div>
  1152. </div>
  1153. </label>
  1154. <input type='text' id='api2d_request_entry'>
  1155. <div class='AtBetter_setting_list'>
  1156. <label for="x_api2d_no_cache">使用缓存</label>
  1157. <div class="help_tip">
  1158. `+ helpCircleHTML + `
  1159. <div class="tip_text">
  1160. <p>API2D 的服务器会对请求结果做缓存,如果请求体的hash值相同,会直接返回缓存的结果。缓存命中之后,本次请求不会扣除任何点数。</p>
  1161. <p>缓存会保存 24 小时,如果不想使用缓存,你可以关闭“使用缓存”来跳过缓存,强制 API2D 服务器发送新请求。<a target="_blank" href="https://api2d.com/wiki/doc">详请阅读官方文档</a></p>
  1162. </div>
  1163. </div>
  1164. <input type="checkbox" id="x_api2d_no_cache" name="x_api2d_no_cache">
  1165. </div>
  1166. </div>
  1167. <br>
  1168. <button id='save'>保存</button>
  1169. </div>
  1170. `);
  1171. $("#bottomZh_CN").prop("checked", GM_getValue("bottomZh_CN") === true);
  1172. $("#showLoading").prop("checked", GM_getValue("showLoading") === true);
  1173. $("#enableSegmentedTranslation").prop("checked", GM_getValue("enableSegmentedTranslation") === true);
  1174. $("#showJumpToLuogu").prop("checked", GM_getValue("showJumpToLuogu") === true);
  1175. $("#loaded").prop("checked", GM_getValue("loaded") === true);
  1176. $("#x_api2d_no_cache").prop("checked", GM_getValue("x_api2d_no_cache") === true);
  1177. $("#showOpneAiAdvanced").prop("checked", GM_getValue("showOpneAiAdvanced") === true);
  1178. $("#hoverTargetAreaDisplay").prop("checked", GM_getValue("hoverTargetAreaDisplay") === true);
  1179. $("input[name='translation'][value='" + translation + "']").prop("checked", true);
  1180. $("input[name='translation']").css("color", "gray");
  1181. if (translation == "openai") {
  1182. $("#openai").show();
  1183. $("#openai_model").val(openai_model);
  1184. $("#openai_key").val(GM_getValue("openai_key"));
  1185. $("#openai_proxy").val(GM_getValue("openai_proxy"));
  1186. $("#openai_key").css("color", "gray");
  1187. if (showOpneAiAdvanced) $("#is_showOpneAiAdvanced").show();
  1188. else $("#is_showOpneAiAdvanced").hide();
  1189. } else if (translation == "api2d") {
  1190. $("#api2d").show();
  1191. $("#api2d_model").val(api2d_model);
  1192. $("#api2d_key").val(GM_getValue("api2d_key"));
  1193. $("#api2d_request_entry").val(api2d_request_entry);
  1194. $("#api2d_key").css("color", "gray");
  1195. }
  1196. // 当单选框被选中时,显示对应的输入框,同时隐藏其他输入框
  1197. $("input[name='translation']").change(function () {
  1198. var selected = $(this).val(); // 获取当前选中的值
  1199. if (selected === "openai") {
  1200. $("#openai").show();
  1201. $("#openai_model").val(openai_model);
  1202. $("#openai_key").val(GM_getValue("openai_key"));
  1203. $("#showOpneAiAdvanced").prop("checked", showOpneAiAdvanced);
  1204. if (showOpneAiAdvanced) {
  1205. $("#is_showOpneAiAdvanced").show();
  1206. $("#openai_proxy").val(GM_getValue("openai_proxy"));
  1207. }
  1208. else $("#is_showOpneAiAdvanced").hide();
  1209. $("#api2d").hide();
  1210. } else if (selected === "api2d") {
  1211. $("#api2d").show();
  1212. $("#api2d_model").val(api2d_model);
  1213. $("#api2d_key").val(GM_getValue("api2d_key"));
  1214. $("#api2d_request_entry").val(api2d_request_entry);
  1215. $("#x_api2d_no_cache").prop("checked", GM_getValue("x_api2d_no_cache"));
  1216. $("#openai").hide();
  1217. } else {
  1218. $("#openai, #api2d").hide();
  1219. }
  1220. });
  1221.  
  1222. // ChatGPT高级选项
  1223. $("input[name='showOpneAiAdvanced']").change(function () {
  1224. var isChecked = $(this).is(":checked");
  1225. if (isChecked) {
  1226. $("#is_showOpneAiAdvanced").show();
  1227. } else {
  1228. $("#is_showOpneAiAdvanced").hide();
  1229. }
  1230. });
  1231.  
  1232. const $settingMenu = $("#AtBetter_setting_menu");
  1233.  
  1234. $("#save").click(debounce(function () {
  1235. const settings = {
  1236. bottomZh_CN: $("#bottomZh_CN").prop("checked"),
  1237. showLoading: $("#showLoading").prop("checked"),
  1238. loaded: $("#loaded").prop("checked"),
  1239. enableSegmentedTranslation: $("#enableSegmentedTranslation").prop("checked"),
  1240. showJumpToLuogu: $("#showJumpToLuogu").prop("checked"),
  1241. showOpneAiAdvanced: $("#showOpneAiAdvanced").prop("checked"),
  1242. hoverTargetAreaDisplay: $("#hoverTargetAreaDisplay").prop("checked"),
  1243. translation: $("input[name='translation']:checked").val()
  1244. };
  1245. if (settings.translation === "openai") {
  1246. GM_setValue("openai_model", $("#openai_model").val());
  1247. GM_setValue("openai_key", $("#openai_key").val());
  1248. GM_setValue("openai_proxy", $("#openai_proxy").val());
  1249. } else if (settings.translation === "api2d") {
  1250. GM_setValue("api2d_model", $("#api2d_model").val());
  1251. GM_setValue("api2d_key", $("#api2d_key").val());
  1252. GM_setValue("api2d_request_entry", $("#api2d_request_entry").val());
  1253. GM_setValue("x_api2d_no_cache", $("#x_api2d_no_cache").prop("checked"));
  1254. }
  1255. for (const [key, value] of Object.entries(settings)) {
  1256. GM_setValue(key, value);
  1257. }
  1258.  
  1259. $settingMenu.remove();
  1260. $(styleElement).remove();
  1261. location.reload();
  1262. }));
  1263.  
  1264. // 关闭
  1265. $settingMenu.on("click", ".btn-close", () => {
  1266. $settingMenu.remove();
  1267. $settingBtns.prop("disabled", false).removeClass("open");
  1268. $(styleElement).remove();
  1269. });
  1270. });
  1271. });
  1272.  
  1273. // html2md转换/处理规则
  1274. var turndownService = new TurndownService({ bulletListMarker: '-', escape: (text) => text });
  1275. var turndown = turndownService.turndown;
  1276.  
  1277. // 保留原始
  1278. turndownService.keep(['del']);
  1279.  
  1280. turndownService.addRule('removeByClass', {
  1281. filter: function (node) {
  1282. return node.classList.contains('html2md-panel') ||
  1283. node.classList.contains('div-btn-copy') ||
  1284. node.classList.contains('btn-copy') ||
  1285. node.classList.contains('overlay')
  1286. },
  1287. replacement: function () {
  1288. return '';
  1289. }
  1290. });
  1291.  
  1292. // inline math
  1293. turndownService.addRule('inline-math', {
  1294. filter: function (node, options) {
  1295. return node.tagName.toLowerCase() == "span" && node.className == "katex";
  1296. },
  1297. replacement: function (content, node) {
  1298. var latex = $(node).find('annotation').text();
  1299. latex = latex.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  1300. return "$" + latex + "$";
  1301. }
  1302. });
  1303.  
  1304. // block math
  1305. turndownService.addRule('block-math', {
  1306. filter: function (node, options) {
  1307. return node.tagName.toLowerCase() == "span" && node.className == "katex-display";
  1308. },
  1309. replacement: function (content, node) {
  1310. var latex = $(node).find('annotation').text();
  1311. latex = latex.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  1312. return "\n$$\n" + latex + "\n$$\n";
  1313. }
  1314. });
  1315.  
  1316. // pre
  1317. turndownService.addRule('pre', {
  1318. filter: function (node, options) {
  1319. return node.tagName.toLowerCase() == "pre";
  1320. },
  1321. replacement: function (content, node) {
  1322. return "```\n" + content + "```\n";
  1323. }
  1324. });
  1325.  
  1326. // bordertable
  1327. turndownService.addRule('bordertable', {
  1328. filter: 'table',
  1329. replacement: function (content, node) {
  1330. if (node.classList.contains('table')) {
  1331. var output = [],
  1332. thead = '',
  1333. trs = node.querySelectorAll('tr');
  1334. if (trs.length > 0) {
  1335. var ths = trs[0].querySelectorAll('th, td');
  1336. console.log(ths.length);
  1337. if (ths.length > 0) {
  1338. thead = '| ' + Array.from(ths).map(th => turndownService.turndown(th.innerHTML.trim())).join(' | ') + ' |\n'
  1339. thead += '| ' + Array.from(ths).map(() => ' --- ').join('|') + ' |\n';
  1340. }
  1341. }
  1342. var rows = node.querySelectorAll('tr');
  1343. Array.from(rows).forEach(function (row, i) {
  1344. if (i > 0) {
  1345. var cells = row.querySelectorAll('td,th');
  1346. var trow = '| ' + Array.from(cells).map(cell => turndownService.turndown(cell.innerHTML.trim())).join(' | ') + ' |';
  1347. output.push(trow);
  1348. }
  1349. });
  1350. return thead + output.join('\n');
  1351. } else {
  1352. return content;
  1353. }
  1354. }
  1355. });
  1356.  
  1357. // 随机数生成
  1358. function getRandomNumber(numDigits) {
  1359. let min = Math.pow(10, numDigits - 1);
  1360. let max = Math.pow(10, numDigits) - 1;
  1361. return Math.floor(Math.random() * (max - min + 1)) + min;
  1362. }
  1363.  
  1364. // 题目markdown转换/翻译面板
  1365. function addButtonPanel(parent, suffix, type, is_simple = false) {
  1366. let htmlString = `<div class='html2md-panel'>
  1367. <button class='html2mdButton html2md-view${suffix}'>MarkDown视图</button>
  1368. <button class='html2mdButton html2md-cb${suffix}'>Copy</button>
  1369. <button class='html2mdButton translateButton${suffix}'>翻译</button>
  1370. </div>`;
  1371. if (type === "this_level") {
  1372. $(parent).before(htmlString);
  1373. } else if (type === "child_level") {
  1374. $(parent).prepend(htmlString);
  1375. }
  1376. if (is_simple) {
  1377. $('.html2md-panel').find('.html2mdButton.html2md-view' + suffix + ', .html2mdButton.html2md-cb' + suffix).remove();
  1378. }
  1379. }
  1380.  
  1381. function addButtonWithHTML2MD(parent, suffix, type) {
  1382. $(document).on("click", ".html2md-view" + suffix, debounce(function () {
  1383. var target, removedChildren = $();
  1384. if (type === "this_level") {
  1385. target = $(".html2md-view" + suffix).parent().next().get(0);
  1386. } else if (type === "child_level") {
  1387. target = $(".html2md-view" + suffix).parent().parent().get(0);
  1388. removedChildren = $(".html2md-view" + suffix).parent().parent().children(':first').detach();
  1389. }
  1390. if (target.viewmd) {
  1391. target.viewmd = false;
  1392. $(this).text("MarkDown视图");
  1393. $(this).removeClass("mdViewed");
  1394. $(target).html(target.original_html);
  1395. } else {
  1396. target.viewmd = true;
  1397. if (!target.original_html) {
  1398. target.original_html = $(target).html();
  1399. }
  1400. if (!target.markdown) {
  1401. target.markdown = turndownService.turndown($(target).html());
  1402. }
  1403. $(this).text("原始内容");
  1404. $(this).addClass("mdViewed");
  1405. $(target).html(`<span class="mdViewContent" oninput="$(this).parent().get(0).markdown=this.value;" style="width:auto; height:auto;">${target.markdown}</span>`);
  1406. }
  1407. // 恢复删除的元素
  1408. if (removedChildren) $(target).prepend(removedChildren);
  1409. }));
  1410.  
  1411. if (hoverTargetAreaDisplay) {
  1412. $(document).on("mouseover", ".html2md-view" + suffix, function () {
  1413. var target;
  1414.  
  1415. if (type === "this_level") {
  1416. target = $(".html2md-view" + suffix).parent().next().get(0);
  1417. } else if (type === "child_level") {
  1418. target = $(".html2md-view" + suffix).parent().parent().get(0);
  1419. }
  1420.  
  1421. $(target).append('<div class="overlay">目标转换区域</div>');
  1422. $(target).css({
  1423. "position": "relative",
  1424. "display": "block"
  1425. });
  1426. $(".html2md-view" + suffix).parent().css({
  1427. "position": "relative",
  1428. "z-index": "99999"
  1429. })
  1430. });
  1431.  
  1432. $(document).on("mouseout", ".html2md-view" + suffix, function () {
  1433. var target;
  1434.  
  1435. if (type === "this_level") {
  1436. target = $(".html2md-view" + suffix).parent().next().get(0);
  1437. } else if (type === "child_level") {
  1438. target = $(".html2md-view" + suffix).parent().parent().get(0);
  1439. }
  1440.  
  1441. $(target).find('.overlay').remove();
  1442. $(target).css({
  1443. "position": "",
  1444. "display": ""
  1445. });
  1446. $(".html2md-view" + suffix).parent().css({
  1447. "position": "static"
  1448. })
  1449. });
  1450. }
  1451. }
  1452.  
  1453. function addButtonWithCopy(parent, suffix, type) {
  1454. $(document).on("click", ".html2md-cb" + suffix, debounce(function () {
  1455. var target, removedChildren;
  1456. if (type === "this_level") {
  1457. target = $(".translateButton" + suffix).parent().next().eq(0).clone();
  1458. } else if (type === "child_level") {
  1459. target = $(".translateButton" + suffix).parent().parent().eq(0).clone();
  1460. $(target).children(':first').remove();
  1461. }
  1462. if ($(target).find('.mdViewContent').length <= 0) {
  1463. text = turndownService.turndown($(target).html());
  1464. } else {
  1465. text = $(target).find('.mdViewContent').text();
  1466. }
  1467. GM_setClipboard(text);
  1468. $(this).addClass("copied");
  1469. $(this).text("Copied");
  1470. // 更新复制按钮文本
  1471. setTimeout(() => {
  1472. $(this).removeClass("copied");
  1473. $(this).text("Copy");
  1474. }, 2000);
  1475. $(target).remove();
  1476. }));
  1477.  
  1478. if (hoverTargetAreaDisplay) {
  1479. $(document).on("mouseover", ".html2md-cb" + suffix, function () {
  1480. var target;
  1481.  
  1482. if (type === "this_level") {
  1483. target = $(".html2md-cb" + suffix).parent().next().get(0);
  1484. } else if (type === "child_level") {
  1485. target = $(".html2md-cb" + suffix).parent().parent().get(0);
  1486. }
  1487.  
  1488. $(target).append('<div class="overlay">目标复制区域</div>');
  1489. $(target).css({
  1490. "position": "relative",
  1491. "display": "block"
  1492. });
  1493. $(".html2md-cb" + suffix).parent().css({
  1494. "position": "relative",
  1495. "z-index": "99999"
  1496. })
  1497. });
  1498.  
  1499. $(document).on("mouseout", ".html2md-cb" + suffix, function () {
  1500. var target;
  1501.  
  1502. if (type === "this_level") {
  1503. target = $(".html2md-cb" + suffix).parent().next().get(0);
  1504. } else if (type === "child_level") {
  1505. target = $(".html2md-cb" + suffix).parent().parent().get(0);
  1506. }
  1507.  
  1508. $(target).find('.overlay').remove();
  1509. $(target).css({
  1510. "position": "",
  1511. "display": ""
  1512. });
  1513. $(".html2md-cb" + suffix).parent().css({
  1514. "position": "static"
  1515. })
  1516. });
  1517. }
  1518. }
  1519.  
  1520. async function addButtonWithTranslation(parent, suffix, type) {
  1521. var result;
  1522. $(document).on('click', '.translateButton' + suffix, debounce(async function () {
  1523. $(this).removeClass("translated");
  1524. $(this).text("翻译中");
  1525. $(this).css("cursor", "not-allowed");
  1526. var target, element_node, block, errerNum = 0, is_x_api2d_no_cache = false;
  1527. if (type === "this_level") block = $(".translateButton" + suffix).parent().next();
  1528. else if (type === "child_level") block = $(".translateButton" + suffix).parent().parent();
  1529.  
  1530. // 重新翻译
  1531. if (result) {
  1532. if (result.translateDiv) {
  1533. $(result.translateDiv).remove();
  1534. }
  1535. if (result.copyDiv) {
  1536. $(result.copyDiv).remove();
  1537. }
  1538. if (result.copyButton) {
  1539. $(result.copyButton).remove();
  1540. }
  1541. // 重新翻译时暂时关闭 x_api2d_no_cache
  1542. if (x_api2d_no_cache) {
  1543. x_api2d_no_cache = false;
  1544. is_x_api2d_no_cache = true;
  1545. }
  1546. // 移除旧的事件
  1547. $(document).off("mouseover", ".translateButton" + suffix);
  1548. $(document).off("mouseout", ".translateButton" + suffix);
  1549. // 重新绑定悬停事件
  1550. if (hoverTargetAreaDisplay) bindHoverEvents(suffix, type);
  1551. }
  1552.  
  1553. // 分段翻译
  1554. if (enableSegmentedTranslation) {
  1555. var pElements = block.find("p, li");
  1556. for (let i = 0; i < pElements.length; i++) {
  1557. target = $(pElements[i]).eq(0).clone();
  1558. if (type === "child_level") $(target).children(':first').remove();
  1559. element_node = pElements[i];
  1560. if (type === "child_level") {
  1561. $(pElements[i]).append("<div></div>");
  1562. element_node = $(pElements[i]).find("div:last-child").get(0);
  1563. }
  1564. result = await blockProcessing(target, element_node, $(".translateButton" + suffix));
  1565. if (result.status) errerNum += 1;
  1566. $(target).remove();
  1567. if (translation == "deepl") await new Promise(resolve => setTimeout(resolve, 2000));
  1568. }
  1569. } else {
  1570. target = block.eq(0).clone();
  1571. if (type === "child_level") $(target).children(':first').remove();
  1572. element_node = $(block).get(0);
  1573. if (type === "child_level") {
  1574. $(parent).append("<div></div>");
  1575. element_node = $(parent).find("div:last-child").get(0);
  1576. }
  1577. //是否跳过折叠块
  1578. if ($(target).find('.spoiler').length > 0) {
  1579. const shouldSkip = await skiFoldingBlocks();
  1580. if (shouldSkip) {
  1581. $(target).find('.spoiler').remove();
  1582. } else {
  1583. $(target).find('.html2md-panel').remove();
  1584. }
  1585. }
  1586. result = await blockProcessing(target, element_node, $(".translateButton" + suffix));
  1587. if (result.status) errerNum += 1;
  1588. $(target).remove();
  1589. }
  1590. if (!errerNum) {
  1591. $(this).addClass("translated")
  1592. .text("已翻译")
  1593. .css("cursor", "pointer")
  1594. .removeClass("error");
  1595. }
  1596.  
  1597. // 恢复x_api2d_no_cache设置
  1598. if (is_x_api2d_no_cache) x_api2d_no_cache = true;
  1599.  
  1600. // 重新翻译
  1601. let currentText, is_error;
  1602. $(document).on("mouseover", ".translateButton" + suffix, function () {
  1603. currentText = $(this).text();
  1604. $(this).text("重新翻译");
  1605. if ($(this).hasClass("error")) {
  1606. is_error = true;
  1607. $(this).removeClass("error");
  1608. }
  1609. });
  1610.  
  1611. $(document).on("mouseout", ".translateButton" + suffix, function () {
  1612. $(this).text(currentText);
  1613. if (is_error) $(this).addClass("error");
  1614. });
  1615. }));
  1616.  
  1617. // 目标区域指示
  1618. function bindHoverEvents(suffix, type) {
  1619. $(document).on("mouseover", ".translateButton" + suffix, function () {
  1620. var target;
  1621.  
  1622. if (type === "this_level") {
  1623. target = $(".translateButton" + suffix).parent().next().get(0);
  1624. } else if (type === "child_level") {
  1625. target = $(".translateButton" + suffix).parent().parent().get(0);
  1626. }
  1627.  
  1628. $(target).append('<div class="overlay">目标翻译区域</div>');
  1629. $(target).css({
  1630. "position": "relative",
  1631. "display": "block"
  1632. });
  1633. $(".translateButton" + suffix).parent().css({
  1634. "position": "relative",
  1635. "z-index": "99999"
  1636. });
  1637. });
  1638.  
  1639. $(document).on("mouseout", ".translateButton" + suffix, function () {
  1640. var target;
  1641.  
  1642. if (type === "this_level") {
  1643. target = $(".translateButton" + suffix).parent().next().get(0);
  1644. } else if (type === "child_level") {
  1645. target = $(".translateButton" + suffix).parent().parent().get(0);
  1646. }
  1647.  
  1648. $(target).find('.overlay').remove();
  1649. $(target).css({
  1650. "position": "",
  1651. "display": ""
  1652. });
  1653. $(".translateButton" + suffix).parent().css({
  1654. "position": "static"
  1655. });
  1656. });
  1657. }
  1658.  
  1659. if (hoverTargetAreaDisplay) bindHoverEvents(suffix, type);
  1660. }
  1661.  
  1662. // 块处理
  1663. async function blockProcessing(target, element_node, button) {
  1664. if (!target.markdown) {
  1665. target.markdown = turndownService.turndown($(target).html());
  1666. }
  1667. const textarea = document.createElement('textarea');
  1668. textarea.value = target.markdown;
  1669. var result = await translateProblemStatement(textarea.value, element_node, $(button));
  1670. //
  1671. if (result.status == 1) {
  1672. $(button).addClass("error")
  1673. .text("翻译中止")
  1674. .css("cursor", "pointer")
  1675. .prop("disabled", false);
  1676. $(result.translateDiv).remove();
  1677. $(target).remove();
  1678. } else if (result.status == 2) {
  1679. result.translateDiv.classList.add("error_translate");
  1680. $(button).addClass("error")
  1681. .text("翻译出错")
  1682. .css("cursor", "pointer")
  1683. .prop("disabled", false);
  1684. $(target).remove();
  1685. }
  1686. return result;
  1687. }
  1688.  
  1689. function addConversionButton() {
  1690. // 基本添加
  1691. $('section').each(function () {
  1692. let id = "_" + getRandomNumber(8);
  1693. addButtonPanel(this, id, "this_level");
  1694. addButtonWithHTML2MD(this, id, "this_level");
  1695. addButtonWithCopy(this, id, "this_level");
  1696. addButtonWithTranslation(this, id, "this_level");
  1697. });
  1698.  
  1699. // 添加按钮到题解部分
  1700. if (window.location.href.includes("editorial")) {
  1701. let contestNavTabs = $("#contest-nav-tabs");
  1702. let nextElement = contestNavTabs.next();
  1703. let id = "_editorial_" + getRandomNumber(8);
  1704. addButtonPanel(nextElement, id, "child_level");
  1705. addButtonWithHTML2MD(nextElement, id, "child_level");
  1706. addButtonWithCopy(nextElement, id, "child_level");
  1707. addButtonWithTranslation(nextElement, id, "child_level");
  1708. }
  1709. if (window.location.href.includes("editorial")) {
  1710. let contestNavTabs = $("#contest-nav-tabs");
  1711. let nextElement = contestNavTabs.next().children().eq(-2);
  1712. let id = "_editorial_" + getRandomNumber(8);
  1713. addButtonPanel(nextElement, id, "child_level");
  1714. addButtonWithHTML2MD(nextElement, id, "child_level");
  1715. addButtonWithCopy(nextElement, id, "child_level");
  1716. addButtonWithTranslation(nextElement, id, "child_level");
  1717. }
  1718.  
  1719. // 添加按钮到折叠块部分
  1720. $('details').each(function () {
  1721. let id = "_details_" + getRandomNumber(8);
  1722. addButtonPanel(this, id, "child_level");
  1723. addButtonWithHTML2MD(this, id, "child_level");
  1724. addButtonWithCopy(this, id, "child_level");
  1725. addButtonWithTranslation(this, id, "child_level");
  1726. });
  1727.  
  1728. // 添加到contest-statement部分
  1729. $('#contest-statement').each(function () {
  1730. let id = "_contest-statement_" + getRandomNumber(8);
  1731. addButtonPanel(this, id, "this_level");
  1732. addButtonWithHTML2MD(this, id, "this_level");
  1733. addButtonWithCopy(this, id, "this_level");
  1734. addButtonWithTranslation(this, id, "this_level");
  1735. });
  1736.  
  1737. // 添加到blog-post部分
  1738. $('.blog-post').each(function () {
  1739. let id = "_blog-post_" + getRandomNumber(8);
  1740. addButtonPanel(this, id, "this_level");
  1741. addButtonWithHTML2MD(this, id, "this_level");
  1742. addButtonWithCopy(this, id, "this_level");
  1743. addButtonWithTranslation(this, id, "this_level");
  1744. });
  1745. };
  1746.  
  1747. // 跳转洛谷
  1748. async function At2luogu() {
  1749. const getProblemId = () => {
  1750. const url = window.location.href;
  1751. const regex = /\/contests\/([A-Za-z\d]+)\/tasks\/([A-Za-z\d\_]+)/;
  1752. const matchResult = url.match(regex);
  1753. return matchResult && matchResult.length >= 3
  1754. ? `${matchResult[2]}`
  1755. : '';
  1756. };
  1757.  
  1758. const checkLinkExistence = (url) => {
  1759. return new Promise((resolve, reject) => {
  1760. GM.xmlHttpRequest({
  1761. method: "GET",
  1762. url,
  1763. headers: { "Range": "bytes=0-9999" }, // 获取前10KB数据
  1764. onload(response) {
  1765. if (response.responseText.match(/题目未找到/g)) {
  1766. resolve(false);
  1767. } else {
  1768. resolve(true);
  1769. }
  1770. },
  1771. onerror(error) {
  1772. reject(error);
  1773. }
  1774. });
  1775. });
  1776. };
  1777.  
  1778. const url = `https://www.luogu.com.cn/problem/AT_${getProblemId()}`;
  1779. const result = await checkLinkExistence(url);
  1780. if (getProblemId() && result) {
  1781. const problemLink = $("<a style='display: inline-block;vertical-align: middle;'>")
  1782. .attr("id", "problemLink")
  1783. .attr("href", url)
  1784. .attr("target", "_blank")
  1785. .html(`<button style="height: 25px;" class="html2mdButton"><img style="width:45px; margin-right:2px;" src="https://cdn.luogu.com.cn/fe/logo.png"></button>`);
  1786. problemLink.appendTo('.h2');
  1787. }
  1788. }
  1789.  
  1790. $(document).ready(function () {
  1791. var newElement = $("<div></div>")
  1792. .addClass("alert alert-info")
  1793. .html(`Atcoder Better! —— 正在等待页面资源加载……`)
  1794. .css({
  1795. margin: "1em",
  1796. "text-align": "center",
  1797. "font-weight": "600",
  1798. position: "relative",
  1799. });
  1800.  
  1801. var tip_SegmentedTranslation = $("<div></div>")
  1802. .addClass("alert alert-danger")
  1803. .html(`
  1804. Atcoder Better! —— 注意!分段翻译已开启,这会造成负面效果,
  1805. <p>除非你现在需要翻译超长篇的博客或者题目,否则请前往设置关闭分段翻译</p>
  1806. `)
  1807. .css({
  1808. margin: "1em",
  1809. "text-align": "center",
  1810. "font-weight": "600",
  1811. position: "relative",
  1812. });
  1813.  
  1814. function processPage() {
  1815. if (enableSegmentedTranslation)
  1816. $("#main-container").prepend(tip_SegmentedTranslation); //显示分段翻译警告
  1817.  
  1818. if (showLoading) {
  1819. newElement.html("Atcoder Better! —— 正在处理中……");
  1820. newElement.removeClass("alert-info").addClass("alert-success");
  1821. }
  1822.  
  1823. if (showJumpToLuogu) At2luogu();
  1824.  
  1825. addConversionButton();
  1826.  
  1827. if (showLoading) {
  1828. newElement.html("Atcoder Better! —— 加载已完成");
  1829. setTimeout(function () {
  1830. newElement.remove();
  1831. }, 3000);
  1832. }
  1833. }
  1834.  
  1835. if (showLoading) $("#main-container").prepend(newElement);
  1836.  
  1837. if (loaded) {
  1838. processPage();
  1839. } else {
  1840. // 页面完全加载完成后执行
  1841. window.onload = function () {
  1842. processPage();
  1843. };
  1844. }
  1845. });
  1846.  
  1847. // 字数超限确认
  1848. function showWordsExceededDialog(button) {
  1849. return new Promise(resolve => {
  1850. const styleElement = GM_addStyle(darkenPageStyle);
  1851. $(button).removeClass("translated");
  1852. $(button).text("字数超限");
  1853. $(button).css("cursor", "not-allowed");
  1854. $(button).prop("disabled", true);
  1855. let htmlString = `
  1856. <div class="wordsExceeded">
  1857. <h4>字数超限!</h4>
  1858. <p>注意,即将翻译的内容字数超过了4950个字符,您可能选择了错误的翻译按钮</p>
  1859. <div style="display:flex; padding:5px 0px; align-items: center;">
  1860. `+ helpCircleHTML + `
  1861. <p>
  1862. 由于实现方式,区域中会出现多个翻译按钮,请点击更小的子区域中的翻译按钮,
  1863. <br>或者在设置面板中开启 分段翻译 后重试。
  1864. </p>
  1865. </div>
  1866. <p>对于免费的接口,大量请求可能导致你的IP被暂时禁止访问,对于GPT,会消耗大量的token</p>
  1867. <p>您确定要继续翻译吗?</p>
  1868. <div style="display:flex; padding-top:10px">
  1869. <button id="continueButton">继续</button><button id="cancelButton">取消</button>
  1870. </div>
  1871. </div>
  1872. `;
  1873. $('body').before(htmlString);
  1874. $("#continueButton").click(function () {
  1875. $(styleElement).remove();
  1876. $('.wordsExceeded').remove();
  1877. resolve(true);
  1878. });
  1879. $("#cancelButton").click(function () {
  1880. $(styleElement).remove();
  1881. $('.wordsExceeded').remove();
  1882. resolve(false);
  1883. });
  1884. });
  1885. }
  1886.  
  1887. // 跳过折叠块确认
  1888. function skiFoldingBlocks() {
  1889. return new Promise(resolve => {
  1890. const styleElement = GM_addStyle(darkenPageStyle);
  1891. let htmlString = `
  1892. <div class="wordsExceeded">
  1893. <h4>是否跳过折叠块?</h4>
  1894. <p></p>
  1895. <div style="display:grid; padding:5px 0px; align-items: center;">
  1896. <p>
  1897. 即将翻译的区域中包含折叠块,可能不需要翻译,现在您需要选择是否跳过这些折叠块,
  1898. </p>
  1899. <p>
  1900. 如果其中有您需要翻译的折叠块,可以稍后再单独点击这些折叠块内的翻译按钮进行翻译
  1901. </p>
  1902. </div>
  1903. <p>要跳过折叠块吗?(建议选择跳过)</p>
  1904. <div style="display:flex; padding-top:10px">
  1905. <button id="cancelButton">否</button><button id="skipButton">跳过</button>
  1906. </div>
  1907. </div>
  1908. `;
  1909. $('body').before(htmlString);
  1910. $("#skipButton").click(function () {
  1911. $(styleElement).remove();
  1912. $('.wordsExceeded').remove();
  1913. resolve(true);
  1914. });
  1915. $("#cancelButton").click(function () {
  1916. $(styleElement).remove();
  1917. $('.wordsExceeded').remove();
  1918. resolve(false);
  1919. });
  1920. });
  1921. }
  1922.  
  1923. // 翻译框/翻译处理器
  1924. var translatedText = "";
  1925. async function translateProblemStatement(text, element_node, button) {
  1926. let status = 0;
  1927. let id = getRandomNumber(8);
  1928. let matches = [];
  1929. let replacements = {};
  1930. // 创建元素并放在element_node的后面
  1931. const translateDiv = document.createElement('div');
  1932. translateDiv.setAttribute('id', id);
  1933. translateDiv.classList.add('translate-problem-statement');
  1934. const spanElement = document.createElement('span');
  1935. translateDiv.appendChild(spanElement);
  1936. element_node.insertAdjacentElement('afterend', translateDiv);
  1937. // 替换latex公式
  1938. if (translation != "api2d" && translation != "openai") {
  1939. // 使用GPT翻译时不必替换latex公式
  1940. let i = 0;
  1941. // 块公式
  1942. matches = matches.concat(text.match(/\$\$([\s\S]*?)\$\$/g));
  1943. try {
  1944. for (i; i < matches.length; i++) {
  1945. let match = matches[i];
  1946. text = text.replace(match, `【${i + 1}】`);
  1947. replacements[`【${i + 1}】`] = match;
  1948. }
  1949. } catch (e) { }
  1950. // 行内公式
  1951. matches = matches.concat(text.match(/\$(.*?)\$/g));
  1952. try {
  1953. for (i; i < matches.length; i++) {
  1954. let match = matches[i];
  1955. text = text.replace(match, `【${i + 1}】`);
  1956. replacements[`【${i + 1}】`] = match;
  1957. }
  1958. } catch (e) { }
  1959. }
  1960. if (text.length > 4950) {
  1961. const shouldContinue = await showWordsExceededDialog(button);
  1962. if (!shouldContinue) {
  1963. status = 1;
  1964. return {
  1965. translateDiv: translateDiv,
  1966. status: status
  1967. };
  1968. }
  1969. }
  1970. // 翻译
  1971. if (translation == "deepl") {
  1972. translateDiv.innerHTML = "正在翻译中……请稍等";
  1973. translatedText = await translate_deepl(text);
  1974. } else if (translation == "youdao") {
  1975. translateDiv.innerHTML = "正在翻译中……请稍等";
  1976. translatedText = await translate_youdao_mobile(text);
  1977. } else if (translation == "google") {
  1978. translateDiv.innerHTML = "正在翻译中……请稍等";
  1979. translatedText = await translate_gg(text);
  1980. } else if (translation == "openai") {
  1981. try {
  1982. translateDiv.innerHTML = "正在翻译中……<br><br>使用GPT(ChatGPT/api2d)进行翻译通常需要很长的时间,请耐心等待";
  1983. translatedText = await translate_openai(text);
  1984. } catch (error) {
  1985. status = 2;
  1986. translatedText = error;
  1987. }
  1988. } else if (translation == "api2d") {
  1989. try {
  1990. translateDiv.innerHTML = "正在翻译中……<br><br>使用GPT(ChatGPT/api2d)进行翻译通常需要很长的时间,请耐心等待";
  1991. translatedText = await translate_api2d(text);
  1992. } catch (error) {
  1993. status = 2;
  1994. translatedText = error;
  1995. }
  1996. }
  1997. if (/^翻译出错/.test(translatedText)) status = 2;
  1998. // 还原latex公式
  1999. if (translation != "api2d" && translation != "openai") {
  2000. try {
  2001. for (let i = 0; i < matches.length; i++) {
  2002. let match = matches[i];
  2003. let replacement = replacements[`【${i + 1}】`];
  2004. let regex;
  2005. regex = new RegExp(`【\\s*${i + 1}\\s*】`, 'g');
  2006. translatedText = translatedText.replace(regex, replacement);
  2007. regex = new RegExp(`\\[\\s*${i + 1}\\s*\\]`, 'g');
  2008. translatedText = translatedText.replace(regex, replacement);
  2009. regex = new RegExp(`【\\s*${i + 1}[^】\\d]`, 'g');
  2010. translatedText = translatedText.replace(regex, replacement);
  2011. regex = new RegExp(`[^【\\d]${i + 1}\\s*】`, 'g');
  2012. translatedText = translatedText.replace(regex, " " + replacement);
  2013. }
  2014. } catch (e) { }
  2015. }
  2016.  
  2017. // 创建一个隐藏的元素来保存 translatedText 的值
  2018. var textElement = document.createElement("div");
  2019. textElement.style.display = "none";
  2020. textElement.textContent = translatedText;
  2021. translateDiv.parentNode.insertBefore(textElement, translateDiv);
  2022.  
  2023. // 翻译复制按钮
  2024. var copyButton = document.createElement("button");
  2025. copyButton.textContent = "Copy";
  2026. var wrapperDiv = document.createElement("div");
  2027. $(wrapperDiv).css({
  2028. display: "flex",
  2029. justifyContent: "flex-end"
  2030. });
  2031. $(wrapperDiv).append(copyButton);
  2032. $(copyButton).addClass("html2mdButton html2md-cb");
  2033.  
  2034. copyButton.addEventListener("click", function () {
  2035. var translatedText = textElement.textContent;
  2036. GM_setClipboard(translatedText);
  2037. $(this).addClass("copied").text("Copied");
  2038. // 更新复制按钮文本
  2039. setTimeout(() => {
  2040. $(this).removeClass("copied");
  2041. $(this).text("Copy");
  2042. }, 2000);
  2043. });
  2044. translateDiv.parentNode.insertBefore(wrapperDiv, translateDiv);
  2045.  
  2046. // 转义LaTex中的特殊符号
  2047. const escapeRules = [
  2048. { pattern: /(?<!\\)>(?!\s)/g, replacement: " &gt; " }, // >符号
  2049. { pattern: /(?<!\\)</g, replacement: " &lt; " }, // <符号
  2050. { pattern: /(?<!\\)\*/g, replacement: " &#42; " }, // *符号
  2051. { pattern: /(?<!\\)& /g, replacement: "\\&" }, // &符号
  2052. ];
  2053.  
  2054. let latexMatches = [...translatedText.matchAll(/\$\$([\s\S]*?)\$\$|\$(.*?)\$/g)];
  2055.  
  2056. for (const match of latexMatches) {
  2057. const matchedText = match[0];
  2058.  
  2059. for (const rule of escapeRules) {
  2060. const escapedText = matchedText.replaceAll(rule.pattern, rule.replacement);
  2061. translatedText = translatedText.replace(matchedText, escapedText);
  2062. }
  2063. }
  2064.  
  2065. // 渲染MarkDown
  2066. var md = window.markdownit();
  2067. var html = md.render(translatedText);
  2068. translateDiv.innerHTML = html;
  2069. // 渲染Latex
  2070. if (typeof renderMathInElement === 'function') {
  2071. renderMathInElement(translateDiv, {
  2072. delimiters: [{
  2073. left: "$$",
  2074. right: "$$",
  2075. display: true
  2076. }, {
  2077. left: "$",
  2078. right: "$",
  2079. display: false
  2080. }]
  2081. });
  2082. }
  2083. return {
  2084. translateDiv: translateDiv,
  2085. status: status,
  2086. copyDiv: textElement,
  2087. copyButton: copyButton
  2088. };
  2089.  
  2090. }
  2091.  
  2092. // ChatGPT
  2093. async function translate_openai(raw) {
  2094. var openai_key = GM_getValue("openai_key");
  2095. var openai_retext = "";
  2096. var data = {
  2097. model: openai_model,
  2098. messages: [{
  2099. role: "user",
  2100. content: "(请将下面的文本翻译为中文,这是一道编程竞赛题描述的一部分,注意术语的翻译,注意保持其中的latex公式不翻译,你只需要回复翻译后的内容即可,不要回复任何其他内容:\n\n" + raw + ")"
  2101. }],
  2102. temperature: 0.7
  2103. };
  2104. return new Promise(function (resolve, reject) {
  2105. GM_xmlhttpRequest({
  2106. method: 'POST',
  2107. url: (showOpneAiAdvanced && GM_getValue("openai_proxy") !== null && GM_getValue("openai_proxy") !== "") ? GM_getValue("openai_proxy") : 'https://api.openai.com/v1/chat/completions', // Use the chat endpoint here
  2108.  
  2109. data: JSON.stringify(data),
  2110. headers: {
  2111. 'Content-Type': 'application/json',
  2112. 'Authorization': 'Bearer ' + GM_getValue("openai_key")
  2113. },
  2114. responseType: 'json',
  2115. onload: function (response) {
  2116. if (!response.response) {
  2117. reject("发生了未知的错误,如果你启用了代理API,请确认是否填写正确,并确保代理能够正常工作。\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  2118. }
  2119. else if (!response.response.choices || response.response.choices.length < 1 || !response.response.choices[0].message) {
  2120. resolve("翻译出错,请重试\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈\n\n报错信息:" + JSON.stringify(response.response, null, ''));
  2121. } else {
  2122. openai_retext = response.response.choices[0].message.content;
  2123. resolve(openai_retext);
  2124. }
  2125. },
  2126. onerror: function (response) {
  2127. reject("发生了未知的错误,请确认你是否能正常访问OpenAi的接口,如果使用代理API,请检查是否正常工作\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  2128. },
  2129. });
  2130.  
  2131. });
  2132. }
  2133.  
  2134. // api2d
  2135. async function translate_api2d(raw) {
  2136. var api2d_key = GM_getValue("api2d_key");
  2137. var api2d_retext = "";
  2138. var postData = JSON.stringify({
  2139. model: api2d_model,
  2140. messages: [{ role: 'user', content: '请帮我将下面的文本翻译为中文,这是一道编程竞赛题描述的一部分,注意术语的翻译,注意保持其中的latex公式不翻译,你只需要回复翻译后的内容即可,不要回复任何其他内容:\n\n' + raw }],
  2141. temperature: 0.7
  2142. });
  2143. const options = {
  2144. method: 'POST',
  2145. headers: {
  2146. 'Content-Type': 'application/json',
  2147. 'Authorization': 'Bearer ' + api2d_key,
  2148. ...(x_api2d_no_cache ? {} : { 'x-api2d-no-cache': 1 })
  2149. },
  2150. data: postData,
  2151. };
  2152.  
  2153. return new Promise(function (resolve, reject) {
  2154. GM_xmlhttpRequest({
  2155. method: options.method,
  2156. url: api2d_request_entry + `/v1/chat/completions`,
  2157. headers: options.headers,
  2158. data: options.data,
  2159. responseType: 'json',
  2160. onload: function (response) {
  2161. if (!response.response.choices || response.response.choices.length < 1 || !response.response.choices[0].message) {
  2162. resolve("翻译出错,请重试\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈\n\n报错信息:" + JSON.stringify(response.response, null, '\n'));
  2163. } else {
  2164. api2d_retext = response.response.choices[0].message.content;
  2165. resolve(api2d_retext);
  2166. }
  2167. },
  2168. onerror: function (response) {
  2169. reject("发生了未知的错误,请检查请求入口地址是否正确,能否正常访问\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  2170. },
  2171. });
  2172. });
  2173.  
  2174.  
  2175. }
  2176. //
  2177.  
  2178. //--谷歌翻译--start
  2179. async function translate_gg(raw) {
  2180. return new Promise((resolve, reject) => {
  2181. const url = 'https://translate.google.com/m';
  2182. const params = `tl=zh-CN&q=${encodeURIComponent(raw)}`;
  2183.  
  2184. GM_xmlhttpRequest({
  2185. method: 'GET',
  2186. url: `${url}?${params}`,
  2187. onload: function (response) {
  2188. const html = response.responseText;
  2189. const translatedText = $(html).find('.result-container').text();
  2190. resolve(translatedText);
  2191. },
  2192. onerror: function (error) {
  2193. console.error('Error:', error);
  2194. reject(error);
  2195. }
  2196. });
  2197. });
  2198. }
  2199. //--谷歌翻译--end
  2200.  
  2201. //--有道翻译m--start
  2202. async function translate_youdao_mobile(raw) {
  2203. const options = {
  2204. method: "POST",
  2205. url: 'http://m.youdao.com/translate',
  2206. data: "inputtext=" + encodeURIComponent(raw) + "&type=AUTO",
  2207. anonymous: true,
  2208. headers: {
  2209. "Content-Type": "application/x-www-form-urlencoded",
  2210. 'Host': 'm.youdao.com',
  2211. 'Origin': 'http://m.youdao.com',
  2212. 'Referer': 'http://m.youdao.com/translate',
  2213. }
  2214. }
  2215. return await BaseTranslate('有道翻译mobile', raw, options, res => /id="translateResult">\s*?<li>([\s\S]*?)<\/li>\s*?<\/ul/.exec(res)[1])
  2216. }
  2217. //--有道翻译m--end
  2218.  
  2219. //--Deepl翻译--start
  2220. function getTimeStamp(iCount) {
  2221. const ts = Date.now();
  2222. if (iCount !== 0) {
  2223. iCount = iCount + 1;
  2224. return ts - (ts % iCount) + iCount;
  2225. } else {
  2226. return ts;
  2227. }
  2228. }
  2229.  
  2230. async function translate_deepl(raw) {
  2231. const id = (Math.floor(Math.random() * 99999) + 100000) * 1000;
  2232. const data = {
  2233. jsonrpc: '2.0',
  2234. method: 'LMT_handle_texts',
  2235. id,
  2236. params: {
  2237. splitting: 'newlines',
  2238. lang: {
  2239. source_lang_user_selected: 'auto',
  2240. target_lang: 'ZH',
  2241. },
  2242. texts: [{
  2243. text: raw,
  2244. requestAlternatives: 3
  2245. }],
  2246. timestamp: getTimeStamp(raw.split('i').length - 1)
  2247. }
  2248. }
  2249. let postData = JSON.stringify(data);
  2250. if ((id + 5) % 29 === 0 || (id + 3) % 13 === 0) {
  2251. postData = postData.replace('"method":"', '"method" : "');
  2252. } else {
  2253. postData = postData.replace('"method":"', '"method": "');
  2254. }
  2255. const options = {
  2256. method: 'POST',
  2257. url: 'https://www2.deepl.com/jsonrpc',
  2258. data: postData,
  2259. headers: {
  2260. 'Content-Type': 'application/json',
  2261. 'Host': 'www2.deepl.com',
  2262. 'Origin': 'https://www.deepl.com',
  2263. 'Referer': 'https://www.deepl.com/',
  2264. },
  2265. anonymous: true,
  2266. nocache: true,
  2267. }
  2268. return await BaseTranslate('Deepl翻译', raw, options, res => JSON.parse(res).result.texts[0].text)
  2269. }
  2270.  
  2271. //--Deepl翻译--end
  2272.  
  2273. //--异步请求包装工具--start
  2274. async function PromiseRetryWrap(task, options, ...values) {
  2275. const { RetryTimes, ErrProcesser } = options || {};
  2276. let retryTimes = RetryTimes || 5;
  2277. const usedErrProcesser = ErrProcesser || (err => { throw err });
  2278. if (!task) return;
  2279. while (true) {
  2280. try {
  2281. return await task(...values);
  2282. } catch (err) {
  2283. if (!--retryTimes) {
  2284. console.log(err);
  2285. return usedErrProcesser(err);
  2286. }
  2287. }
  2288. }
  2289. }
  2290.  
  2291. async function BaseTranslate(name, raw, options, processer) {
  2292. let errtext;
  2293. const toDo = async () => {
  2294. var tmp;
  2295. try {
  2296. const data = await Request(options);
  2297. tmp = data.responseText;
  2298. const result = await processer(tmp);
  2299. if (result) sessionStorage.setItem(name + '-' + raw, result);
  2300. return result
  2301. } catch (err) {
  2302. errtext = tmp;
  2303. throw {
  2304. responseText: tmp,
  2305. err: err
  2306. }
  2307. }
  2308. }
  2309. return await PromiseRetryWrap(toDo, { RetryTimes: 3, ErrProcesser: () => "翻译出错,请重试或更换翻译接口\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码报错信息的敏感部分\n\n报错信息:" + errtext })
  2310. }
  2311.  
  2312.  
  2313. function Request(options) {
  2314. return new Promise((reslove, reject) => GM_xmlhttpRequest({ ...options, onload: reslove, onerror: reject }))
  2315. }
  2316.  
  2317. //--异步请求包装工具--end