Atcoder Better!

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

2023-10-08 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Atcoder Better!
  3. // @namespace https://greatest.deepsurf.us/users/747162
  4. // @version 1.12
  5. // @description Atcoder界面汉化、题目翻译、markdown视图、一键复制题目、跳转到洛谷
  6. // @author 北极小狐
  7. // @match https://atcoder.jp/*
  8. // @run-at document-start
  9. // @connect www2.deepl.com
  10. // @connect www.iflyrec.com
  11. // @connect m.youdao.com
  12. // @connect api.interpreter.caiyunai.com
  13. // @connect translate.google.com
  14. // @connect openai.api2d.net
  15. // @connect api.openai.com
  16. // @connect www.luogu.com.cn
  17. // @connect greatest.deepsurf.us
  18. // @connect *
  19. // @grant GM_xmlhttpRequest
  20. // @grant GM_info
  21. // @grant GM_setValue
  22. // @grant GM_getValue
  23. // @grant GM_deleteValue
  24. // @grant GM_addStyle
  25. // @grant GM_setClipboard
  26. // @icon https://aowuucdn.oss-cn-beijing.aliyuncs.com/atcoder.png
  27. // @require https://cdn.staticfile.org/turndown/7.1.2/turndown.min.js
  28. // @require https://cdn.staticfile.org/markdown-it/13.0.1/markdown-it.min.js
  29. // @require https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/crypto-js.min.js
  30. // @license MIT
  31. // @compatible Chrome
  32. // @compatible Firefox
  33. // @compatible Edge
  34. // ==/UserScript==
  35.  
  36. // 状态与初始化
  37. const getGMValue = (key, defaultValue) => {
  38. const value = GM_getValue(key);
  39. if (value === undefined || value === "") {
  40. GM_setValue(key, defaultValue);
  41. return defaultValue;
  42. }
  43. return value;
  44. };
  45.  
  46. var darkMode = getGMValue("darkMode", "follow");
  47. var is_problem, is_homepage;
  48. var bottomZh_CN, showLoading, hoverTargetAreaDisplay, expandFoldingblocks, enableSegmentedTranslation, translation;
  49. var openai_model, openai_key, openai_proxy, openai_header, openai_data, opneaiConfig;
  50. var replaceSymbol, commentPaging, showJumpToLuogu, loaded;
  51. var isEnglishLanguage;
  52. function init() {
  53. const { hostname, href } = window.location;
  54. is_problem = href.includes('/tasks/');
  55. is_homepage = (href === 'https://atcoder.jp/' || href === 'https://atcoder.jp/?lang=ja');
  56. bottomZh_CN = getGMValue("bottomZh_CN", true);
  57. showLoading = getGMValue("showLoading", true);
  58. hoverTargetAreaDisplay = getGMValue("hoverTargetAreaDisplay", false);
  59. expandFoldingblocks = getGMValue("expandFoldingblocks", true);
  60. commentPaging = getGMValue("commentPaging", true);
  61. enableSegmentedTranslation = getGMValue("enableSegmentedTranslation", false);
  62. showJumpToLuogu = getGMValue("showJumpToLuogu", true);
  63. loaded = getGMValue("loaded", false);
  64. translation = getGMValue("translation", "deepl");
  65. replaceSymbol = getGMValue("replaceSymbol", "2");
  66. //openai
  67. opneaiConfig = getGMValue("chatgpt-config", {
  68. "choice": -1,
  69. "configurations": []
  70. });
  71. if (opneaiConfig.choice !== -1 && opneaiConfig.configurations.length !== 0) {
  72. const configAtIndex = opneaiConfig.configurations[opneaiConfig.choice];
  73.  
  74. if (configAtIndex == undefined) {
  75. let existingConfig = GM_getValue('chatgpt-config');
  76. existingConfig.choice = 0;
  77. GM_setValue('chatgpt-config', existingConfig);
  78. location.reload();
  79. }
  80.  
  81. openai_model = configAtIndex.model;
  82. openai_key = configAtIndex.key;
  83. openai_proxy = configAtIndex.proxy;
  84. openai_header = configAtIndex._header ?
  85. configAtIndex._header.split("\n").map(header => {
  86. const [key, value] = header.split(":");
  87. return { [key.trim()]: value.trim() };
  88. }) : [];
  89. openai_data = configAtIndex._data ?
  90. configAtIndex._data.split("\n").map(header => {
  91. const [key, value] = header.split(":");
  92. return { [key.trim()]: value.trim() };
  93. }) : [];
  94. }
  95. }
  96.  
  97. // 常量
  98. 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>';
  99. const unfoldIcon = `<svg t="1695971616104" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2517" width="16" height="16"><path d="M747.451 527.394L512.376 707.028l-235.071-185.71a37.975 37.975 0 0 0-23.927-8.737 38 38 0 0 0-29.248 13.674 37.984 37.984 0 0 0 4.938 53.552l259.003 205.456c14.013 11.523 34.219 11.523 48.231 0l259.003-199.002a37.974 37.974 0 0 0 5.698-53.552 37.982 37.982 0 0 0-53.552-5.315z m0 0" p-id="2518"></path><path d="M488.071 503.845c14.013 11.522 34.219 11.522 48.231 0l259.003-199.003a37.97 37.97 0 0 0 13.983-25.591 37.985 37.985 0 0 0-8.285-27.959 37.97 37.97 0 0 0-25.591-13.979 37.985 37.985 0 0 0-27.96 8.284L512.376 425.61 277.305 239.899a37.974 37.974 0 0 0-23.927-8.736 37.993 37.993 0 0 0-29.248 13.674 37.984 37.984 0 0 0 4.938 53.552l259.003 205.456z m0 0" p-id="2519"></path></svg>`;
  100. const putawayIcon = `<svg t="1695971573189" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2266" width="16" height="16"><path d="M276.549 496.606l235.075-179.634 235.071 185.711a37.975 37.975 0 0 0 23.927 8.737 38 38 0 0 0 29.248-13.674 37.986 37.986 0 0 0-4.938-53.552L535.929 238.737c-14.013-11.523-34.219-11.523-48.231 0L228.695 437.739a37.974 37.974 0 0 0-5.698 53.552 37.982 37.982 0 0 0 53.552 5.315z m0 0" p-id="2267"></path><path d="M535.929 520.155c-14.013-11.522-34.219-11.522-48.231 0L228.695 719.158a37.97 37.97 0 0 0-13.983 25.591 37.985 37.985 0 0 0 8.285 27.959 37.97 37.97 0 0 0 25.591 13.979 37.985 37.985 0 0 0 27.96-8.284L511.624 598.39l235.071 185.711a37.974 37.974 0 0 0 23.927 8.736 37.993 37.993 0 0 0 29.248-13.674 37.984 37.984 0 0 0-4.938-53.552L535.929 520.155z m0 0" p-id="2268"></path></svg>`;
  101. const copyIcon = `<svg t="1695970366492" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2499" width="16" height="16"><path d="M720 192h-544A80.096 80.096 0 0 0 96 272v608C96 924.128 131.904 960 176 960h544c44.128 0 80-35.872 80-80v-608C800 227.904 764.128 192 720 192z m16 688c0 8.8-7.2 16-16 16h-544a16 16 0 0 1-16-16v-608a16 16 0 0 1 16-16h544a16 16 0 0 1 16 16v608z" p-id="2500"></path><path d="M848 64h-544a32 32 0 0 0 0 64h544a16 16 0 0 1 16 16v608a32 32 0 1 0 64 0v-608C928 99.904 892.128 64 848 64z" p-id="2501"></path><path d="M608 360H288a32 32 0 0 0 0 64h320a32 32 0 1 0 0-64zM608 520H288a32 32 0 1 0 0 64h320a32 32 0 1 0 0-64zM480 678.656H288a32 32 0 1 0 0 64h192a32 32 0 1 0 0-64z" p-id="2502"></path></svg>`;
  102. 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: 1100; }`;
  103. 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: 1300; }`;
  104.  
  105. // 切换系统黑暗监听
  106. const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
  107. const changeEventListeners = [];
  108. function handleColorSchemeChange(event) {
  109. const newColorScheme = event.matches ? $('html').attr('data-theme', 'dark') : $('html').attr('data-theme', 'light');
  110. if (!event.matches) {
  111. var originalColor = $(this).data("original-color");
  112. $(this).css("background-color", originalColor);
  113. }
  114. }
  115.  
  116. // 黑暗模式
  117. (function setDark() {
  118. // 初始化
  119. function setDarkTheme() {
  120. const htmlElement = document.querySelector('html');
  121. if (htmlElement) {
  122. htmlElement.setAttribute('data-theme', 'dark');
  123. } else {
  124. setTimeout(setDarkTheme, 100);
  125. }
  126. }
  127. if (darkMode == "dark") {
  128. setDarkTheme();
  129. } else if (darkMode == "follow") {
  130. // 添加事件监听器
  131. changeEventListeners.push(handleColorSchemeChange);
  132. mediaQueryList.addEventListener('change', handleColorSchemeChange);
  133.  
  134. if (window.matchMedia('(prefers-color-scheme: dark)').matches) setDarkTheme();
  135. }
  136.  
  137. GM_addStyle(`
  138. /* 黑暗支持 */
  139. html[data-theme=dark]:root {
  140. color-scheme: light dark;
  141. }
  142. /* 文字颜色1 */
  143. html[data-theme=dark] .float-container>#main-container, html[data-theme=dark] .alert-success, html[data-theme=dark] .alert-info, html[data-theme=dark] .alert-danger,
  144. html[data-theme=dark] .alert-warning, html[data-theme=dark] .panel-default>.panel-heading, html[data-theme=dark] #header a,
  145. html[data-theme=dark] .pagination>li>a, html[data-theme=dark] .pagination>li>span, html[data-theme=dark] .dropdown-menu,
  146. html[data-theme=dark] .select2-container--bootstrap .select2-selection--single .select2-selection__rendered,
  147. html[data-theme=dark] .ace-tm .ace_gutter, html[data-theme=dark] .translate-problem-statement-panel,
  148. html[data-theme=dark] .translate-problem-statement,
  149. html[data-theme=dark] .select2-container--bootstrap .select2-results__option--highlighted[aria-selected],
  150. html[data-theme=dark] .nav-pills>li.active>a, html[data-theme=dark] .user-unrated, html[data-theme=dark] #header .header-page li.is-active a,
  151. html[data-theme=dark] .m-box_inner, html[data-theme=dark] .m-list-job_item, html[data-theme=dark] .a-btn_arrow,
  152. html[data-theme=dark] #header, html[data-theme=dark] #header .header-sub_page li a{
  153. color: #a0adb9 !important;
  154. }
  155. /* 文字颜色2 */
  156. html[data-theme=dark] pre, html[data-theme=dark] .html2mdButton, html[data-theme=dark] .btn-default, html[data-theme=dark] .btn-pre,
  157. html[data-theme=dark] small.contest-duration, html[data-theme=dark] .select2-container--bootstrap .select2-results__option,
  158. html[data-theme=dark] #ace_settingsmenu, #kbshortcutmenu, html[data-theme=dark] code{
  159. color: #9099a3;
  160. }
  161. /* 文字颜色3 */
  162. html[data-theme=dark] input, html[data-theme=dark] #header .header-page li a:hover{
  163. color: #6385a6 !important;
  164. }
  165. /* 文字颜色4 */
  166. html[data-theme=dark] .katex{
  167. color: #cbd6e2 !important;
  168. }
  169. /* 链接颜色 */
  170. html[data-theme=dark] a:link {
  171. color: #a0adb9;
  172. }
  173. html[data-theme=dark] a:visited {
  174. color: #8590a6;
  175. }
  176. /* 按钮 */
  177. html[data-theme=dark] input:hover, html[data-theme=dark] .btn-default:hover{
  178. background-color: #22272e !important;
  179. }
  180. /* 背景层次1 */
  181. html[data-theme=dark] body, html[data-theme=dark] #main-div.float-container, html[data-theme=dark] pre,
  182. html[data-theme=dark] .html2mdButton:hover, html[data-theme=dark] .pagination>.active>a, html[data-theme=dark] .ace-tm,
  183. html[data-theme=dark] .dropdown-menu>li>a:hover, html[data-theme=dark] .dropdown-menu>li>a:focus,
  184. html[data-theme=dark] .dropdown-menu .divider, html[data-theme=dark] .select2-container--bootstrap .select2-selection,
  185. html[data-theme=dark] .ace-tm .ace_gutter-active-line, html[data-theme=dark] .select2-dropdown,
  186. html[data-theme=dark] input, html[data-theme=dark] button, html[data-theme=dark] select, html[data-theme=dark] textarea,
  187. html[data-theme=dark] code, html[data-theme=dark] .AtBetter_setting_menu,
  188. html[data-theme=dark] .AtBetter_setting_sidebar li a.active, html[data-theme=dark] .AtBetter_setting_sidebar li,
  189. html[data-theme=dark] .AtBetter_setting_menu::-webkit-scrollbar-track, html[data-theme=dark] .AtBetter_setting_content::-webkit-scrollbar-track,
  190. html[data-theme=dark] .AtBetter_modal, html[data-theme=dark] .AtBetter_modal button:hover, html[data-theme=dark] #config_bar_list,
  191. html[data-theme=dark] .translate-problem-statement-panel, html[data-theme=dark] .translate-problem-statement,
  192. html[data-theme=dark] #keyvisual .keyvisual-inner:before, html[data-theme=dark] .m-box_inner,
  193. html[data-theme=dark] .m-list-job_item{
  194. background-color: #22272e !important;
  195. }
  196. /* 背景层次2 */
  197. html[data-theme=dark] .float-container>#main-container, html[data-theme=dark] #contest-nav-tabs,
  198. html[data-theme=dark] .btn-default, html[data-theme=dark] .html2mdButton,
  199. html[data-theme=dark] .nav-tabs>li.active>a, html[data-theme=dark] .nav-tabs>li.active>a:hover, html[data-theme=dark] .nav-tabs>li.active>a:focus,
  200. html[data-theme=dark] .nav>li>a:hover, html[data-theme=dark] .nav>li>a:focus, html[data-theme=dark] .panel,
  201. html[data-theme=dark] .table-striped>tbody>tr:nth-of-type(odd), html[data-theme=dark] .insert-participant-box,
  202. html[data-theme=dark] .btn-pre, html[data-theme=dark] .alert-success, html[data-theme=dark] .alert-info, html[data-theme=dark] .alert-danger,
  203. html[data-theme=dark] .alert-warning, html[data-theme=dark] .panel-default>.panel-heading,
  204. html[data-theme=dark] .pagination>li>a, html[data-theme=dark] .pagination>li>span, html[data-theme=dark] .dropdown-menu,
  205. html[data-theme=dark] .ace-tm .ace_gutter, html[data-theme=dark] .select2-container--bootstrap .select2-results__option[aria-selected=true],
  206. html[data-theme=dark] #ace_settingsmenu, #kbshortcutmenu, html[data-theme=dark] .AtBetter_setting_sidebar li,
  207. html[data-theme=dark] .AtBetter_setting_list, html[data-theme=dark] #header .header-inner,
  208. html[data-theme=dark] .AtBetter_setting_menu hr, html[data-theme=dark] .AtBetter_setting_sidebar li a,
  209. html[data-theme=dark] .AtBetter_setting_menu::-webkit-scrollbar-thumb, html[data-theme=dark] .AtBetter_setting_content::-webkit-scrollbar-thumb,
  210. html[data-theme=dark] .AtBetter_modal button, html[data-theme=dark] ul#config_bar_ul::-webkit-scrollbar-thumb,
  211. html[data-theme=dark] .panel-info>.panel-heading, html[data-theme=dark] .post-footer, html[data-theme=dark] .a-btn_arrow:before,
  212. html[data-theme=dark] .table-hover>tbody>tr:hover, html[data-theme=dark] .AtBetter_contextmenu{
  213. background-color: #2d333b !important;
  214. }
  215. /* 实线边框颜色-圆角 */
  216. html[data-theme=dark] input{
  217. border: 1px solid #424b56 !important;
  218. border-radius: 2px;
  219. }
  220. /* 实线边框颜色-无圆角 */
  221. html[data-theme=dark] .btn-default, html[data-theme=dark] .html2mdButton, html[data-theme=dark] .nav-tabs>li>a:hover,
  222. html[data-theme=dark] .nav-tabs>li.active>a, html[data-theme=dark] .nav-tabs>li.active>a:hover,
  223. html[data-theme=dark] .nav-tabs>li.active>a:focus, html[data-theme=dark] .btn-pre, html[data-theme=dark] .btn-pre:hover,
  224. html[data-theme=dark] pre, html[data-theme=dark] .pagination>li>a, html[data-theme=dark] .pagination>li>span,
  225. html[data-theme=dark] .table-bordered>thead>tr>th, html[data-theme=dark] .table-bordered>tbody>tr>th, html[data-theme=dark] .table-bordered>tfoot>tr>th,
  226. html[data-theme=dark] .table-bordered>thead>tr>td, html[data-theme=dark] .table-bordered>tbody>tr>td, html[data-theme=dark] .table-bordered>tfoot>tr>td,
  227. html[data-theme=dark] .panel, html[data-theme=dark] #editor, html[data-theme=dark] .AtBetter_setting_list,
  228. html[data-theme=dark] .AtBetter_setting_sidebar li, html[data-theme=dark] .AtBetter_setting_menu select,
  229. html[data-theme=dark] .AtBetter_modal button, html[data-theme=dark] div#config_bar_list, html[data-theme=dark] label.config_bar_ul_li_text,
  230. html[data-theme=dark] .translate-problem-statement-panel, html[data-theme=dark] .translate-problem-statement,
  231. html[data-theme=dark] .select2-container--bootstrap .select2-selection{
  232. border: 1px solid #424b56 !important;
  233. }
  234. html[data-theme=dark] hr, html[data-theme=dark] .panel-footer,
  235. html[data-theme=dark] .table>thead>tr>th, html[data-theme=dark] .table>tbody>tr>th, html[data-theme=dark] .table>tfoot>tr>th,
  236. html[data-theme=dark] .table>thead>tr>td, html[data-theme=dark] .table>tbody>tr>td, html[data-theme=dark] .table>tfoot>tr>td{
  237. border-top: 1px solid #424b56 !important;
  238. }
  239. html[data-theme=dark] .nav-tabs, html[data-theme=dark] .panel-info>.panel-heading, html[data-theme=dark] .panel-default>.panel-heading,
  240. html[data-theme=dark] .a-btn_arrow{
  241. border-bottom: 1px solid #424b56 !important;
  242. }
  243. html[data-theme=dark] .table>thead>tr>th{
  244. border-bottom: 2px solid #424b56 !important;
  245. }
  246. html[data-theme=dark] .AtBetter_setting_sidebar {
  247. border-right: 1px solid #424b56 !important;
  248. }
  249. /* 双实线边框颜色 */
  250. html[data-theme=dark] #header .header-inner{
  251. border-bottom: 5px double #22272e !important;
  252. }
  253. /* 阴影 */
  254. html[data-theme=dark] .float-container>#main-container{
  255. box-shadow: 0px 0px 10px 5px #fff0;
  256. }
  257. /* 虚线边框颜色 */
  258. html[data-theme=dark] .AtBetter_setting_menu_label_text, html[data-theme=dark] li#add_button{
  259. border: 1px dashed #424b56 !important;
  260. }
  261. /* focus-visible
  262. html[data-theme=dark] {
  263. border-width: 1.5px !important;
  264. outline: none;
  265. }*/
  266. /* 图片-亮度 */
  267. html[data-theme=dark] img{
  268. opacity: .75;
  269. }
  270. /* 反转 */
  271. html[data-theme=dark] .ace_content, html[data-theme=dark] #header .header-logo img{
  272. filter: invert(1) hue-rotate(.5turn);
  273. }
  274. /* 区域遮罩 */
  275. html[data-theme=dark] .overlay {
  276. background: repeating-linear-gradient(135deg, #49525f6e, #49525f6e 30px, #49525f29 0px, #49525f29 55px);
  277. color: #9099a3;
  278. text-shadow: 0px 0px 2px #000000;
  279. }
  280. /* 其他样式 */
  281. html[data-theme=dark] .nav-tabs>li.active>a, html[data-theme=dark] .nav-tabs>li.active>a:hover, html[data-theme=dark] .nav-tabs>li.active>a:focus{
  282. border-bottom-color: transparent !important;
  283. }
  284. html[data-theme=dark] .AtBetter_setting_menu, html[data-theme=dark] .AtBetter_modal{
  285. box-shadow: 0px 0px 0px 4px #2d333b;
  286. border: 1px solid #2d333b;
  287. }
  288. html[data-theme=dark] .collapsible-topic.collapsed .content .collapsible-topic-options:before{
  289. background-image: linear-gradient(#22272e00, #22272e);
  290. }
  291. html[data-theme=dark] .alert{
  292. text-shadow: none;
  293. }
  294. html[data-theme=dark] input[type="radio"]:checked+.AtBetter_setting_menu_label_text {
  295. color: #a0adb9 !important;
  296. border: 1px solid #326154 !important;
  297. }
  298. html[data-theme=dark] .AtBetter_setting_menu .btn-close{
  299. background-color: #ef5350a1 !important;
  300. }
  301. html[data-theme=dark] .m-box-news_post:before{
  302. background: linear-gradient(0deg, #22272e 50%, rgba(255,255,255,0) 100%);
  303. }
  304. html[data-theme=dark] #header .header-sub_page li a:before, html[data-theme=dark] #header .header-page li a:before{
  305. background-color: #9e9e9e !important;
  306. }
  307. `);
  308. })()
  309.  
  310. // 样式
  311. GM_addStyle(`
  312. html {
  313. scroll-behavior: smooth;
  314. }
  315. :root {
  316. --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";
  317. }
  318. span.mdViewContent {
  319. white-space: pre-wrap;
  320. }
  321. /*翻译区域提示*/
  322. .overlay {
  323. pointer-events: none;
  324. position: absolute;
  325. top: 0;
  326. left: 0;
  327. width: 100%;
  328. height: 100%;
  329. background: repeating-linear-gradient(135deg, #97e7cacc, #97e7cacc 30px, #e9fbf1cc 0px, #e9fbf1cc 55px);
  330. border-radius: 5px;
  331. display: flex;
  332. align-items: center;
  333. justify-content: center;
  334. color: #00695C;
  335. font-size: 16px;
  336. font-weight: bold;
  337. text-shadow: 0px 0px 2px #edfcf4;
  338. }
  339. /*翻译div*/
  340. .translate-problem-statement {
  341. justify-items: start;
  342. letter-spacing: 1.8px;
  343. color: #059669;
  344. background-color: #f9f9fa;
  345. border: 1px solid #10b981;
  346. border-radius: 0.3rem;
  347. padding: 5px;
  348. margin: -1px 0px 10px 0px;
  349. width: 100%;
  350. box-sizing: border-box;
  351. font-size: 13px;
  352. }
  353. .translate-problem-statement.error_translate {
  354. color: red;
  355. border-color: red;
  356. }
  357.  
  358. .translate-problem-statement h2, .translate-problem-statement h3 {
  359. font-size: 16px;
  360. }
  361.  
  362. .translate-problem-statement ul {
  363. line-height: 100%;
  364. }
  365.  
  366. .translate-problem-statement a, .translate-problem-statement a:link {
  367. color: #10b981;
  368. font-weight: 600;
  369. background: 0 0;
  370. text-decoration: none;
  371. }
  372. .translate-problem-statement p {
  373. font-size: 14px !important;
  374. }
  375. .translate-problem-statement img {
  376. max-width: 100.0%;
  377. max-height: 100.0%;
  378. }
  379.  
  380. .translate-problem-statement .katex {
  381. font-size: 14px;
  382. }
  383. .translate-problem-statement a:hover {
  384. text-decoration: revert;
  385. }
  386. .translate-problem-statement-panel{
  387. display: flex;
  388. justify-content: space-between;
  389. background-color: #f9f9fa;
  390. border: 1px solid #c5ebdf;
  391. border-radius: 0.3rem;
  392. margin: 4px 0px;
  393. }
  394. .html2md-panel {
  395. display: flex;
  396. justify-content: flex-end;
  397. align-items: center;
  398. }
  399. .html2md-panel a {
  400. text-decoration: none;
  401. }
  402. .html2mdButton {
  403. display: flex;
  404. align-items: center;
  405. cursor: pointer;
  406. background-color: #ffffff;
  407. color: #606266;
  408. height: 22px;
  409. width: auto;
  410. font-size: 13px;
  411. border-radius: 0.3rem;
  412. padding: 1px 5px;
  413. margin: 5px !important;
  414. border: 1px solid #dcdfe6;
  415. }
  416. .html2mdButton:hover {
  417. color: #409eff;
  418. border-color: #409eff;
  419. }
  420. button.html2mdButton.copied {
  421. background-color: #f0f9eb;
  422. color: #67c23e;
  423. border: 1px solid #b3e19d;
  424. }
  425. button.html2mdButton.mdViewed {
  426. background-color: #fdf6ec;
  427. color: #e6a23c;
  428. border: 1px solid #f3d19e;
  429. }
  430. button.html2mdButton.error {
  431. background-color: #fef0f0;
  432. color: #f56c6c;
  433. border: 1px solid #fab6b6;
  434. }
  435. button.translated {
  436. cursor: not-allowed;
  437. background-color: #f0f9eb;
  438. color: #67c23e;
  439. border: 1px solid #b3e19d;
  440. }
  441. button.html2mdButton.reTranslation {
  442. background-color: #f4f4f5;
  443. color: #909399;
  444. border: 1px solid #c8c9cc;
  445. }
  446. .borderlessButton{
  447. display: flex;
  448. align-items: center;
  449. margin: 2.5px 7px;
  450. fill: #9E9E9E;
  451. }
  452. .borderlessButton:hover{
  453. cursor: pointer;
  454. fill: #059669;
  455. }
  456. .translate-problem-statement table {
  457. border: 1px #ccc solid !important;
  458. margin: 1.5em 0 !important;
  459. color: #059669 !important;
  460. }
  461. .translate-problem-statement table thead th {
  462. border: 1px #ccc solid !important;
  463. color: #059669 !important;
  464. }
  465. .translate-problem-statement table td {
  466. border-right: 1px solid #ccc;
  467. border-top: 1px solid #ccc;
  468. padding: 0.7143em 0.5em;
  469. }
  470. .translate-problem-statement table th {
  471. padding: 0.7143em 0.5em;
  472. }
  473. .translate-problem-statement p:not(:first-child) {
  474. margin: 1.5em 0 0;
  475. }
  476. /*设置面板*/
  477. header .enter-or-register-box, header .languages {
  478. position: absolute;
  479. right: 170px;
  480. }
  481. button.html2mdButton.AtBetter_setting {
  482. float: right;
  483. height: 30px;
  484. background: #3c5a7f;
  485. color: white;
  486. margin: 10px !important;
  487. border: 0px;
  488. }
  489.  
  490. button.html2mdButton.AtBetter_setting.open {
  491. background-color: #e6e6e61f;
  492. color: #727378;
  493. cursor: not-allowed;
  494. }
  495. .AtBetter_setting_menu {
  496. z-index: 1200;
  497. box-shadow: 0px 0px 0px 4px #ffffff;
  498. display: grid;
  499. position: fixed;
  500. top: 50%;
  501. left: 50%;
  502. width: 485px;
  503. height: 600px;
  504. transform: translate(-50%, -50%);
  505. border-radius: 6px;
  506. background-color: #f0f4f9;
  507. border-collapse: collapse;
  508. border: 1px solid #ffffff;
  509. color: #697e91;
  510. font-family: var(--vp-font-family-base);
  511. padding: 10px 20px 20px 10px;
  512. box-sizing: content-box;
  513. }
  514. .AtBetter_setting_menu h4,.AtBetter_setting_menu h5 {
  515. font-weight: 600;
  516. margin: 15px 0px 10px 0px;
  517. }
  518. .AtBetter_setting_menu h3 {
  519. margin-top: 10px;
  520. }
  521. .AtBetter_setting_menu hr {
  522. border: none;
  523. height: 1px;
  524. background-color: #ccc;
  525. margin: 10px 0;
  526. }
  527. .AtBetter_setting_menu .badge {
  528. border-radius: 4px;
  529. border: 1px solid #009688;
  530. color: #009688;
  531. font-size: 12px;
  532. padding: 0.5px 4px;
  533. margin-left: 5px;
  534. margin-right: auto;
  535. }
  536. /* 页面切换 */
  537. .settings-page {
  538. display: none;
  539. }
  540. .settings-page.active {
  541. display: block;
  542. }
  543. .AtBetter_setting_container {
  544. display: flex;
  545. }
  546. .AtBetter_setting_sidebar {
  547. width: 120px;
  548. padding: 6px 10px 6px 6px;
  549. margin: 20px 0px;
  550. border-right: 1px solid #d4d8e9;
  551. }
  552. .AtBetter_setting_content {
  553. flex-grow: 1;
  554. width: 350px;
  555. margin: 20px 0px 0px 20px;
  556. padding-right: 10px;
  557. max-height: 580px;
  558. overflow-y: auto;
  559. box-sizing: border-box;
  560. }
  561. .AtBetter_setting_sidebar h3 {
  562. margin-top: 0;
  563. }
  564. .AtBetter_setting_sidebar hr {
  565. margin-top: 10px;
  566. margin-bottom: 10px;
  567. border: none;
  568. border-top: 1px solid #DADCE0;
  569. }
  570. .AtBetter_setting_sidebar ul {
  571. list-style-type: none;
  572. margin: 0;
  573. padding: 0;
  574. }
  575. .AtBetter_setting_sidebar li {
  576. margin: 5px 0px;
  577. background-color: #ffffff;
  578. border: 1px solid #d4d8e9;
  579. border-radius: 4px;
  580. font-size: 16px;
  581. }
  582. .AtBetter_setting_sidebar li a {
  583. text-decoration: none;
  584. display: flex;
  585. width: 100%;
  586. color: gray;
  587. letter-spacing: 2px;
  588. padding: 7px;
  589. border-radius: 4px;
  590. align-items: center;
  591. -webkit-box-sizing: border-box;
  592. -moz-box-sizing: border-box;
  593. box-sizing: border-box;
  594. }
  595. .AtBetter_setting_sidebar li a.active {
  596. background-color: #eceff1c7;
  597. }
  598. /* 下拉选择框 */
  599. .AtBetter_setting_menu select {
  600. margin-left: 6px;
  601. border-style: solid;
  602. border-color: #26A69A;
  603. color: #009688;
  604. font-size: 15px;
  605. }
  606. .AtBetter_setting_menu select:focus-visible {
  607. outline: none;
  608. }
  609. /*设置面板-滚动条*/
  610. .AtBetter_setting_menu::-webkit-scrollbar, .AtBetter_setting_content::-webkit-scrollbar {
  611. width: 5px;
  612. height: 7px;
  613. background-color: #aaa;
  614. }
  615. .AtBetter_setting_menu::-webkit-scrollbar-thumb, .AtBetter_setting_content::-webkit-scrollbar-thumb {
  616. background-clip: padding-box;
  617. background-color: #d7d9e4;
  618. }
  619. .AtBetter_setting_menu::-webkit-scrollbar-track, .AtBetter_setting_content::-webkit-scrollbar-track {
  620. background-color: #f1f1f1;
  621. }
  622. /*设置面板-关闭按钮*/
  623. .AtBetter_setting_menu .tool-box {
  624. position: absolute;
  625. align-items: center;
  626. justify-content: center;
  627. width: 20px;
  628. height: 20px;
  629. overflow: hidden;
  630. border-radius: 10px;
  631. top: 3px;
  632. right: 3px;
  633. }
  634.  
  635. .AtBetter_setting_menu .btn-close {
  636. display: flex;
  637. text-align: center;
  638. width: 20px;
  639. height: 20px;
  640. color: transparent;
  641. font-size: 0;
  642. cursor: pointer;
  643. background-color: #ff000080;
  644. border: none;
  645. margin: 0px;
  646. padding: 0px;
  647. overflow: hidden;
  648. transition: .15s ease all;
  649. align-items: center;
  650. justify-content: center;
  651. box-sizing: border-box;
  652. }
  653.  
  654. .AtBetter_setting_menu .btn-close:hover {
  655. width: 20px;
  656. height: 20px !important;
  657. font-size: 17px;
  658. color: #ffffff;
  659. background-color: #ff0000cc;
  660. box-shadow: 0 5px 5px 0 #00000026;
  661. }
  662.  
  663. .AtBetter_setting_menu .btn-close:active {
  664. width: 20px;
  665. height: 20px;
  666. font-size: 1px;
  667. color: #ffffffde;
  668. --shadow-btn-close: 0 3px 3px 0 #00000026;
  669. box-shadow: var(--shadow-btn-close);
  670. }
  671.  
  672. /*设置面板-checkbox*/
  673. .AtBetter_setting_menu input[type=checkbox]:focus {
  674. outline: 0px;
  675. }
  676.  
  677. .AtBetter_setting_menu input[type="checkbox"] {
  678. margin: 0px;
  679. appearance: none;
  680. -webkit-appearance: none;
  681. width: 40px;
  682. height: 20px !important;
  683. border: 1.5px solid #D7CCC8;
  684. padding: 0px !important;
  685. border-radius: 20px;
  686. background: #efebe978;
  687. position: relative;
  688. box-sizing: border-box;
  689. }
  690.  
  691. .AtBetter_setting_menu input[type="checkbox"]::before {
  692. content: "";
  693. width: 14px;
  694. height: 14px;
  695. background: #D7CCC8;
  696. border: 1.5px solid #BCAAA4;
  697. border-radius: 50%;
  698. position: absolute;
  699. top: 0;
  700. left: 0;
  701. transform: translate(2%, 2%);
  702. transition: all 0.3s ease-in-out;
  703. -webkit-box-sizing: content-box;
  704. -moz-box-sizing: content-box;
  705. box-sizing: content-box;
  706. }
  707.  
  708. .AtBetter_setting_menu input[type="checkbox"]::after {
  709. 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");
  710. position: absolute;
  711. top: 0;
  712. left: 24px;
  713. }
  714.  
  715. .AtBetter_setting_menu input[type="checkbox"]:checked {
  716. border: 1.5px solid #C5CAE9;
  717. background: #E8EAF6;
  718. }
  719.  
  720. .AtBetter_setting_menu input[type="checkbox"]:checked::before {
  721. background: #C5CAE9;
  722. border: 1.5px solid #7986CB;
  723. transform: translate(122%, 2%);
  724. transition: all 0.3s ease-in-out;
  725. }
  726.  
  727. .AtBetter_setting_menu input[type="checkbox"]:checked::after {
  728. 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");
  729. position: absolute;
  730. top: 1.5px;
  731. left: 4.5px;
  732. }
  733.  
  734. .AtBetter_setting_menu label, #darkMode_span, #loaded_span {
  735. font-size: 16px;
  736. font-weight: initial;
  737. }
  738.  
  739. .AtBetter_setting_list {
  740. display: flex;
  741. align-items: center;
  742. padding: 10px;
  743. margin: 5px 0px;
  744. background-color: #ffffff;
  745. border-bottom: 1px solid #c9c6c696;
  746. border-radius: 8px;
  747. justify-content: space-between;
  748. }
  749.  
  750. /*设置面板-radio*/
  751. .AtBetter_setting_menu #translation-settings label {
  752. display: grid;
  753. list-style-type: none;
  754. padding-inline-start: 0px;
  755. overflow-x: auto;
  756. max-width: 100%;
  757. margin: 0px;
  758. align-items: center;
  759. margin: 3px 0px;
  760. }
  761.  
  762. .AtBetter_setting_menu_label_text {
  763. display: flex;
  764. border: 1px dashed #00aeeccc;
  765. height: 35px;
  766. width: 100%;
  767. color: gray;
  768. font-weight: 300;
  769. font-size: 14px;
  770. letter-spacing: 2px;
  771. padding: 7px;
  772. align-items: center;
  773. -webkit-box-sizing: border-box;
  774. -moz-box-sizing: border-box;
  775. box-sizing: border-box;
  776. }
  777.  
  778. input[type="radio"]:checked+.AtBetter_setting_menu_label_text {
  779. background: #41e49930;
  780. border: 1px solid green;
  781. color: green;
  782. font-weight: 500;
  783. }
  784.  
  785. .AtBetter_setting_menu label input[type="radio"], .AtBetter_contextmenu label input[type="radio"]{
  786. appearance: none;
  787. list-style: none;
  788. padding: 0px !important;
  789. margin: 0px;
  790. clip: rect(0 0 0 0);
  791. -webkit-clip-path: inset(100%);
  792. clip-path: inset(100%);
  793. height: 1px;
  794. overflow: hidden;
  795. position: absolute;
  796. white-space: nowrap;
  797. width: 1px;
  798. }
  799.  
  800. .AtBetter_setting_menu input[type="text"] {
  801. display: block;
  802. height: 25px !important;
  803. width: 100%;
  804. background-color: #ffffff;
  805. color: #727378;
  806. font-size: 12px;
  807. border-radius: 0.3rem;
  808. padding: 1px 5px !important;
  809. box-sizing: border-box;
  810. margin: 5px 0px 5px 0px;
  811. border: 1px solid #00aeeccc;
  812. box-shadow: 0 0 1px #0000004d;
  813. }
  814.  
  815. .AtBetter_setting_menu .AtBetter_setting_list input[type="text"] {
  816. margin-left: 5px;
  817. }
  818.  
  819. .AtBetter_setting_menu input[type="text"]:focus-visible{
  820. border-style: solid;
  821. border-color: #3f51b5;
  822. outline: none;
  823. }
  824.  
  825. .AtBetter_setting_menu_input {
  826. width: 100%;
  827. display: grid;
  828. margin-top: 5px;
  829. -webkit-box-sizing: border-box;
  830. -moz-box-sizing: border-box;
  831. box-sizing: border-box;
  832. }
  833. .AtBetter_setting_menu input::placeholder {
  834. color: #727378;
  835. }
  836. .AtBetter_setting_menu input.no_default::placeholder{
  837. color: #BDBDBD;
  838. }
  839. .AtBetter_setting_menu input.is_null::placeholder{
  840. color: red;
  841. border-width: 1.5px;
  842. }
  843. .AtBetter_setting_menu input.is_null{
  844. border-color: red;
  845. }
  846. .AtBetter_setting_menu textarea {
  847. display: block;
  848. width: 100%;
  849. height: 60px;
  850. background-color: #ffffff;
  851. color: #727378;
  852. font-size: 12px;
  853. padding: 1px 5px !important;
  854. box-sizing: border-box;
  855. margin: 5px 0px 5px 0px;
  856. border: 1px solid #00aeeccc;
  857. box-shadow: 0 0 1px #0000004d;
  858. }
  859. .AtBetter_setting_menu textarea:focus-visible{
  860. border-style: solid;
  861. border-color: #3f51b5;
  862. outline: none;
  863. }
  864. .AtBetter_setting_menu textarea::placeholder{
  865. color: #BDBDBD;
  866. font-size: 14px;
  867. }
  868.  
  869. .AtBetter_setting_menu #save {
  870. cursor: pointer;
  871. display: inline-flex;
  872. padding: 5px;
  873. background-color: #1aa06d;
  874. color: #ffffff;
  875. font-size: 14px;
  876. line-height: 1.5rem;
  877. font-weight: 500;
  878. justify-content: center;
  879. width: 100%;
  880. border-radius: 0.375rem;
  881. border: none;
  882. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  883. margin-top: 20px
  884. }
  885. .AtBetter_setting_menu button#debug_button.debug_button {
  886. width: 18%;
  887. }
  888.  
  889. .AtBetter_setting_menu span.tip {
  890. color: #999;
  891. font-size: 12px;
  892. font-weight: 500;
  893. padding: 5px 0px;
  894. }
  895. /*设置面板-tip*/
  896. .help_tip {
  897. margin-right: auto;
  898. }
  899. span.input_label {
  900. font-size: 14px;
  901. }
  902. .help_tip .tip_text {
  903. display: none;
  904. position: absolute;
  905. color: #697e91;
  906. font-weight: 400;
  907. font-size: 14px;
  908. letter-spacing: 0px;
  909. background-color: #ffffff;
  910. padding: 10px;
  911. margin: 5px 0px;
  912. border-radius: 4px;
  913. border: 1px solid #e4e7ed;
  914. box-shadow: 0px 0px 12px rgba(0, 0, 0, .12);
  915. z-index: 1100;
  916. }
  917. .help_tip .tip_text p {
  918. margin-bottom: 5px;
  919. }
  920. .help_tip .tip_text:before {
  921. content: "";
  922. position: absolute;
  923. top: -20px;
  924. right: -10px;
  925. bottom: -10px;
  926. left: -10px;
  927. z-index: -1;
  928. }
  929. .help-icon {
  930. cursor: help;
  931. width: 15px;
  932. color: #b4b9d4;
  933. margin-left: 5px;
  934. margin-top: 3px;
  935. }
  936. .AtBetter_setting_menu .AtBetter_setting_menu_label_text .help_tip .help-icon {
  937. color: #7fbeb2;
  938. }
  939. .help_tip .help-icon:hover + .tip_text, .help_tip .tip_text:hover {
  940. display: block;
  941. cursor: help;
  942. width: 250px;
  943. }
  944.  
  945. /*确认弹窗*/
  946. .AtBetter_modal {
  947. z-index: 1600;
  948. display: grid;
  949. position: fixed;
  950. top: 50%;
  951. left: 50%;
  952. transform: translate(-50%, -50%);
  953. font-size: 12px;
  954. font-family: var(--vp-font-family-base);
  955. padding: 10px 20px;
  956. box-shadow: 0px 0px 0px 4px #ffffff;
  957. border-radius: 6px;
  958. background-color: #f0f4f9;
  959. border-collapse: collapse;
  960. border: 1px solid #ffffff;
  961. color: #697e91;
  962. }
  963. .AtBetter_modal h2 {
  964. font-size: 1.6em;
  965. margin: 0px;
  966. }
  967. .AtBetter_modal .buttons{
  968. display: flex;
  969. padding-top: 15px;
  970. }
  971. .AtBetter_modal button {
  972. display: inline-flex;
  973. justify-content: center;
  974. align-items: center;
  975. line-height: 1;
  976. white-space: nowrap;
  977. cursor: pointer;
  978. text-align: center;
  979. box-sizing: border-box;
  980. outline: none;
  981. transition: .1s;
  982. user-select: none;
  983. vertical-align: middle;
  984. -webkit-appearance: none;
  985. height: 24px;
  986. padding: 5px 11px;
  987. margin-right: 15px;
  988. font-size: 12px;
  989. border-radius: 4px;
  990. color: #ffffff;
  991. background: #009688;
  992. border-color: #009688;
  993. border: none;
  994. }
  995. .AtBetter_modal button#cancelButton{
  996. background-color:#4DB6AC;
  997. }
  998. .AtBetter_modal button:hover{
  999. background-color:#4DB6AC;
  1000. }
  1001. .AtBetter_modal button#cancelButton:hover {
  1002. background-color: #80CBC4;
  1003. }
  1004. .AtBetter_modal .help-icon {
  1005. margin: 0px 8px 0px 0px;
  1006. height: 1em;
  1007. width: 1em;
  1008. line-height: 1em;
  1009. display: inline-flex;
  1010. justify-content: center;
  1011. align-items: center;
  1012. position: relative;
  1013. fill: currentColor;
  1014. font-size: inherit;
  1015. }
  1016. .AtBetter_modal p {
  1017. margin: 5px 0px;
  1018. }
  1019. /*更新检查*/
  1020. div#update_panel {
  1021. z-index: 1200;
  1022. position: fixed;
  1023. top: 50%;
  1024. left: 50%;
  1025. width: 240px;
  1026. transform: translate(-50%, -50%);
  1027. box-shadow: 0px 0px 4px 0px #0000004d;
  1028. padding: 10px 20px 20px 20px;
  1029. color: #444242;
  1030. background-color: #f5f5f5;
  1031. border: 1px solid #848484;
  1032. border-radius: 8px;
  1033. }
  1034. div#update_panel #updating {
  1035. cursor: pointer;
  1036. display: inline-flex;
  1037. padding: 0px;
  1038. background-color: #1aa06d;
  1039. color: #ffffff;
  1040. font-size: 14px;
  1041. line-height: 1.5rem;
  1042. font-weight: 500;
  1043. justify-content: center;
  1044. width: 100%;
  1045. border-radius: 0.375rem;
  1046. border: none;
  1047. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  1048. }
  1049. div#update_panel #updating a {
  1050. text-decoration: none;
  1051. color: white;
  1052. display: flex;
  1053. position: inherit;
  1054. top: 0;
  1055. left: 0;
  1056. width: 100%;
  1057. height: 22px;
  1058. font-size: 14px;
  1059. justify-content: center;
  1060. align-items: center;
  1061. }
  1062. #skip_menu {
  1063. display: flex;
  1064. margin-top: 10px;
  1065. justify-content: flex-end;
  1066. align-items: center;
  1067. }
  1068. #skip_menu .help_tip {
  1069. margin-right: 5px;
  1070. margin-left: -5px;
  1071. }
  1072. #skip_menu .help-icon {
  1073. color: #f44336;
  1074. }
  1075. /* 配置管理 */
  1076. .embed-responsive {
  1077. height: max-content;
  1078. padding-bottom: 0px;
  1079. }
  1080. .config_bar {
  1081. height: 70px;
  1082. width: 100%;
  1083. display: flex;
  1084. justify-content: space-between;
  1085. }
  1086. li#add_button {
  1087. cursor: pointer;
  1088. height: 40px;
  1089. border: 1px dashed #BDBDBD;
  1090. border-radius: 8px;
  1091. background-color: #fcfbfb36;
  1092. color: #bdbdbd;
  1093. font-size: 14px;
  1094. align-items: center;
  1095. justify-content: center;
  1096. }
  1097. li#add_button:hover {
  1098. border: 1px dashed #03A9F4;
  1099. background-color: #d7f0fb8c;
  1100. color: #03A9F4;
  1101. }
  1102. div#config_bar_list {
  1103. display: flex;
  1104. width: 340px;
  1105. border: 1px solid #c5cae9;
  1106. border-radius: 8px;
  1107. background-color: #f0f8ff;
  1108. box-sizing: border-box;
  1109. }
  1110. div#config_bar_list input[type="radio"] {
  1111. appearance: none;
  1112. width: 0;
  1113. height: 0;
  1114. overflow: hidden;
  1115. }
  1116. div#config_bar_list input[type="radio"] {
  1117. margin: 0px;
  1118. }
  1119. div#config_bar_list input[type=radio]:focus {
  1120. outline: 0px;
  1121. }
  1122. label.config_bar_ul_li_text {
  1123. display: flex;
  1124. align-items: center;
  1125. justify-content: center;
  1126. max-width: 100%;
  1127. height: 40px;
  1128. overflow-x: auto;
  1129. font-size: 14px;
  1130. font-weight: 400;
  1131. margin: 0px 4px;
  1132. padding: 3px;
  1133. border: 1px solid #dedede;
  1134. border-radius: 10px;
  1135. box-shadow: 0px 2px 4px 0px rgba(0,0,0,.05);
  1136. box-sizing: border-box;
  1137. }
  1138. ul#config_bar_ul li button {
  1139. background-color: #e6e6e6;
  1140. color: #727378;
  1141. height: 23px;
  1142. font-size: 14px;
  1143. border-radius: 0.3rem;
  1144. padding: 1px 5px;
  1145. margin: 5px;
  1146. border: none;
  1147. box-shadow: 0 0 1px #0000004d;
  1148. }
  1149. ul#config_bar_ul {
  1150. display: flex;
  1151. align-items: center;
  1152. list-style-type: none;
  1153. padding-inline-start: 0px;
  1154. overflow-x: auto;
  1155. max-width: 100%;
  1156. margin: 0px;
  1157. }
  1158. ul#config_bar_ul li {
  1159. width: 80px;
  1160. display: grid;
  1161. margin: 4px 4px;
  1162. min-width: 100px;
  1163. box-sizing: border-box;
  1164. }
  1165. label.config_bar_ul_li_text:hover {
  1166. background-color: #eae4dc24;
  1167. }
  1168. input[type="radio"]:checked + .config_bar_ul_li_text {
  1169. background: #41b3e430;
  1170. border: 1px solid #5e7ce0;
  1171. color: #5e7ce0;
  1172. }
  1173. ul#config_bar_ul::-webkit-scrollbar {
  1174. width: 5px;
  1175. height: 5px;
  1176. }
  1177. ul#config_bar_ul::-webkit-scrollbar-thumb {
  1178. background-clip: padding-box;
  1179. background-color: #d7d9e4;
  1180. border-radius: 8px;
  1181. }
  1182. ul#config_bar_ul::-webkit-scrollbar-button:start:decrement {
  1183. width: 4px;
  1184. background-color: transparent;
  1185. }
  1186. ul#config_bar_ul::-webkit-scrollbar-button:end:increment {
  1187. width: 4px;
  1188. background-color: transparent;
  1189. }
  1190. ul#config_bar_ul::-webkit-scrollbar-track {
  1191. border-radius: 5px;
  1192. }
  1193. label.config_bar_ul_li_text::-webkit-scrollbar {
  1194. width: 5px;
  1195. height: 7px;
  1196. background-color: #aaa;
  1197. }
  1198. label.config_bar_ul_li_text::-webkit-scrollbar-thumb {
  1199. background-clip: padding-box;
  1200. background-color: #d7d9e4;
  1201. }
  1202. label.config_bar_ul_li_text::-webkit-scrollbar-track {
  1203. background-color: #f1f1f1;
  1204. }
  1205. .config_bar_list_add_div {
  1206. display: flex;
  1207. height: 40px;
  1208. margin: 4px 2px;
  1209. }
  1210. /* 修改菜单 */
  1211. div#config_bar_menu {
  1212. z-index: 1300;
  1213. position: absolute;
  1214. width: 60px;
  1215. background: #ffffff;
  1216. box-shadow: 1px 1px 4px 0px #0000004d;
  1217. border: 0px solid rgba(0,0,0,0.04);
  1218. border-radius: 4px;
  1219. padding: 8px 0;
  1220. }
  1221. div.config_bar_menu_item {
  1222. cursor: pointer;
  1223. padding: 2px 6px;
  1224. display: flex;
  1225. justify-content: center;
  1226. align-items: center;
  1227. height: 32px;
  1228. color: rgba(0,0,0,0.75);
  1229. font-size: 14px;
  1230. font-weight: 500;
  1231. box-shadow: inset 0px 0px 0px 0px #8bb2d9;
  1232. }
  1233. div#config_bar_menu_edit:hover {
  1234. background-color: #00aeec;
  1235. color: white;
  1236. }
  1237. div#config_bar_menu_delete:hover {
  1238. background-color: #FF5722;
  1239. color: white;
  1240. }
  1241. /* 配置页面 */
  1242. #config_edit_menu {
  1243. z-index: 1300;
  1244. width: 450px;
  1245. }
  1246. /* 黑暗模式选项 */
  1247. .dark-mode-selection {
  1248. display: flex;
  1249. justify-content: center;
  1250. align-items: center;
  1251. max-width: 350px;
  1252. -webkit-user-select: none;
  1253. -moz-user-select: none;
  1254. -ms-user-select: none;
  1255. user-select: none;
  1256. }
  1257. .dark-mode-selection > * {
  1258. margin: 6px;
  1259. }
  1260. .dark-mode-selection .AtBetter_setting_menu_label_text {
  1261. border-radius: 8px;
  1262. }
  1263. /* 右键菜单 */
  1264. .AtBetter_contextmenu {
  1265. z-index: 1500;
  1266. display: grid;
  1267. position: absolute;
  1268. background-color: #f0f4f9;
  1269. border-collapse: collapse;
  1270. color: #697e91;
  1271. font-family: var(--vp-font-family-base);
  1272. overflow: hidden;
  1273. box-sizing: content-box;
  1274. box-shadow: 0px 0px 0px 2px #eddbdb4d;
  1275. }
  1276. input[type="radio"]:checked+.AtBetter_contextmenu_label_text {
  1277. background: #41e49930;
  1278. border: 1px solid green;
  1279. color: green;
  1280. font-weight: 500;
  1281. }
  1282. .AtBetter_contextmenu label{
  1283. margin: 0px;
  1284. font-weight: initial;
  1285. }
  1286. .AtBetter_contextmenu_label_text {
  1287. display: flex;
  1288. border: 1px dashed #80cbc4;
  1289. height: 26px;
  1290. width: 100%;
  1291. color: gray;
  1292. font-size: 13px;
  1293. padding: 4px;
  1294. align-items: center;
  1295. -webkit-box-sizing: border-box;
  1296. -moz-box-sizing: border-box;
  1297. box-sizing: border-box;
  1298. }
  1299. .AtBetter_contextmenu_label_text:hover {
  1300. color: #F44336;
  1301. border: 1px dashed #009688;
  1302. background-color: #ffebcd;
  1303. }
  1304. /* alert提示 */
  1305. .AtBetter_alert{
  1306. margin: 1em;
  1307. text-align: center;
  1308. font-weight: 600;
  1309. position: relative;
  1310. margin-left: -15px;
  1311. margin-right: -15px;
  1312. }
  1313. `);
  1314.  
  1315. // 获取cookie
  1316. function getCookie(name) {
  1317. const cookies = document.cookie.split(";");
  1318. for (let i = 0; i < cookies.length; i++) {
  1319. const cookie = cookies[i].trim();
  1320. const [cookieName, cookieValue] = cookie.split("=");
  1321.  
  1322. if (cookieName === name) {
  1323. return decodeURIComponent(cookieValue);
  1324. }
  1325. }
  1326. return "";
  1327. }
  1328.  
  1329. // 防抖函数
  1330. function debounce(callback) {
  1331. let timer;
  1332. let immediateExecuted = false;
  1333. const delay = 500;
  1334. return function () {
  1335. clearTimeout(timer);
  1336. if (!immediateExecuted) { callback.call(this); immediateExecuted = true; }
  1337. timer = setTimeout(() => { immediateExecuted = false; }, delay);
  1338. };
  1339. }
  1340.  
  1341. // 为元素添加鼠标拖动
  1342. function addDraggable(element) {
  1343. let isDragging = false;
  1344. let initialX, initialY; // 元素的初始位置
  1345. let startX, startY, offsetX, offsetY; // 鼠标起始位置,移动偏移量
  1346. let isSpecialMouseDown = false; // 选取某些元素时不拖动
  1347.  
  1348. element.on('mousedown', function (e) {
  1349. var elem = $(this);
  1350. var elemOffset = elem.offset();
  1351. var centerX = elemOffset.left + elem.outerWidth() / 2;
  1352. var centerY = elemOffset.top + elem.outerHeight() / 2;
  1353. initialX = centerX - window.pageXOffset;
  1354. initialY = centerY - window.pageYOffset;
  1355.  
  1356. isDragging = true;
  1357. startX = e.clientX;
  1358. startY = e.clientY;
  1359.  
  1360. isSpecialMouseDown = $(e.target).is('label, p, input, textarea, span, select');
  1361.  
  1362. $('body').css('cursor', 'all-scroll');
  1363. });
  1364.  
  1365.  
  1366. $(document).on('mousemove', function (e) {
  1367. if (!isDragging) return;
  1368. // 不执行拖动操作
  1369. if ($(e.target).is('label, p, input, textarea, span') || isSpecialMouseDown && !$(e.target).is('input, textarea')) return;
  1370. e.preventDefault();
  1371. offsetX = e.clientX - startX;
  1372. offsetY = e.clientY - startY;
  1373. element.css({ top: initialY + offsetY + 'px', left: initialX + offsetX + 'px' });
  1374. });
  1375.  
  1376. $(document).on('mouseup', function () {
  1377. isDragging = false;
  1378. isSpecialMouseDown = false;
  1379. $('body').css('cursor', 'default');
  1380. });
  1381. }
  1382.  
  1383.  
  1384.  
  1385. // 更新检查
  1386. function checkScriptVersion() {
  1387. function compareVersions(version1 = "0", version2 = "0") {
  1388. const v1Array = String(version1).split(".");
  1389. const v2Array = String(version2).split(".");
  1390. const minLength = Math.min(v1Array.length, v2Array.length);
  1391. let result = 0;
  1392. for (let i = 0; i < minLength; i++) {
  1393. const curV1 = Number(v1Array[i]);
  1394. const curV2 = Number(v2Array[i]);
  1395. if (curV1 > curV2) {
  1396. result = 1;
  1397. break;
  1398. } else if (curV1 < curV2) {
  1399. result = -1;
  1400. break;
  1401. }
  1402. }
  1403. if (result === 0 && v1Array.length !== v2Array.length) {
  1404. const v1IsBigger = v1Array.length > v2Array.length;
  1405. const maxLenArray = v1IsBigger ? v1Array : v2Array;
  1406. for (let i = minLength; i < maxLenArray.length; i++) {
  1407. const curVersion = Number(maxLenArray[i]);
  1408. if (curVersion > 0) {
  1409. v1IsBigger ? result = 1 : result = -1;
  1410. break;
  1411. }
  1412. }
  1413. }
  1414. return result;
  1415. }
  1416.  
  1417. GM_xmlhttpRequest({
  1418. method: "GET",
  1419. url: "https://greatest.deepsurf.us/zh-CN/scripts/471106.json",
  1420. timeout: 10 * 1e3,
  1421. onload: function (response) {
  1422. const scriptData = JSON.parse(response.responseText);
  1423. const skipUpdate = getCookie("skipUpdate");
  1424.  
  1425. if (
  1426. scriptData.name === GM_info.script.name &&
  1427. compareVersions(scriptData.version, GM_info.script.version) === 1 &&
  1428. skipUpdate !== "true"
  1429. ) {
  1430. const styleElement = GM_addStyle(darkenPageStyle);
  1431. $("body").append(`
  1432. <div id='update_panel'>
  1433. <h3>${GM_info.script.name}有新版本!</h3>
  1434. <hr>
  1435. <div class='update_panel_menu'>
  1436. <span class ='tip'>版本信息:${GM_info.script.version} ${scriptData.version}</span>
  1437. </div>
  1438. <br>
  1439. <div id="skip_menu">
  1440. <div class="help_tip">
  1441. `+ helpCircleHTML + `
  1442. <div class="tip_text">
  1443. <p><b>更新遇到了问题?</b></p>
  1444. <p>由于 Greasyfork 平台的原因,当新版本刚发布时,点击 Greasyfork 上的更新按钮<u>可能</u>会出现<u>实际更新/安装的却是上一个版本</u>的情况</p>
  1445. <p>通常你只需要稍等几分钟,然后再次前往更新/安装即可</p>
  1446. <p>你也可以<u>点击下方按钮,在本次浏览器会话期间将不再提示更新</u></p>
  1447. <button id='skip_update' class='html2mdButton'>暂不更新</button>
  1448. </div>
  1449. </div>
  1450. <button id='updating'><a target="_blank" href="${scriptData.url}">更新</a></button>
  1451. </div>
  1452. </div>
  1453. `);
  1454.  
  1455. $("#skip_update").click(function () {
  1456. document.cookie = "skipUpdate=true; expires=session; path=/";
  1457. styleElement.remove();
  1458. $("#update_panel").remove();
  1459. });
  1460. }
  1461. }
  1462. });
  1463.  
  1464. };
  1465.  
  1466.  
  1467. // 汉化替换
  1468. function toZH_CN() {
  1469. if (!bottomZh_CN) return;
  1470.  
  1471. // 语言判断
  1472. isEnglishLanguage = (function () {
  1473. var metaElement = $('meta[http-equiv="Content-Language"]');
  1474. var contentValue = metaElement.attr('content');
  1475. return (contentValue === 'en');
  1476. })();
  1477.  
  1478. // 文本节点遍历替换
  1479. function traverseTextNodes(node, rules) {
  1480. if (!node) return;
  1481. if (node.nodeType === Node.TEXT_NODE) {
  1482. rules.forEach(rule => {
  1483. const regex = new RegExp(rule.match, 'g');
  1484. node.textContent = node.textContent.replace(regex, rule.replace);
  1485. });
  1486. } else {
  1487. $(node).contents().each((_, child) => traverseTextNodes(child, rules));
  1488. }
  1489. }
  1490.  
  1491. // 严格
  1492. function strictTraverseTextNodes(node, rules) {
  1493. if (!node) return;
  1494. if (node.nodeType === Node.TEXT_NODE) {
  1495. const nodeText = node.textContent.trim();
  1496. rules.forEach(rule => {
  1497. if (nodeText === rule.match) {
  1498. node.textContent = rule.replace;
  1499. }
  1500. });
  1501. } else {
  1502. $(node).contents().each((_, child) => strictTraverseTextNodes(child, rules));
  1503. }
  1504. }
  1505.  
  1506. // 日语汉化
  1507. if (!isEnglishLanguage) {
  1508. const rules1 = [
  1509. { match: 'コンテスト', replace: '比赛' },
  1510. { match: 'Jobs', replace: '工作' },
  1511. { match: '検定', replace: '考试' },
  1512. { match: 'CareerDesign', replace: '职业规划' },
  1513. { match: 'マイプロフィール', replace: '我的个人资料' },
  1514. { match: '基本設定', replace: '基本设置' },
  1515. { match: 'アイコン設定', replace: '头像设置' },
  1516. { match: 'パスワードの変更', replace: '修改密码' },
  1517. { match: 'お気に入り管理', replace: '收藏夹管理' },
  1518. { match: 'ログアウト', replace: '注销' }
  1519. ];
  1520. traverseTextNodes($('.header-inner'), rules1);
  1521.  
  1522. const rules2 = [
  1523. { match: 'コンテスト', replace: '比赛' },
  1524. { match: '最新コンテスト', replace: '最新比赛' },
  1525. { match: 'ランキング', replace: '排名' },
  1526. { match: 'お知らせ', replace: '公告' },
  1527. { match: 'AtCoderJobs', replace: 'AtCoder工作' },
  1528. { match: '検定', replace: '考试' },
  1529. { match: 'アルゴリズム実技検定についてはこちらから!', replace: '有关算法实际技能考试,请点击此处!' },
  1530. { match: '過去問公開中', replace: '过去问题公开中' },
  1531. ];
  1532. traverseTextNodes($('.a-title_ttl'), rules2);
  1533.  
  1534. const rules3 = [
  1535. { match: '詳細を見る', replace: '查看详情' },
  1536. { match: '求人情報を見る', replace: '查看职位信息' },
  1537. { match: '採用担当者の方へ', replace: '致招聘负责人' },
  1538. { match: '詳細ページ', replace: '详细页面' },
  1539. { match: 'マイページ', replace: '我的页面' },
  1540. { match: 'コンテスト一覧', replace: '比赛列表' },
  1541. { match: 'すべて表示', replace: '显示全部' },
  1542. { match: '殿堂入り', replace: '名人堂' },
  1543. { match: 'お知らせ一覧', replace: '公告列表' },
  1544. ];
  1545. traverseTextNodes($('.a-btnarea'), rules3);
  1546.  
  1547. const rules4 = [
  1548. { match: '解けた!を', replace: '解决了!' },
  1549. { match: '世界に届けたい。', replace: '给全世界。' },
  1550. { match: 'AtCoderは、世界最高峰の競技プログラミングサイトです。', replace: 'AtCoder是世界最高水平的竞技编程网站。' },
  1551. { match: 'リアルタイムのオンラインコンテストで競い合うことや、', replace: '您可以参加实时在线比赛,' },
  1552. { match: '5,000以上の過去問にいつでもチャレンジすることができます。', replace: '随时挑战超过5,000道历年题目。' },
  1553. ];
  1554. traverseTextNodes($('.keyvisual-grid'), rules4);
  1555.  
  1556. const rules5 = [
  1557. { match: 'コンテスト', replace: '比赛' },
  1558. { match: '開催中のコンテスト', replace: '进行中的比赛' },
  1559. { match: '常設中のコンテスト', replace: '长期持续的比赛' },
  1560. { match: '予定されたコンテスト', replace: '计划中的比赛' },
  1561. { match: '終了後のコンテスト(最新 10 件)', replace: '已结束的比赛(最新10场)' },
  1562. { match: '終了後のコンテスト(最新 50 件)', replace: '已结束的比赛(最新10场)' },
  1563. { match: 'ランキング', replace: '排名' },
  1564. { match: 'インフォメーション', replace: '信息' },
  1565. { match: '過去のコンテスト', replace: '过去的比赛' },
  1566. { match: '過去のコンテストを検索', replace: '搜索过去的比赛' },
  1567. ];
  1568. strictTraverseTextNodes($('.panel-title'), rules5);
  1569. strictTraverseTextNodes($('h3'), rules5);
  1570. strictTraverseTextNodes($('.h3'), rules5);
  1571. strictTraverseTextNodes($('h4'), rules5);
  1572.  
  1573. const rules6 = [
  1574. { match: 'ホーム', replace: '主页' },
  1575. { match: 'コンテスト一覧', replace: '比赛列表' },
  1576. { match: 'ランキング', replace: '排名' },
  1577. { match: '便利リンク集', replace: '实用链接' },
  1578. ];
  1579. traverseTextNodes($('.header-sub_nav'), rules6);
  1580. traverseTextNodes($('.h3'), rules6);
  1581.  
  1582. const rules7 = [
  1583. { match: '現在のコンテスト', replace: '现在的比赛' },
  1584. { match: '過去のコンテスト', replace: '过去的比赛' },
  1585. { match: 'Algorithm', replace: '算法' },
  1586. { match: 'Heuristic', replace: '启发式' },
  1587. { match: 'アクティブユーザのみ', replace: '仅活跃用户' },
  1588. { match: '全ユーザ', replace: '所有用户' },
  1589. { match: '新エディタテストコンテスト', replace: '新编辑器测试比赛' },
  1590. { match: '日本語', replace: '日语' },
  1591. { match: 'English', replace: '英语' },
  1592. { match: 'bjxh (Guest)', replace: 'bjxh(游客)' },
  1593. { match: 'マイプロフィール', replace: '个人资料' },
  1594. { match: '基本設定', replace: '基本设置' },
  1595. { match: 'アイコン設定', replace: '头像设置' },
  1596. { match: 'パスワードの変更', replace: '修改密码' },
  1597. { match: 'お気に入り管理', replace: '收藏管理' },
  1598. { match: 'ログアウト', replace: '登出' },
  1599. { match: 'トップ', replace: '首页' },
  1600. { match: '問題', replace: '问题' },
  1601. { match: '質問', replace: '提问' },
  1602. { match: '提出', replace: '提交' },
  1603. { match: '提出結果', replace: '提交结果' },
  1604. { match: 'すべての提出', replace: '所有提交' },
  1605. { match: '自分の提出', replace: '我的提交' },
  1606. { match: '自分の得点状況', replace: '我的得分情况' },
  1607. { match: 'バーチャル順位表', replace: '虚拟排名表' },
  1608. { match: '順位表', replace: '排名表' },
  1609. { match: 'チーム戦排名表', replace: '团队比赛排名表' },
  1610. { match: 'コードテスト', replace: '代码测试' },
  1611. { match: '解説', replace: '题解' },
  1612. { match: 'すべての提交', replace: '所有提交' },
  1613. { match: '自分の提交', replace: '我的提交' },
  1614. { match: 'プロフィール', replace: '个人资料' },
  1615. { match: 'コンテスト成績表', replace: '比赛成绩表' },
  1616. { match: '設定', replace: '设置' },
  1617. { match: 'メールアドレスの更新・認証', replace: '更新/认证电子邮件地址' },
  1618. { match: '收藏管理', replace: '收藏管理' },
  1619. { match: 'ユーザ名照会', replace: '用户名查询' },
  1620. { match: 'ユーザ名の変更', replace: '更改用户名' },
  1621. { match: '退会', replace: '注销' },
  1622. { match: 'その他', replace: '其他' },
  1623. ];
  1624. traverseTextNodes($('.nav'), rules7);
  1625.  
  1626. const rules8 = [
  1627. { match: 'Rated対象', replace: '限定范围' },
  1628. { match: 'ABCクラス', replace: 'ABC类别' },
  1629. { match: '(Rated上限: 1999)', replace: '(Rated上限: 1999)' },
  1630. { match: 'ARCクラス', replace: 'ARC类别' },
  1631. { match: '(Rated上限: 2799)', replace: '(Rated上限: 2799)' },
  1632. { match: 'AGCクラス', replace: 'AGC类别' },
  1633. { match: '(Rated上限なし)', replace: '(无Rated上限)' },
  1634. { match: 'AHCクラス', replace: 'AHC类别' },
  1635. { match: 'カテゴリ', replace: '分类' },
  1636. { match: '全て', replace: '全部' },
  1637. { match: 'AtCoder Typical Contest', replace: 'AtCoder经典比赛' },
  1638. { match: 'PAST過去問', replace: 'PAST历年问题' },
  1639. { match: '非公式コンテスト(unrated)', replace: '非官方比赛(未评级)' },
  1640. { match: 'JOI過去問', replace: 'JOI历年问题' },
  1641. { match: '企業コンテスト決勝', replace: '企业比赛决赛' },
  1642. { match: '企業オープンコンテスト(rated)', replace: '企业公开比赛(已评级)' },
  1643. { match: '企業オープンコンテスト(unrated)', replace: '企业公开比赛(未评级)' },
  1644. { match: '企業ABC', replace: '企业ABC' },
  1645. { match: '企業ARC', replace: '企业ARC' },
  1646. { match: 'ヒューリスティック', replace: '启发式' },
  1647. { match: '企業ヒューリスティック', replace: '企业启发式' },
  1648. { match: '検索', replace: '搜索' },
  1649. { match: 'リセット', replace: '重置' },
  1650. { match: 'コンテスト名', replace: '比赛名称' },
  1651. ];
  1652. strictTraverseTextNodes($('#collapse-search'), rules8);
  1653.  
  1654. const rules9 = [
  1655. { match: 'もっと見る', replace: '查看更多' },
  1656. { match: '自分の得点状況', replace: '我的得分情况' },
  1657. { match: '印刷用問題文', replace: '打印问题集' },
  1658. { match: '記事アーカイブ', replace: '文章存档' },
  1659. { match: '詳細', replace: '详情' },
  1660. { match: 'すべて表示', replace: '显示全部' },
  1661. { match: '殿堂入り', replace: '名人堂' },
  1662. ];
  1663. strictTraverseTextNodes($('.btn-text'), rules9);
  1664.  
  1665. const rules10 = [
  1666. { match: 'ホーム', replace: '主页' },
  1667. { match: 'コンテスト一覧', replace: '比赛列表' },
  1668. { match: 'コンテスト', replace: '比赛' },
  1669. { match: 'ランキング', replace: '排名' },
  1670. { match: '便利リンク集', replace: '实用链接' },
  1671. { match: 'AtCoderJobs', replace: 'AtCoder职位' },
  1672. { match: 'AtCoderJobsトップ', replace: 'AtCoder职位首页' },
  1673. { match: '2024年新卒採用求人一覧', replace: '2024年应届毕业生招聘职位列表' },
  1674. { match: '2025年新卒採用求人一覧', replace: '2025年应届毕业生招聘职位列表' },
  1675. { match: '中途採用求人一覧', replace: '社会人招聘职位列表' },
  1676. { match: 'インターン求人一覧', replace: '实习职位列表' },
  1677. { match: 'アルバイト求人一覧', replace: '兼职职位列表' },
  1678. { match: 'その他求人一覧', replace: '其他职位列表' },
  1679. { match: 'AtCoder社による職業紹介求人一覧', replace: '由AtCoder公司提供的职业介绍职位列表' },
  1680. { match: '採用担当者の方へ', replace: '给招聘负责人的信息' },
  1681. { match: '検定', replace: '认证考试' },
  1682. { match: '検定トップ', replace: '认证考试首页' },
  1683. { match: 'マイページ', replace: '个人主页' },
  1684. { match: 'AtCoderCareerDesign', replace: 'AtCoder职业设计' },
  1685. { match: 'キャリアデザイントップ', replace: '职业设计首页' },
  1686. { match: 'About', replace: '关于' },
  1687. { match: '企業情報', replace: '企业信息' },
  1688. { match: 'よくある質問', replace: '常见问题' },
  1689. { match: 'お問い合わせ', replace: '联系我们' },
  1690. { match: '資料請求', replace: '索取资料' },
  1691. { match: '利用規約', replace: '使用规范' },
  1692. { match: 'ルール', replace: '规则' },
  1693. { match: '用語集', replace: '术语表' },
  1694. { match: 'プライバシーポリシー', replace: '隐私政策' },
  1695. { match: '個人情報保護方針', replace: '个人信息保护政策' },
  1696. { match: 'Copyright Since 2012 (C) AtCoder Inc. All rights reserved.', replace: '版权所有 © 2012年起 AtCoder公司。保留所有权利。' },
  1697. ];
  1698. strictTraverseTextNodes($('#footer'), rules10);
  1699. strictTraverseTextNodes($('.footer'), rules10);
  1700.  
  1701. const rules11 = [
  1702. { match: 'ファイルを開く', replace: '打开文件' },
  1703. { match: 'カスタマイズ', replace: '自定义' },
  1704. { match: 'エディタ切り替え', replace: '切换编辑器' },
  1705. { match: '高さ自動調節', replace: '自动调整高度' },
  1706. ];
  1707. traverseTextNodes($('.editor-buttons'), rules11);
  1708.  
  1709. const rules12 = [
  1710. { match: '問題', replace: '问题' },
  1711. { match: '言語', replace: '语言' },
  1712. { match: 'ソースコード', replace: '源代码' },
  1713. { match: '標準入力', replace: '标注输入' },
  1714. { match: '標準出力', replace: '标准输出' },
  1715. { match: '標準エラー出力', replace: '标准错误输出' },
  1716. ];
  1717. traverseTextNodes($('.control-label'), rules12);
  1718.  
  1719. const rules13 = [
  1720. { match: 'トップ', replace: '首页' },
  1721. { match: '問題', replace: '问题' },
  1722. { match: '質問', replace: '提问' },
  1723. { match: '提出', replace: '提交' },
  1724. { match: '提出結果', replace: '提交结果' },
  1725. { match: 'すべての提交', replace: '所有提交' },
  1726. { match: '自分の提交', replace: '我的提交' },
  1727. { match: '自分の得点状況', replace: '我的得分情况' },
  1728. { match: 'バーチャル順位表', replace: '虚拟排名表' },
  1729. { match: '順位表', replace: '排名表' },
  1730. { match: 'コードテスト', replace: '代码测试' },
  1731. { match: '解説', replace: '题解' },
  1732. ];
  1733. traverseTextNodes($('.h2'), rules13);
  1734. traverseTextNodes($('h2'), rules13);
  1735.  
  1736. const rules14 = [
  1737. { match: 'トップ', replace: '首页' },
  1738. { match: '問題', replace: '问题' },
  1739. { match: '質問', replace: '提问' },
  1740. { match: '提出', replace: '提交' },
  1741. { match: '提出結果', replace: '提交结果' },
  1742. { match: 'すべての提交', replace: '所有提交' },
  1743. { match: '自分の提交', replace: '我的提交' },
  1744. { match: '自分の得点状況', replace: '我的得分情况' },
  1745. { match: 'バーチャル順位表', replace: '虚拟排名表' },
  1746. { match: '順位表', replace: '排名表' },
  1747. { match: 'コードテスト', replace: '代码测试' },
  1748. { match: '解説', replace: '题解' },
  1749. ];
  1750. traverseTextNodes($('.panel-heading'), rules14);
  1751.  
  1752. const rules15 = [
  1753. { match: '開催中', replace: '进行中' },
  1754. { match: '予定', replace: '即将举行' },
  1755. { match: '終了', replace: '已结束' },
  1756. ];
  1757. traverseTextNodes($('.status'), rules15);
  1758.  
  1759. const rules16 = [
  1760. { match: 'コンテスト名', replace: '比赛名称' },
  1761. { match: 'Rated対象', replace: '计分对象' },
  1762. { match: '時間', replace: '时长' },
  1763. { match: '開始時刻', replace: '开始时间' },
  1764. ];
  1765. traverseTextNodes($('th.text-center'), rules16);
  1766.  
  1767. const rules17 = [
  1768. { match: 'コンテスト名', replace: '比赛名称' },
  1769. { match: '開始時刻', replace: '开始时间' },
  1770. { match: 'ユーザ', replace: '用户' },
  1771. ];
  1772. traverseTextNodes($('.table-responsive tr th'), rules17);
  1773.  
  1774. const rules19 = [
  1775. { match: '問題名', replace: '问题名称' },
  1776. { match: '実行時間制限', replace: '执行时间限制' },
  1777. { match: 'メモリ制限', replace: '内存限制' },
  1778. ];
  1779. traverseTextNodes($('.table-bordered tr th'), rules19);
  1780.  
  1781. const rules20 = [
  1782. { match: 'ページトップ', replace: '返回顶部' },
  1783. ];
  1784. traverseTextNodes($('#scroll-page-top'), rules20);
  1785.  
  1786. const rules21 = [
  1787. { match: 'AtCoderホームへ戻る', replace: '返回 AtCoder 主页' },
  1788. ];
  1789. traverseTextNodes($('.back-to-home'), rules21);
  1790.  
  1791. const rules22 = [
  1792. { match: '参加登録', replace: '报名' },
  1793. { match: 'バーチャル参加', replace: '虚拟参与' },
  1794. ];
  1795. traverseTextNodes($('.btn'), rules22);
  1796.  
  1797. return;
  1798. }
  1799.  
  1800. // 英语汉化
  1801. const rules1 = [
  1802. { match: 'Present Contests', replace: '目前的比赛' },
  1803. { match: 'Past Contests', replace: '过去的比赛' },
  1804. { match: 'Top', replace: '首页' },
  1805. { match: 'Tasks', replace: '问题集' },
  1806. { match: 'Clarifications', replace: '问题答疑' },
  1807. { match: 'Submit', replace: '提交' },
  1808. { match: 'Results', replace: '结果' },
  1809. { match: 'All Submissions', replace: '所有提交' },
  1810. { match: 'My Submissions', replace: '我的提交' },
  1811. { match: 'My Score', replace: '我的得分' },
  1812. { match: 'Virtual Standings', replace: '虚拟排名' },
  1813. { match: 'Standings', replace: '排名' },
  1814. { match: 'Custom Test', replace: '自定义测试' },
  1815. { match: 'Editorial', replace: '题解' },
  1816. { match: 'Discuss', replace: '讨论' },
  1817. { match: 'Algorithm', replace: '算法' },
  1818. { match: 'Heuristic', replace: '启发式' },
  1819. { match: 'Active Users', replace: '活跃用户' },
  1820. { match: 'All Users', replace: '所有用户' },
  1821. { match: 'Profile', replace: '个人资料' },
  1822. { match: 'Competition History', replace: '比赛记录' },
  1823. { match: 'General Settings', replace: '常规设置' },
  1824. { match: 'Settings', replace: '设置' },
  1825. { match: 'Change/Verify Email address', replace: '更改/验证电子邮件地址' },
  1826. { match: 'Remind Username', replace: '提醒用户名' },
  1827. { match: 'Change Username', replace: '更改用户名' },
  1828. { match: 'Delete Account', replace: '删除账户' },
  1829. { match: 'Change Photo', replace: '更改头像' },
  1830. { match: 'Change Password', replace: '更改密码' },
  1831. { match: 'Manage Fav', replace: '管理收藏' },
  1832. { match: 'Other', replace: '其他' },
  1833. { match: 'Remind Username', replace: '提醒用户名' },
  1834. { match: 'Change Username', replace: '更改用户名' },
  1835. { match: 'Delete Account', replace: '删除账户' }
  1836. ];
  1837. traverseTextNodes($('.nav'), rules1);
  1838.  
  1839. const rules2 = [
  1840. { match: 'My 个人资料', replace: '我的个人资料' },
  1841. { match: 'General Settings', replace: '常规设置' },
  1842. { match: 'Change Photo', replace: '更改照片' },
  1843. { match: 'Change Password', replace: '更改密码' },
  1844. { match: 'Manage Fav', replace: '管理收藏' },
  1845. { match: 'Sign Out', replace: '退出登录' }
  1846. ];
  1847. traverseTextNodes($('.dropdown-menu'), rules2);
  1848.  
  1849. const rules3 = [
  1850. { match: 'Search in Archive', replace: '搜索存档' },
  1851. { match: 'Permanent Contests', replace: '长期持续的比赛' },
  1852. { match: 'Upcoming Contests', replace: '即将举行的比赛' },
  1853. { match: 'Recent Contests', replace: '最近的比赛' },
  1854. { match: 'Ranking', replace: '排行' },
  1855. { match: 'Contest Archive', replace: '比赛档案' },
  1856. { match: 'Information', replace: '信息' },
  1857. { match: 'About the situation where it is difficult to access the contest site', replace: '关于难以访问比赛网站的情况' },
  1858. ];
  1859. traverseTextNodes($('.panel-title'), rules3);
  1860. traverseTextNodes($('.h3'), rules3);
  1861. strictTraverseTextNodes($('h3'), rules3);
  1862.  
  1863. const rules4 = [
  1864. { match: 'Rated Range', replace: '限定范围' },
  1865. { match: 'Category', replace: '类别' },
  1866. { match: 'Search', replace: '搜索' }
  1867. ];
  1868. traverseTextNodes($('.filter-body-heading'), rules4);
  1869.  
  1870. const rules5 = [
  1871. { match: 'Current Password', replace: '当前密码' },
  1872. { match: 'New Password', replace: '新密码' },
  1873. { match: 'Confirm Password', replace: '确认密码' },
  1874. { match: 'Update', replace: '更新' },
  1875. { match: 'Contest Name', replace: '比赛名称' },
  1876. { match: 'Username', replace: '用户名' },
  1877. { match: 'Password', replace: '密码' },
  1878. { match: 'Sign In', replace: '登录' },
  1879. { match: 'Sign Up', replace: '注册' },
  1880. { match: 'Nickname', replace: '昵称' },
  1881. { match: 'Country/Region', replace: '国家/地区' },
  1882. { match: 'Birth Year', replace: '出生年份' },
  1883. { match: 'Affiliation', replace: '机构' },
  1884. { match: 'Email Notifications', replace: '邮件通知' },
  1885. { match: 'New Email address', replace: '新电子邮件地址' },
  1886. { match: 'Request Email address verify', replace: '请求电子邮件地址验证' },
  1887. { match: 'I agree.', replace: '我同意。' },
  1888. { match: 'Do you live in Japan?', replace: '您是否居住在日本?' },
  1889. { match: 'Family Name', replace: '姓氏' },
  1890. { match: 'First Name', replace: '名字' },
  1891. { match: 'Category', replace: '分类' },
  1892. { match: 'College Students (Master or Doctor cource)', replace: '大学生(硕士或博士课程)' },
  1893. { match: 'College Students', replace: '大学生' },
  1894. { match: 'Technical college/Vocational school/Short-term university', replace: '技术学院/职业学校/短期大学' },
  1895. { match: 'High school', replace: '高中' },
  1896. { match: 'Junior high school', replace: '初中' },
  1897. { match: 'Office worker', replace: '上班族' },
  1898. { match: 'Other', replace: '其他' },
  1899. { match: 'Organization Name \\(Company Name or School Name\\)', replace: '组织名称(公司名称或学校名称)' },
  1900. { match: 'Depertment \\(For Students\\)', replace: '部门(适用于学生)' },
  1901. { match: 'Do you have any intention or plan to find a job or change jobs in 2023 or 2024?', replace: '您是否有意向或计划在2023年或2024年找工作或换工作?' },
  1902. { match: 'Graduation Schedule', replace: '毕业时间表' },
  1903. { match: "I'm already employed.", replace: '我已经就业了。' },
  1904. { match: 'Later years', replace: '以后的几年' },
  1905. { match: 'I am interested in going into the digital area of Toyota Motor Corporation\'s operations.', replace: '我对加入丰田汽车公司的数字领域感兴趣。' },
  1906. { match: 'Toyota is currently actively recruiting engineers. Would you like to be considered?', replace: '丰田目前正在积极招聘工程师。您有兴趣被考虑吗?' },
  1907. { match: 'I\'d like to talk to you first.', replace: '我想先和您交谈。' },
  1908. { match: 'Department name', replace: '部门名称' },
  1909. { match: 'What kind of work do you currently do?', replace: '您目前从事什么样的工作?' },
  1910. { match: 'How can the Algorithms Group of the Digital Transformation Office help\\?', replace: '数字转型办公室的算法组可以如何帮助您?' }
  1911. ];
  1912. traverseTextNodes($('.form-group'), rules5);
  1913.  
  1914. const rules6 = [
  1915. { match: 'Unofficial(unrated)', replace: '非官方(无评级)' },
  1916. { match: 'Sponsored Parallel(rated)', replace: '赞助平行(有评级)' },
  1917. { match: 'Sponsored Parallel(unrated)', replace: '赞助平行(无评级)' },
  1918. { match: 'Sponsored Heuristic Contest', replace: '启发式赞助比赛' },
  1919. { match: 'All', replace: '全部' },
  1920. { match: 'AtCoder Typical Contest', replace: 'AtCoder 经典比赛' },
  1921. { match: 'PAST Archive', replace: 'PAST 比赛归档' },
  1922. { match: 'JOI Archive', replace: 'JOI 比赛归档' },
  1923. { match: 'Sponsored Tournament', replace: '赞助比赛' },
  1924. { match: 'Sponsored ABC', replace: '赞助 ABC' },
  1925. { match: 'Sponsored ARC', replace: '赞助 ARC' },
  1926. { match: 'Heuristic Contest', replace: '启发式比赛' }
  1927. ];
  1928. strictTraverseTextNodes($('#category-btn-group'), rules6);
  1929.  
  1930. const rules7 = [
  1931. { match: 'Task', replace: '任务' },
  1932. { match: 'Language', replace: '语言' },
  1933. { match: 'Source Code', replace: '源代码' },
  1934. { match: 'Standard Input', replace: '标准输入' },
  1935. { match: 'Standard Output', replace: '标准输出' },
  1936. { match: 'Standard Error', replace: '标准错误' },
  1937. ];
  1938. traverseTextNodes($('.control-label'), rules7);
  1939.  
  1940. const rules8 = [
  1941. { match: 'Permanent Contests', replace: '永久比赛' },
  1942. { match: 'Upcoming Contests', replace: '即将举行的比赛' },
  1943. { match: 'Recent Contests', replace: '最近的比赛' }
  1944. ];
  1945. traverseTextNodes($('h4'), rules8);
  1946.  
  1947. const rules9 = [
  1948. { match: 'Open File', replace: '打开文件' },
  1949. { match: 'Customize', replace: '个性化' },
  1950. { match: 'Toggle Editor', replace: '切换编辑器' },
  1951. { match: 'Auto Height', replace: '自动调整高度' }
  1952. ];
  1953. traverseTextNodes($('.editor-buttons'), rules9);
  1954.  
  1955. const rules10 = [
  1956. { match: 'Register', replace: '报名' },
  1957. { match: 'Virtual Participation', replace: '虚拟参加' }
  1958. ];
  1959. traverseTextNodes($('.btn'), rules10);
  1960.  
  1961. const rules11 = [
  1962. { match: 'Home', replace: '主页' },
  1963. { match: 'Contest', replace: '比赛' },
  1964. { match: 'Ranking', replace: '排名' },
  1965. { match: 'Sign Up', replace: '注册' },
  1966. { match: 'Sign In', replace: '登录' },
  1967. ];
  1968. strictTraverseTextNodes($('#navbar-collapse'), rules11);
  1969.  
  1970. const rules12 = [
  1971. { match: 'Editorial', replace: '题解' },
  1972. ];
  1973. strictTraverseTextNodes($('.btn'), rules12);
  1974.  
  1975. const rules13 = [
  1976. { match: 'Official', replace: '官方' },
  1977. ];
  1978. strictTraverseTextNodes($('.label'), rules13);
  1979.  
  1980. const rules14 = [
  1981. { match: 'Contest Duration', replace: '比赛时间' },
  1982. { match: 'local time', replace: '当地时间' }
  1983. ];
  1984. traverseTextNodes($('.contest-duration'), rules14);
  1985. };
  1986.  
  1987. // 配置管理函数
  1988. function setupConfigManagement(element, tempConfig, structure, configHTML, checkable) {
  1989. let counter = 0;
  1990. createControlBar();
  1991. createContextMenu();
  1992.  
  1993. // 键值对校验
  1994. function valiKeyValue(value) {
  1995. const keyValuePairs = value.split('\n');
  1996. const regex = /^[a-zA-Z0-9_-]+\s*:\s*[a-zA-Z0-9_-]+$/;
  1997. for (let i = 0; i < keyValuePairs.length; i++) {
  1998. if (!regex.test(keyValuePairs[i])) {
  1999. return false;
  2000. }
  2001. }
  2002. return true;
  2003. }
  2004.  
  2005. // 新增数据
  2006. function onAdd() {
  2007. const styleElement = createWindow();
  2008.  
  2009. const settingMenu = $("#config_edit_menu");
  2010. settingMenu.on("click", "#save", () => {
  2011. const config = {};
  2012. let allFieldsValid = true;
  2013. for (const key in structure) {
  2014. let value = $(key).val();
  2015. if (value || $(key).attr('require') === 'false') {
  2016. config[structure[key]] = $(key).val();
  2017. $(key).removeClass('is_null');
  2018. } else {
  2019. $(key).addClass('is_null');
  2020. allFieldsValid = false;
  2021. }
  2022. }
  2023.  
  2024. // 校验提示
  2025. for (let i = 0, len = checkable.length; i < len; i++) {
  2026. let value = $(checkable[i]).val();
  2027. if (value && !valiKeyValue(value)) {
  2028. if (!$(checkable[i]).prev('span.text-error').length) {
  2029. $(checkable[i]).before('<span class="text-error" style="color: red;">格式不符或存在非法字符</span>');
  2030. }
  2031. allFieldsValid = false;
  2032. } else {
  2033. $(checkable[i]).prev('span.text-error').remove();
  2034. }
  2035. }
  2036.  
  2037. if (!allFieldsValid) return;
  2038. tempConfig.configurations.push(config);
  2039.  
  2040. const list = $("#config_bar_ul");
  2041. createListItemElement(config[structure['#note']]).insertBefore($('#add_button'));
  2042.  
  2043. settingMenu.remove();
  2044. $(styleElement).remove();
  2045. });
  2046.  
  2047. settingMenu.on("click", ".btn-close", () => {
  2048. settingMenu.remove();
  2049. $(styleElement).remove();
  2050. });
  2051. }
  2052.  
  2053. // 编辑数据
  2054. function onEdit() {
  2055. const menu = $("#config_bar_menu");
  2056. menu.css({ display: "none" });
  2057.  
  2058. const list = $("#config_bar_ul");
  2059. const index = Array.from(list.children()).indexOf(this);
  2060.  
  2061. const styleElement = createWindow();
  2062.  
  2063. const settingMenu = $("#config_edit_menu");
  2064. const configAtIndex = tempConfig.configurations[index];
  2065.  
  2066. if (configAtIndex) {
  2067. for (const key in structure) {
  2068. $(key).val(configAtIndex[structure[key]]);
  2069. }
  2070. }
  2071.  
  2072. settingMenu.on("click", "#save", () => {
  2073. const config = {};
  2074. let allFieldsValid = true;
  2075. for (const key in structure) {
  2076. let value = $(key).val();
  2077. if (value || $(key).attr('require') === 'false') {
  2078. config[structure[key]] = $(key).val();
  2079. $(key).removeClass('is_null');
  2080. } else {
  2081. $(key).addClass('is_null');
  2082. allFieldsValid = false;
  2083. }
  2084. }
  2085.  
  2086. // 校验提示
  2087. for (let i = 0, len = checkable.length; i < len; i++) {
  2088. let value = $(checkable[i]).val();
  2089. if (value && !valiKeyValue(value)) {
  2090. if (!$(checkable[i]).prev('span.text-error').length) {
  2091. $(checkable[i]).before('<span class="text-error" style="color: red;">格式不符或存在非法字符</span>');
  2092. }
  2093. allFieldsValid = false;
  2094. } else {
  2095. $(checkable[i]).prev('span.text-error').remove();
  2096. }
  2097. }
  2098.  
  2099. if (!allFieldsValid) return;
  2100. tempConfig.configurations[index] = config;
  2101.  
  2102. settingMenu.remove();
  2103. $(styleElement).remove();
  2104. menu.css({ display: "none" });
  2105.  
  2106. list.children().eq(index).find("label").text(config.note);
  2107. });
  2108.  
  2109. // 关闭按钮
  2110. settingMenu.on("click", ".btn-close", () => {
  2111. settingMenu.remove();
  2112. $(styleElement).remove();
  2113. });
  2114. }
  2115.  
  2116. // 删除数据
  2117. function onDelete() {
  2118. const menu = $("#config_bar_menu");
  2119. menu.css({ display: "none" });
  2120.  
  2121. const list = $("#config_bar_ul");
  2122. const index = Array.from(list.children()).indexOf(this);
  2123.  
  2124. tempConfig.configurations.splice(index, 1);
  2125.  
  2126. list.children().eq(index).remove();
  2127. }
  2128.  
  2129. // 创建编辑窗口
  2130. function createWindow() {
  2131. const styleElement = GM_addStyle(darkenPageStyle2);
  2132. $("body").append(configHTML);
  2133. addDraggable($('#config_edit_menu'));
  2134. return styleElement;
  2135. }
  2136.  
  2137. // 创建控制面板
  2138. function createControlBar() {
  2139. $(element).append(`
  2140. <div id='configControlTip' style='color:red;'></div>
  2141. <div class='config_bar'>
  2142. <div class='config_bar_list' id='config_bar_list'>
  2143. <ul class='config_bar_ul' id='config_bar_ul'></ul>
  2144. </div>
  2145. </div>
  2146. `);
  2147. }
  2148.  
  2149. // 创建右键菜单
  2150. function createContextMenu() {
  2151. const menu = $("<div id='config_bar_menu' style='display: none;'></div>");
  2152. menu.html(`
  2153. <div class='config_bar_menu_item' id='config_bar_menu_edit'>修改</div>
  2154. <div class='config_bar_menu_item' id='config_bar_menu_delete'>删除</div>
  2155. `);
  2156. $("body").append(menu);
  2157. }
  2158.  
  2159. // 创建新的li元素
  2160. function createListItemElement(text) {
  2161. const li = $("<li></li>");
  2162. const radio = $("<input type='radio' name='config_item'></input>").appendTo(li);
  2163. radio.attr("value", counter).attr("id", counter++);
  2164. const label = $("<label class='config_bar_ul_li_text'></label>").text(text).attr("for", radio.attr("value")).appendTo(li);
  2165.  
  2166. // 添加右键菜单
  2167. li.on("contextmenu", function (event) {
  2168. event.preventDefault();
  2169. const menu = $("#config_bar_menu");
  2170. menu.css({ display: "block", left: event.pageX, top: event.pageY });
  2171.  
  2172. const deleteItem = $("#config_bar_menu_delete");
  2173. const editItem = $("#config_bar_menu_edit");
  2174.  
  2175. // 移除旧事件
  2176. deleteItem.off("click");
  2177. editItem.off("click");
  2178.  
  2179. deleteItem.on("click", onDelete.bind(this));
  2180. editItem.on("click", onEdit.bind(this));
  2181.  
  2182. $(document).one("click", (event) => {
  2183. if (!menu.get(0).contains(event.target)) {
  2184. menu.css({ display: "none" });
  2185. deleteItem.off("click", onDelete);
  2186. editItem.off("click", onEdit);
  2187. }
  2188. });
  2189. });
  2190.  
  2191.  
  2192. return li;
  2193. }
  2194.  
  2195. // 渲染列表
  2196. function renderList() {
  2197. const listContainer = $("#config_bar_list");
  2198. const list = $("#config_bar_ul");
  2199. list.empty();
  2200. tempConfig.configurations.forEach((item) => {
  2201. list.append(createListItemElement(item[structure['#note']]));
  2202. });
  2203.  
  2204. list.append(`
  2205. <li id='add_button'>
  2206. <span>+ 添加</span>
  2207. </li>
  2208. `);
  2209. const addItem = $('#add_button');
  2210. addItem.on("click", onAdd);
  2211. };
  2212.  
  2213. renderList();
  2214. return tempConfig;
  2215. }
  2216.  
  2217. const AtBetterSettingMenuHTML = `
  2218. <div class='AtBetter_setting_menu' id='AtBetter_setting_menu'>
  2219. <div class="tool-box">
  2220. <button class="btn-close">×</button>
  2221. </div>
  2222. <div class="AtBetter_setting_container">
  2223. <div class="AtBetter_setting_sidebar">
  2224. <ul>
  2225. <li><a href="#basic-settings" id="sidebar-basic-settings" class="active">基本设置</a></li>
  2226. <li><a href="#translation-settings" id="sidebar-translation-settings">翻译设置</a></li>
  2227. <li><a href="#compatibility-settings" id="sidebar-compatibility-settings">兼容设置</a></li>
  2228. </ul>
  2229. </div>
  2230. <div class="AtBetter_setting_content">
  2231. <div id="basic-settings" class="settings-page active">
  2232. <h3>基本设置</h3>
  2233. <hr>
  2234. <div class='AtBetter_setting_list' style="padding: 0px 10px;">
  2235. <span id="darkMode_span">黑暗模式</span>
  2236. <div class="dark-mode-selection">
  2237. <label>
  2238. <input class="radio-input" type="radio" name="darkMode" value="dark" />
  2239. <span class="AtBetter_setting_menu_label_text">黑暗</span>
  2240. <span class="radio-icon"> </span>
  2241. </label>
  2242. <label>
  2243. <input checked="" class="radio-input" type="radio" name="darkMode" value="light" />
  2244. <span class="AtBetter_setting_menu_label_text">白天</span>
  2245. <span class="radio-icon"> </span>
  2246. </label>
  2247. <label>
  2248. <input class="radio-input" type="radio" name="darkMode" value="follow" />
  2249. <span class="AtBetter_setting_menu_label_text">跟随系统</span>
  2250. <span class="radio-icon"> </span>
  2251. </label>
  2252. </div>
  2253. </div>
  2254. <div class='AtBetter_setting_list'>
  2255. <label for="bottomZh_CN">界面汉化</label>
  2256. <input type="checkbox" id="bottomZh_CN" name="bottomZh_CN">
  2257. </div>
  2258. <div class='AtBetter_setting_list'>
  2259. <label for="showLoading">显示加载信息</label>
  2260. <div class="help_tip">
  2261. `+ helpCircleHTML + `
  2262. <div class="tip_text">
  2263. <p>当你开启 显示加载信息 时,每次加载页面时会在上方显示加载信息提示:“Atcoder Better! —— xxx”</p>
  2264. <p>这用于了解脚本当前的工作情况,<strong>如果你不想看到,可以选择关闭</strong></p>
  2265. <p><u>需要说明的是,如果你需要反馈脚本的任何加载问题,请开启该选项后再截图,以便于分析问题</u></p>
  2266. </div>
  2267. </div>
  2268. <input type="checkbox" id="showLoading" name="showLoading">
  2269. </div>
  2270. <div class='AtBetter_setting_list'>
  2271. <label for="hoverTargetAreaDisplay">显示目标区域范围</label>
  2272. <div class="help_tip">
  2273. `+ helpCircleHTML + `
  2274. <div class="tip_text">
  2275. <p>开启后当鼠标悬浮在 MD视图/复制/翻译 按钮上时,会显示其目标区域的范围</p>
  2276. </div>
  2277. </div>
  2278. <input type="checkbox" id="hoverTargetAreaDisplay" name="hoverTargetAreaDisplay">
  2279. </div>
  2280. <div class='AtBetter_setting_list'>
  2281. <label for="showJumpToLuogu">显示跳转到洛谷</label>
  2282. <div class="help_tip">
  2283. `+ helpCircleHTML + `
  2284. <div class="tip_text">
  2285. <p>洛谷OJ上收录了Atcoder的部分题目,一些题目有翻译和题解</p>
  2286. <p>开启显示后,如果当前题目被收录,则会在题目的右上角显示洛谷标志,</p>
  2287. <p>点击即可一键跳转到该题洛谷的对应页面。</strong></p>
  2288. </div>
  2289. </div>
  2290. <input type="checkbox" id="showJumpToLuogu" name="showJumpToLuogu">
  2291. </div>
  2292. </div>
  2293. <div id="translation-settings" class="settings-page">
  2294. <h3>翻译设置</h3>
  2295. <hr>
  2296. <h4>首选项</h4>
  2297. <label>
  2298. <input type='radio' name='translation' value='deepl'>
  2299. <span class='AtBetter_setting_menu_label_text'>deepl翻译</span>
  2300. </label>
  2301. <label>
  2302. <input type='radio' name='translation' value='iflyrec'>
  2303. <span class='AtBetter_setting_menu_label_text'>讯飞听见翻译</span>
  2304. </label>
  2305. <label>
  2306. <input type='radio' name='translation' value='youdao'>
  2307. <span class='AtBetter_setting_menu_label_text'>有道翻译</span>
  2308. </label>
  2309. <label>
  2310. <input type='radio' name='translation' value='google'>
  2311. <span class='AtBetter_setting_menu_label_text'>Google翻译</span>
  2312. </label>
  2313. <label>
  2314. <input type='radio' name='translation' value='caiyun'>
  2315. <span class='AtBetter_setting_menu_label_text'>彩云小译翻译</span>
  2316. </label>
  2317. <label>
  2318. <input type='radio' name='translation' value='openai'>
  2319. <span class='AtBetter_setting_menu_label_text'>使用ChatGPT翻译(API)
  2320. <div class="help_tip">
  2321. `+ helpCircleHTML + `
  2322. <div class="tip_text">
  2323. <p><b>请在下方选定你想使用的配置信息</b></p>
  2324. <p>脚本的所有请求均在本地完成</p>
  2325. </div>
  2326. </div>
  2327. </span>
  2328. </label>
  2329. <div class='AtBetter_setting_menu_input' id='openai' style='display: none;'>
  2330. <div id="chatgpt-config"></div>
  2331. </div>
  2332. <h4>高级</h4>
  2333. <div class='AtBetter_setting_list'>
  2334. <label for="enableSegmentedTranslation">分段翻译</label>
  2335. <div class="help_tip">
  2336. `+ helpCircleHTML + `
  2337. <div class="tip_text">
  2338. <p>分段翻译会对区域内的每一个&#60;&#112;&#47;&#62;和&#60;&#105;&#47;&#62;标签依次进行翻译,</p>
  2339. <p>这通常在翻译<strong>长篇博客</strong>或者<strong>超长的题目</strong>时很有用。</p>
  2340. <p><u>注意:开启分段翻译会产生如下问题:</u></p>
  2341. <p>- 使得翻译接口无法知晓整个文本的上下文信息,会降低翻译质量。</p>
  2342. <p>- 会有<strong>部分内容不会被翻译</strong>,因为它们不是&#60;&#112;&#47;&#62;或&#60;&#105;&#47;&#62;标签</p>
  2343. </div>
  2344. </div>
  2345. <input type="checkbox" id="enableSegmentedTranslation" name="enableSegmentedTranslation">
  2346. </div>
  2347. <div class='AtBetter_setting_list'>
  2348. <label for="translation_replaceSymbol" style="display: flex;">LaTeX替换符</label>
  2349. <div class="help_tip">
  2350. `+ helpCircleHTML + `
  2351. <div class="tip_text">
  2352. <p>脚本通过先取出所有的LaTeX公式,并使用替换符占位,来保证公式不会被翻译接口所破坏</p>
  2353. <p>对于各个翻译服务,不同的替换符本身遭到破坏的概率有所不同,具体请阅读脚本页的说明</p>
  2354. <p>注意:使用ChatGPT翻译时不需要上述操作, 因此不受此选项影响</p>
  2355. <p>具体您可以前往阅读脚本页的说明</p>
  2356. </div>
  2357. </div>
  2358. <select id="translation_replaceSymbol" name="translation_replaceSymbol">
  2359. <option value=2>使用{}</option>
  2360. <option value=1>使用【】</option>
  2361. <option value=3>使用[]</option>
  2362. </select>
  2363. </div>
  2364. </div>
  2365. <div id="compatibility-settings" class="settings-page">
  2366. <h3>兼容设置</h3>
  2367. <hr>
  2368. <div class='AtBetter_setting_list'>
  2369. <label for="loaded"><span id="loaded_span">不等待页面资源加载</span></label>
  2370. <div class="help_tip">
  2371. `+ helpCircleHTML + `
  2372. <div class="tip_text">
  2373. <p>为了防止在页面资源未加载完成前(主要是各种js)执行脚本产生意外的错误,脚本默认会等待 window.onload 事件</p>
  2374. <p>如果您的页面上方的加载信息始终停留在:“等待页面资源加载”,即使页面已经完成加载</p>
  2375. <p><u>您首先应该确认是否是网络问题,</u></p>
  2376. <p>如果不是,那这可能是由于 window.onload 事件在您的浏览器中触发过早(早于DOMContentLoaded),</p>
  2377. <p>您可以尝试开启该选项来不再等待 window.onload 事件</p>
  2378. <p><u>注意:如果没有上述问题,请不要开启该选项</u></p>
  2379. </div>
  2380. </div>
  2381. <input type="checkbox" id="loaded" name="loaded">
  2382. </div>
  2383. </div>
  2384. </div>
  2385. `;
  2386.  
  2387. const chatgptConfigEditHTML = `
  2388. <div class='AtBetter_setting_menu' id='config_edit_menu'>
  2389. <div class="tool-box">
  2390. <button class="btn-close">×</button>
  2391. </div>
  2392. <h4>配置</h4>
  2393. <h5>基本</h5>
  2394. <hr>
  2395. <label for='note'>
  2396. <span class="input_label">备注:</span>
  2397. </label>
  2398. <input type='text' id='note' class='no_default' placeholder='请为该配置取一个备注名' require = true>
  2399. <label for='openai_model'>
  2400. <div style="display: flex;align-items: center;">
  2401. <span class="input_label">模型:</span>
  2402. <div class="help_tip">
  2403. `+ helpCircleHTML + `
  2404. <div class="tip_text">
  2405. <p>留空则默认为:gpt-3.5-turbo</p>
  2406. <p>模型列表请查阅<a target="_blank" href="https://platform.openai.com/docs/models">OpenAI官方文档</a></p>
  2407. <p><strong>此外,如果您使用的是服务商提供的代理API,请确认服务商是否支持对应模型</strong></p>
  2408. </div>
  2409. </div>
  2410. </div>
  2411. </label>
  2412. <input type='text' id='openai_model' placeholder='gpt-3.5-turbo' require = false>
  2413. <label for='openai_key'>
  2414. <div style="display: flex;align-items: center;">
  2415. <span class="input_label">KEY:</span>
  2416. <div class="help_tip">
  2417. `+ helpCircleHTML + `
  2418. <div class="tip_text">
  2419. <p>您需要输入自己的OpenAI key,<a target="_blank" href="https://platform.openai.com/account/usage">官网</a></p>
  2420. <p><b>如果您使用的是服务商提供的代理API,则应该填写服务商提供的 Key</b></p>
  2421. </div>
  2422. </div>
  2423. </div>
  2424. </label>
  2425. <input type='text' id='openai_key' class='no_default' placeholder='请输入KEY' require = true>
  2426. <label for='openai_proxy'>
  2427. <div style="display: flex;align-items: center;">
  2428. <span class="input_label">Proxy API:</span>
  2429. <div class="help_tip">
  2430. `+ helpCircleHTML + `
  2431. <div class="tip_text">
  2432. <p>留空则默认为OpenAI官方API</p>
  2433. <p>您也可以填写指定的API来代理访问OpenAIAPI,</p>
  2434. <p>如果您使用的是服务商提供的代理APIKEY,则这里应该填写其提供的<strong>完整</strong>API地址,详请阅读脚本说明</p>
  2435. <p><strong>由于您指定了自定义的APITampermonkey会对您的跨域请求进行警告,您需要自行授权</strong></p>
  2436. </div>
  2437. </div>
  2438. </div>
  2439. </label>
  2440. <input type='text' id='openai_proxy' placeholder='https://api.openai.com/v1/chat/completions' require = false>
  2441. <h5>高级</h5>
  2442. <hr>
  2443. <label for='_header'>
  2444. <div style="display: flex;align-items: center;">
  2445. <span class="input_label">自定义header</span>
  2446. <div class="help_tip">
  2447. `+ helpCircleHTML + `
  2448. <div class="tip_text">
  2449. <p>格式样例:</p>
  2450. <div style="border: 1px solid #795548; padding: 10px;">
  2451. <p>name1 : 123<br>name2 : cccc</p>
  2452. </div>
  2453. </div>
  2454. </div>
  2455. </div>
  2456. </label>
  2457. <textarea id="_header" placeholder='(选填)您可以在这里填写向请求header中额外添加的键值对' require = false></textarea>
  2458. <label for='_data'>
  2459. <div style="display: flex;align-items: center;">
  2460. <span class="input_label">自定义data</span>
  2461. <div class="help_tip">
  2462. `+ helpCircleHTML + `
  2463. <div class="tip_text">
  2464. <p>格式样例:</p>
  2465. <div style="border: 1px solid #795548; padding: 10px;">
  2466. <p>name1 : 123<br>name2 : cccc</p>
  2467. </div>
  2468. </div>
  2469. </div>
  2470. </div>
  2471. </label>
  2472. <textarea id="_data" placeholder='(选填)您可以在这里填写向请求data中额外添加的键值对' require = false></textarea>
  2473. <button id='save'>保存</button>
  2474. </div>
  2475. `;
  2476.  
  2477. // 配置改变保存确认
  2478. function saveConfirmation() {
  2479. return new Promise(resolve => {
  2480. const styleElement = GM_addStyle(darkenPageStyle2);
  2481. let htmlString = `
  2482. <div class="AtBetter_modal">
  2483. <h2>配置已更改,是否保存?</h2>
  2484. <div class="buttons">
  2485. <button id="cancelButton">不保存</button><button id="saveButton">保存</button>
  2486. </div>
  2487. </div>
  2488. `;
  2489. $('body').before(htmlString);
  2490. addDraggable($('.AtBetter_modal'));
  2491. $("#saveButton").click(function () {
  2492. $(styleElement).remove();
  2493. $('.AtBetter_modal').remove();
  2494. resolve(true);
  2495. });
  2496. $("#cancelButton").click(function () {
  2497. $(styleElement).remove();
  2498. $('.AtBetter_modal').remove();
  2499. resolve(false);
  2500. });
  2501. });
  2502. }
  2503.  
  2504. // 设置按钮面板
  2505. async function settingPanel() {
  2506. // 添加按钮
  2507. var htmlContent = "<button class='html2mdButton AtBetter_setting'>AtcoderBetter设置</button>";
  2508. if (isEnglishLanguage) {
  2509. $('#navbar-collapse > ul:nth-child(2) > li:last-child').after("<li class='dropdown'>" + htmlContent + "</li>");
  2510. } else {
  2511. if ($('.header-mypage').length > 0) $('.header-mypage').after(htmlContent);
  2512. else $('#navbar-collapse > ul:nth-child(2) > li:last-child').after("<li class='dropdown'>" + htmlContent + "</li>");
  2513. }
  2514. const $settingBtns = $(".AtBetter_setting");
  2515. $settingBtns.click(() => {
  2516. const styleElement = GM_addStyle(darkenPageStyle);
  2517. $settingBtns.prop("disabled", true).addClass("open");
  2518. $("body").append(AtBetterSettingMenuHTML);
  2519.  
  2520. // 窗口初始化
  2521. addDraggable($('#AtBetter_setting_menu'));
  2522.  
  2523. // 选项卡切换
  2524. $('.AtBetter_setting_sidebar a').click(function (event) {
  2525. event.preventDefault();
  2526. $('.AtBetter_setting_sidebar a').removeClass('active');
  2527. $(this).addClass('active');
  2528. $('.settings-page').removeClass('active');
  2529. const targetPageId = $(this).attr('href').substring(1);
  2530. $('#' + targetPageId).addClass('active');
  2531. });
  2532.  
  2533. const chatgptStructure = {
  2534. '#note': 'note',
  2535. '#openai_model': 'model',
  2536. '#openai_key': 'key',
  2537. '#openai_proxy': 'proxy',
  2538. '#_header': '_header',
  2539. '#_data': '_data',
  2540. }
  2541. const checkable = [
  2542. '#_header',
  2543. '#_data',
  2544. ]
  2545.  
  2546. let tempConfig = GM_getValue('chatgpt-config'); // 缓存配置信息
  2547. tempConfig = setupConfigManagement('#chatgpt-config', tempConfig, chatgptStructure, chatgptConfigEditHTML, checkable);
  2548.  
  2549. // 状态更新
  2550. $("#bottomZh_CN").prop("checked", GM_getValue("bottomZh_CN") === true);
  2551. $("input[name='darkMode'][value='" + darkMode + "']").prop("checked", true);
  2552. $("#showLoading").prop("checked", GM_getValue("showLoading") === true);
  2553. $("#enableSegmentedTranslation").prop("checked", GM_getValue("enableSegmentedTranslation") === true);
  2554. $("#showJumpToLuogu").prop("checked", GM_getValue("showJumpToLuogu") === true);
  2555. $("#loaded").prop("checked", GM_getValue("loaded") === true);
  2556. $("#hoverTargetAreaDisplay").prop("checked", GM_getValue("hoverTargetAreaDisplay") === true);
  2557. $("input[name='translation'][value='" + translation + "']").prop("checked", true);
  2558. $("input[name='translation']").css("color", "gray");
  2559. if (translation == "openai") {
  2560. $("#openai").show();
  2561. if (tempConfig) {
  2562. $("input[name='config_item'][value='" + tempConfig.choice + "']").prop("checked", true);
  2563. }
  2564. }
  2565. $('#translation_replaceSymbol').val(GM_getValue("replaceSymbol"));
  2566.  
  2567. // 翻译选择情况监听
  2568. $("input[name='translation']").change(function () {
  2569. var selected = $(this).val(); // 获取当前选中的值
  2570. if (selected === "openai") {
  2571. $("#openai").show();
  2572. if (tempConfig) {
  2573. $("input[name='config_item'][value='" + tempConfig.choice + "']").prop("checked", true);
  2574. }
  2575. } else {
  2576. $("#openai").hide();
  2577. }
  2578. });
  2579.  
  2580. // 配置选择情况监听
  2581. $("input[name='config_item']").change(function () {
  2582. var selected = $(this).val(); // 获取当前选中的值
  2583. tempConfig.choice = selected;
  2584. });
  2585.  
  2586. // 关闭
  2587. const $settingMenu = $(".AtBetter_setting_menu");
  2588. $settingMenu.on("click", ".btn-close", async () => {
  2589. const settings = {
  2590. bottomZh_CN: $("#bottomZh_CN").prop("checked"),
  2591. darkMode: $("input[name='darkMode']:checked").val(),
  2592. showLoading: $("#showLoading").prop("checked"),
  2593. hoverTargetAreaDisplay: $("#hoverTargetAreaDisplay").prop("checked"),
  2594. enableSegmentedTranslation: $("#enableSegmentedTranslation").prop("checked"),
  2595. showJumpToLuogu: $("#showJumpToLuogu").prop("checked"),
  2596. loaded: $("#loaded").prop("checked"),
  2597. translation: $("input[name='translation']:checked").val(),
  2598. replaceSymbol: $('#translation_replaceSymbol').val()
  2599. };
  2600. // 判断是否改变
  2601. let hasChange = false;
  2602. for (const [key, value] of Object.entries(settings)) {
  2603. if (!hasChange && GM_getValue(key) != value) hasChange = true;
  2604. }
  2605. if (!hasChange && JSON.stringify(GM_getValue('chatgpt-config')) != JSON.stringify(tempConfig)) hasChange = true;
  2606.  
  2607. if (hasChange) {
  2608. const shouldSave = await saveConfirmation();
  2609. if (shouldSave) {
  2610. // 数据校验
  2611. if (settings.translation === "openai") {
  2612. var selectedIndex = $('input[name="config_item"]:checked').closest('li').index();
  2613. if (selectedIndex === -1) {
  2614. $('#configControlTip').text('请选择一项配置!');
  2615. $('.AtBetter_setting_sidebar a').removeClass('active');
  2616. $('#sidebar-translation-settings').addClass('active');
  2617. $('.settings-page').removeClass('active');
  2618. $('#translation-settings').addClass('active');
  2619. return;
  2620. }
  2621. }
  2622.  
  2623. // 保存数据
  2624. let refreshPage = false; // 是否需要刷新页面
  2625. for (const [key, value] of Object.entries(settings)) {
  2626. if (!refreshPage && !(key == 'enableSegmentedTranslation' || key == 'translation' || key == 'darkMode' ||
  2627. key == 'replaceSymbol')) {
  2628. if (GM_getValue(key) != value) refreshPage = true;
  2629. }
  2630. GM_setValue(key, value);
  2631. }
  2632. GM_setValue('chatgpt-config', tempConfig);
  2633.  
  2634. if (refreshPage) location.reload();
  2635. else {
  2636. // 切换黑暗模式
  2637. if (darkMode != settings.darkMode) {
  2638. darkMode = settings.darkMode;
  2639. // 移除旧的事件监听器
  2640. changeEventListeners.forEach(listener => {
  2641. mediaQueryList.removeEventListener('change', listener);
  2642. });
  2643.  
  2644. if (darkMode == "follow") {
  2645. changeEventListeners.push(handleColorSchemeChange);
  2646. mediaQueryList.addEventListener('change', handleColorSchemeChange);
  2647. $('html').removeAttr('data-theme');
  2648. } else if (darkMode == "dark") {
  2649. $('html').attr('data-theme', 'dark');
  2650. } else {
  2651. $('html').attr('data-theme', 'light');
  2652. // 移除旧的事件监听器
  2653. const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
  2654. window.matchMedia('(prefers-color-scheme: dark)');
  2655. }
  2656. }
  2657. // 更新配置信息
  2658. enableSegmentedTranslation = settings.enableSegmentedTranslation;
  2659. translation = settings.translation;
  2660. replaceSymbol = settings.replaceSymbol;
  2661. commentTranslationChoice = settings.commentTranslationChoice;
  2662. if (settings.translation === "openai") {
  2663. var selectedIndex = $('#config_bar_ul li input[type="radio"]:checked').closest('li').index();
  2664. if (selectedIndex !== opneaiConfig.choice) {
  2665. opneaiConfig = GM_getValue("chatgpt-config");
  2666. const configAtIndex = opneaiConfig.configurations[selectedIndex];
  2667. openai_model = configAtIndex.model;
  2668. openai_key = configAtIndex.key;
  2669. openai_proxy = configAtIndex.proxy;
  2670. openai_header = configAtIndex._header ?
  2671. configAtIndex._header.split("\n").map(header => {
  2672. const [key, value] = header.split(":");
  2673. return { [key.trim()]: value.trim() };
  2674. }) : [];
  2675. openai_data = configAtIndex._data ?
  2676. configAtIndex._data.split("\n").map(header => {
  2677. const [key, value] = header.split(":");
  2678. return { [key.trim()]: value.trim() };
  2679. }) : [];
  2680. }
  2681. }
  2682. }
  2683. }
  2684. };
  2685.  
  2686. $settingMenu.remove();
  2687. $settingBtns.prop("disabled", false).removeClass("open");
  2688. $(styleElement).remove();
  2689. });
  2690. });
  2691. };
  2692.  
  2693. // html2md转换/处理规则
  2694. var turndownService = new TurndownService({ bulletListMarker: '-', escape: (text) => text });
  2695. var turndown = turndownService.turndown;
  2696.  
  2697. // 保留原始
  2698. turndownService.keep(['del']);
  2699.  
  2700. turndownService.addRule('removeByClass', {
  2701. filter: function (node) {
  2702. return node.classList.contains('html2md-panel') ||
  2703. node.classList.contains('div-btn-copy') ||
  2704. node.classList.contains('btn-copy') ||
  2705. node.classList.contains('overlay')
  2706. },
  2707. replacement: function () {
  2708. return '';
  2709. }
  2710. });
  2711.  
  2712. // inline math
  2713. turndownService.addRule('inline-math', {
  2714. filter: function (node, options) {
  2715. return node.tagName.toLowerCase() == "span" && node.className == "katex";
  2716. },
  2717. replacement: function (content, node) {
  2718. var latex = $(node).find('annotation').text();
  2719. latex = latex.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  2720. return "$" + latex + "$";
  2721. }
  2722. });
  2723.  
  2724. // block math
  2725. turndownService.addRule('block-math', {
  2726. filter: function (node, options) {
  2727. return node.tagName.toLowerCase() == "span" && node.className == "katex-display";
  2728. },
  2729. replacement: function (content, node) {
  2730. var latex = $(node).find('annotation').text();
  2731. latex = latex.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  2732. return "\n$$\n" + latex + "\n$$\n";
  2733. }
  2734. });
  2735.  
  2736. // pre
  2737. turndownService.addRule('pre', {
  2738. filter: function (node, options) {
  2739. return node.tagName.toLowerCase() == "pre";
  2740. },
  2741. replacement: function (content, node) {
  2742. return "```\n" + content + "```\n";
  2743. }
  2744. });
  2745.  
  2746. // bordertable
  2747. turndownService.addRule('bordertable', {
  2748. filter: 'table',
  2749. replacement: function (content, node) {
  2750. if (node.classList.contains('table')) {
  2751. var output = [],
  2752. thead = '',
  2753. trs = node.querySelectorAll('tr');
  2754. if (trs.length > 0) {
  2755. var ths = trs[0].querySelectorAll('th, td');
  2756. if (ths.length > 0) {
  2757. thead = '| ' + Array.from(ths).map(th => turndownService.turndown(th.innerHTML.trim())).join(' | ') + ' |\n'
  2758. thead += '| ' + Array.from(ths).map(() => ' --- ').join('|') + ' |\n';
  2759. }
  2760. }
  2761. var rows = node.querySelectorAll('tr');
  2762. Array.from(rows).forEach(function (row, i) {
  2763. if (i > 0) {
  2764. var cells = row.querySelectorAll('td,th');
  2765. var trow = '| ' + Array.from(cells).map(cell => turndownService.turndown(cell.innerHTML.trim())).join(' | ') + ' |';
  2766. output.push(trow);
  2767. }
  2768. });
  2769. return thead + output.join('\n');
  2770. } else {
  2771. return content;
  2772. }
  2773. }
  2774. });
  2775.  
  2776. // 随机数生成
  2777. function getRandomNumber(numDigits) {
  2778. let min = Math.pow(10, numDigits - 1);
  2779. let max = Math.pow(10, numDigits) - 1;
  2780. return Math.floor(Math.random() * (max - min + 1)) + min;
  2781. }
  2782.  
  2783. // 题目markdown转换/翻译面板
  2784. function addButtonPanel(parent, suffix, type, is_simple = false) {
  2785. let htmlString = `<div class='html2md-panel'>
  2786. <button class='html2mdButton html2md-view${suffix}'>MarkDown视图</button>
  2787. <button class='html2mdButton html2md-cb${suffix}'>Copy</button>
  2788. <button class='html2mdButton translateButton${suffix}'>翻译</button>
  2789. </div>`;
  2790. if (type === "this_level") {
  2791. $(parent).before(htmlString);
  2792. } else if (type === "child_level") {
  2793. $(parent).prepend(htmlString);
  2794. }
  2795. if (is_simple) {
  2796. $('.html2md-panel').find('.html2mdButton.html2md-view' + suffix + ', .html2mdButton.html2md-cb' + suffix).remove();
  2797. }
  2798. }
  2799.  
  2800. function addButtonWithHTML2MD(parent, suffix, type) {
  2801. $(document).on("click", ".html2md-view" + suffix, debounce(function () {
  2802. var target, removedChildren = $();
  2803. if (type === "this_level") {
  2804. target = $(".html2md-view" + suffix).parent().next().get(0);
  2805. } else if (type === "child_level") {
  2806. target = $(".html2md-view" + suffix).parent().parent().get(0);
  2807. removedChildren = $(".html2md-view" + suffix).parent().parent().children(':first').detach();
  2808. }
  2809. if (target.viewmd) {
  2810. target.viewmd = false;
  2811. $(this).text("MarkDown视图");
  2812. $(this).removeClass("mdViewed");
  2813. $(target).html(target.original_html);
  2814. } else {
  2815. target.viewmd = true;
  2816. if (!target.original_html) {
  2817. target.original_html = $(target).html();
  2818. }
  2819. if (!target.markdown) {
  2820. target.markdown = turndownService.turndown($(target).html());
  2821. }
  2822. $(this).text("原始内容");
  2823. $(this).addClass("mdViewed");
  2824. $(target).html(`<span class="mdViewContent" oninput="$(this).parent().get(0).markdown=this.value;" style="width:auto; height:auto;">${target.markdown}</span>`);
  2825. }
  2826. // 恢复删除的元素
  2827. if (removedChildren) $(target).prepend(removedChildren);
  2828. }));
  2829.  
  2830. if (hoverTargetAreaDisplay) {
  2831. var previousCSS;
  2832. $(document).on("mouseover", ".html2md-view" + suffix, function () {
  2833. var target;
  2834.  
  2835. if (type === "this_level") {
  2836. target = $(".html2md-view" + suffix).parent().next().get(0);
  2837. } else if (type === "child_level") {
  2838. target = $(".html2md-view" + suffix).parent().parent().get(0);
  2839. }
  2840.  
  2841. $(target).append('<div class="overlay">目标转换区域</div>');
  2842.  
  2843. previousCSS = {
  2844. "position": $(target).css("position"),
  2845. "display": $(target).css("display")
  2846. };
  2847. $(target).css({
  2848. "position": "relative",
  2849. "display": "block"
  2850. });
  2851.  
  2852. $(".html2md-view" + suffix).parent().css({
  2853. "position": "relative",
  2854. "z-index": "1400"
  2855. })
  2856. });
  2857.  
  2858. $(document).on("mouseout", ".html2md-view" + suffix, function () {
  2859. var target;
  2860.  
  2861. if (type === "this_level") {
  2862. target = $(".html2md-view" + suffix).parent().next().get(0);
  2863. } else if (type === "child_level") {
  2864. target = $(".html2md-view" + suffix).parent().parent().get(0);
  2865. }
  2866.  
  2867. $(target).find('.overlay').remove();
  2868. if (previousCSS) {
  2869. $(target).css(previousCSS);
  2870. }
  2871. $(".html2md-view" + suffix).parent().css({
  2872. "position": "static"
  2873. })
  2874. });
  2875. }
  2876. }
  2877.  
  2878. function addButtonWithCopy(parent, suffix, type) {
  2879. $(document).on("click", ".html2md-cb" + suffix, debounce(function () {
  2880. var target, removedChildren;
  2881. if (type === "this_level") {
  2882. target = $(".translateButton" + suffix).parent().next().eq(0).clone();
  2883. } else if (type === "child_level") {
  2884. target = $(".translateButton" + suffix).parent().parent().eq(0).clone();
  2885. $(target).children(':first').remove();
  2886. }
  2887. if ($(target).find('.mdViewContent').length <= 0) {
  2888. text = turndownService.turndown($(target).html());
  2889. } else {
  2890. text = $(target).find('.mdViewContent').text();
  2891. }
  2892. GM_setClipboard(text);
  2893. $(this).addClass("copied");
  2894. $(this).text("Copied");
  2895. // 更新复制按钮文本
  2896. setTimeout(() => {
  2897. $(this).removeClass("copied");
  2898. $(this).text("Copy");
  2899. }, 2000);
  2900. $(target).remove();
  2901. }));
  2902.  
  2903. if (hoverTargetAreaDisplay) {
  2904. var previousCSS;
  2905. $(document).on("mouseover", ".html2md-cb" + suffix, function () {
  2906. var target;
  2907.  
  2908. if (type === "this_level") {
  2909. target = $(".html2md-cb" + suffix).parent().next().get(0);
  2910. } else if (type === "child_level") {
  2911. target = $(".html2md-cb" + suffix).parent().parent().get(0);
  2912. }
  2913.  
  2914. $(target).append('<div class="overlay">目标复制区域</div>');
  2915. previousCSS = {
  2916. "position": $(target).css("position"),
  2917. "display": $(target).css("display")
  2918. };
  2919. $(target).css({
  2920. "position": "relative",
  2921. "display": "block"
  2922. });
  2923. $(".html2md-cb" + suffix).parent().css({
  2924. "position": "relative",
  2925. "z-index": "1400"
  2926. })
  2927. });
  2928.  
  2929. $(document).on("mouseout", ".html2md-cb" + suffix, function () {
  2930. var target;
  2931.  
  2932. if (type === "this_level") {
  2933. target = $(".html2md-cb" + suffix).parent().next().get(0);
  2934. } else if (type === "child_level") {
  2935. target = $(".html2md-cb" + suffix).parent().parent().get(0);
  2936. }
  2937.  
  2938. $(target).find('.overlay').remove();
  2939. if (previousCSS) {
  2940. $(target).css(previousCSS);
  2941. }
  2942. $(".html2md-cb" + suffix).parent().css({
  2943. "position": "static"
  2944. })
  2945. });
  2946. }
  2947. }
  2948.  
  2949. async function addButtonWithTranslation(parent, suffix, type) {
  2950. var result;
  2951. $(document).on('click', '.translateButton' + suffix, debounce(async function () {
  2952. $(this).trigger('mouseout')
  2953. .removeClass("translated")
  2954. .text("翻译中")
  2955. .css("cursor", "not-allowed")
  2956. .prop("disabled", true);
  2957. var target, element_node, block, errerNum = 0;
  2958. if (type === "this_level") block = $(".translateButton" + suffix).parent().next();
  2959. else if (type === "child_level") block = $(".translateButton" + suffix).parent().parent();
  2960.  
  2961. // 重新翻译
  2962. if (result) {
  2963. if (result.translateDiv) $(result.translateDiv).remove();
  2964. if (result.copyDiv) $(result.copyDiv).remove();
  2965. if (result.panelDiv) $(result.panelDiv).remove();
  2966. $(block).find(".translate-problem-statement, .translate-problem-statement-panel").remove();
  2967. // 移除旧的事件
  2968. $(document).off("mouseover", ".translateButton" + suffix);
  2969. $(document).off("mouseout", ".translateButton" + suffix);
  2970. // 重新绑定悬停事件
  2971. if (hoverTargetAreaDisplay) bindHoverEvents(suffix, type);
  2972. }
  2973.  
  2974. // 分段翻译
  2975. if (enableSegmentedTranslation) {
  2976. var pElements = block.find("p, li:not(pre li)");
  2977. pElements.find('pre').remove();
  2978. for (let i = 0; i < pElements.length; i++) {
  2979. target = $(pElements[i]).eq(0).clone();
  2980. element_node = pElements[i];
  2981. if (type === "child_level") {
  2982. $(pElements[i]).append("<div></div>");
  2983. element_node = $(pElements[i]).find("div:last-child").get(0);
  2984. }
  2985. result = await blockProcessing(target, element_node, $(".translateButton" + suffix));
  2986. if (result.status) errerNum += 1;
  2987. $(target).remove();
  2988. if (translation == "deepl") await new Promise(resolve => setTimeout(resolve, 2000));
  2989. }
  2990. } else {
  2991. target = block.eq(0).clone();
  2992. $(target).find('pre').remove();
  2993. if (type === "child_level") $(target).children(':first').remove();
  2994. element_node = $(block).get(0);
  2995. if (type === "child_level") {
  2996. $(parent).append("<div></div>");
  2997. element_node = $(parent).find("div:last-child").get(0);
  2998. }
  2999. //是否跳过折叠块
  3000. if ($(target).find('.spoiler').length > 0) {
  3001. const shouldSkip = await skiFoldingBlocks();
  3002. if (shouldSkip) {
  3003. $(target).find('.spoiler').remove();
  3004. } else {
  3005. $(target).find('.html2md-panel').remove();
  3006. }
  3007. }
  3008. result = await blockProcessing(target, element_node, $(".translateButton" + suffix));
  3009. if (result.status) errerNum += 1;
  3010. $(target).remove();
  3011. }
  3012.  
  3013. if (!errerNum) {
  3014. $(this).addClass("translated")
  3015. .text("已翻译")
  3016. .css("cursor", "pointer")
  3017. .removeClass("error")
  3018. .prop("disabled", false);
  3019. } else {
  3020. $(this).prop("disabled", false);
  3021. }
  3022.  
  3023. // 重新翻译
  3024. let currentText, is_error;
  3025. $(document).on("mouseover", ".translateButton" + suffix, function () {
  3026. currentText = $(this).text();
  3027. $(this).text("重新翻译");
  3028. if ($(this).hasClass("error")) {
  3029. is_error = true;
  3030. $(this).removeClass("error");
  3031. }
  3032. });
  3033.  
  3034. $(document).on("mouseout", ".translateButton" + suffix, function () {
  3035. $(this).text(currentText);
  3036. if (is_error) $(this).addClass("error");
  3037. });
  3038. }));
  3039.  
  3040. // 目标区域指示
  3041. function bindHoverEvents(suffix, type) {
  3042. var previousCSS;
  3043.  
  3044. $(document).on("mouseover", ".translateButton" + suffix, function () {
  3045. var target;
  3046.  
  3047. if (type === "this_level") {
  3048. target = $(".translateButton" + suffix).parent().next().get(0);
  3049. } else if (type === "child_level") {
  3050. target = $(".translateButton" + suffix).parent().parent().get(0);
  3051. }
  3052.  
  3053. $(target).append('<div class="overlay">目标翻译区域</div>');
  3054. previousCSS = {
  3055. "position": $(target).css("position"),
  3056. "display": $(target).css("display")
  3057. };
  3058. $(target).css({
  3059. "position": "relative",
  3060. "display": "block"
  3061. });
  3062. $(".translateButton" + suffix).parent().css({
  3063. "position": "relative",
  3064. "z-index": "1400"
  3065. });
  3066. });
  3067.  
  3068. $(document).on("mouseout", ".translateButton" + suffix, function () {
  3069. var target;
  3070.  
  3071. if (type === "this_level") {
  3072. target = $(".translateButton" + suffix).parent().next().get(0);
  3073. } else if (type === "child_level") {
  3074. target = $(".translateButton" + suffix).parent().parent().get(0);
  3075. }
  3076.  
  3077. $(target).find('.overlay').remove();
  3078. if (previousCSS) {
  3079. $(target).css(previousCSS);
  3080. }
  3081. $(".translateButton" + suffix).parent().css({
  3082. "position": "static"
  3083. });
  3084. });
  3085. }
  3086.  
  3087. if (hoverTargetAreaDisplay) bindHoverEvents(suffix, type);
  3088.  
  3089. // 右键菜单
  3090. $(document).on('contextmenu', '.translateButton' + suffix, function (e) {
  3091. e.preventDefault();
  3092.  
  3093. // 移除旧的
  3094. if (!$(event.target).closest('.AtBetter_contextmenu').length) {
  3095. $('.AtBetter_contextmenu').remove();
  3096. }
  3097.  
  3098. var menu = $('<div class="AtBetter_contextmenu"></div>');
  3099. var translations = [
  3100. { value: 'deepl', name: 'deepl翻译' },
  3101. { value: 'iflyrec', name: '讯飞听见翻译' },
  3102. { value: 'youdao', name: '有道翻译' },
  3103. { value: 'google', name: 'Google翻译' },
  3104. { value: 'caiyun', name: '彩云小译翻译' },
  3105. { value: 'openai', name: 'ChatGPT翻译' }
  3106. ];
  3107. translations.forEach(function (translation) {
  3108. var label = $(`<label><input type="radio" name="translation" value="${translation.value}">
  3109. <span class="AtBetter_contextmenu_label_text">${translation.name}</span></label>`);
  3110. menu.append(label);
  3111. });
  3112.  
  3113. // 初始化
  3114. menu.find(`input[name="translation"][value="${translation}"]`).prop('checked', true);
  3115. menu.css({
  3116. top: e.pageY + 'px',
  3117. left: e.pageX + 'px'
  3118. }).appendTo('body');
  3119.  
  3120. $(document).one('change', 'input[name="translation"]', function () {
  3121. translation = $('input[name="translation"]:checked').val();
  3122. GM_setValue("translation", translation);
  3123. $('.AtBetter_contextmenu').remove();
  3124. });
  3125.  
  3126. // 点击区域外关闭菜单
  3127. function handleClick(event) {
  3128. if (!$(event.target).closest('.AtBetter_contextmenu').length) {
  3129. $('.AtBetter_contextmenu').remove();
  3130. $(document).off('change', 'input[name="translation"]');
  3131. } else {
  3132. $(document).one('click', handleClick);
  3133. }
  3134. }
  3135. $(document).one('click', handleClick);
  3136. });
  3137. }
  3138.  
  3139. // 块处理
  3140. async function blockProcessing(target, element_node, button) {
  3141. if (!target.markdown) {
  3142. target.markdown = turndownService.turndown($(target).html());
  3143. }
  3144. const textarea = document.createElement('textarea');
  3145. textarea.value = target.markdown;
  3146. var result = await translateProblemStatement(textarea.value, element_node, $(button));
  3147. //
  3148. if (result.status == 1) {
  3149. $(button).addClass("error")
  3150. .text("翻译中止")
  3151. .css("cursor", "pointer")
  3152. .prop("disabled", false);
  3153. $(result.translateDiv).remove();
  3154. $(target).remove();
  3155. } else if (result.status == 2) {
  3156. result.translateDiv.classList.add("error_translate");
  3157. $(button).addClass("error")
  3158. .text("翻译出错")
  3159. .css("cursor", "pointer")
  3160. .prop("disabled", false);
  3161. $(target).remove();
  3162. }
  3163. return result;
  3164. }
  3165.  
  3166. function addConversionButton() {
  3167. // 基本添加
  3168. if (!is_homepage) {
  3169. $('section').each(function () {
  3170. let id = "_" + getRandomNumber(8);
  3171. addButtonPanel(this, id, "this_level");
  3172. addButtonWithHTML2MD(this, id, "this_level");
  3173. addButtonWithCopy(this, id, "this_level");
  3174. addButtonWithTranslation(this, id, "this_level");
  3175. });
  3176. }
  3177.  
  3178. // 添加按钮到题解部分
  3179. if (window.location.href.includes("editorial")) {
  3180. let contestNavTabs = $("#contest-nav-tabs");
  3181. let nextElement = contestNavTabs.next();
  3182. let id = "_editorial_" + getRandomNumber(8);
  3183. addButtonPanel(nextElement, id, "child_level");
  3184. addButtonWithHTML2MD(nextElement, id, "child_level");
  3185. addButtonWithCopy(nextElement, id, "child_level");
  3186. addButtonWithTranslation(nextElement, id, "child_level");
  3187. }
  3188. if (window.location.href.includes("editorial")) {
  3189. let contestNavTabs = $("#contest-nav-tabs");
  3190. let nextElement = contestNavTabs.next().children().eq(-2);
  3191. let id = "_editorial_" + getRandomNumber(8);
  3192. addButtonPanel(nextElement, id, "child_level");
  3193. addButtonWithHTML2MD(nextElement, id, "child_level");
  3194. addButtonWithCopy(nextElement, id, "child_level");
  3195. addButtonWithTranslation(nextElement, id, "child_level");
  3196. }
  3197.  
  3198. // 添加按钮到折叠块部分
  3199. $('details').each(function () {
  3200. let id = "_details_" + getRandomNumber(8);
  3201. addButtonPanel(this, id, "child_level");
  3202. addButtonWithHTML2MD(this, id, "child_level");
  3203. addButtonWithCopy(this, id, "child_level");
  3204. addButtonWithTranslation(this, id, "child_level");
  3205. });
  3206.  
  3207. // 添加到contest-statement部分
  3208. $('#contest-statement').each(function () {
  3209. let id = "_contest-statement_" + getRandomNumber(8);
  3210. addButtonPanel(this, id, "this_level");
  3211. addButtonWithHTML2MD(this, id, "this_level");
  3212. addButtonWithCopy(this, id, "this_level");
  3213. addButtonWithTranslation(this, id, "this_level");
  3214. });
  3215.  
  3216. // 添加到blog-post部分
  3217. $('.blog-post').each(function () {
  3218. let id = "_blog-post_" + getRandomNumber(8);
  3219. addButtonPanel(this, id, "this_level");
  3220. addButtonWithHTML2MD(this, id, "this_level");
  3221. addButtonWithCopy(this, id, "this_level");
  3222. addButtonWithTranslation(this, id, "this_level");
  3223. });
  3224. };
  3225.  
  3226. // 跳转洛谷
  3227. async function At2luogu() {
  3228. const getProblemId = () => {
  3229. const url = window.location.href;
  3230. const regex = /\/contests\/([A-Za-z\d]+)\/tasks\/([A-Za-z\d\_]+)/;
  3231. const matchResult = url.match(regex);
  3232. return matchResult && matchResult.length >= 3
  3233. ? `${matchResult[2]}`
  3234. : '';
  3235. };
  3236.  
  3237. const checkLinkExistence = (url) => {
  3238. return new Promise((resolve, reject) => {
  3239. GM.xmlHttpRequest({
  3240. method: "GET",
  3241. url,
  3242. headers: { "Range": "bytes=0-9999" }, // 获取前10KB数据
  3243. onload(response) {
  3244. if (response.responseText.match(/题目未找到/g)) {
  3245. resolve(false);
  3246. } else {
  3247. resolve(true);
  3248. }
  3249. },
  3250. onerror(error) {
  3251. reject(error);
  3252. }
  3253. });
  3254. });
  3255. };
  3256.  
  3257. const url = `https://www.luogu.com.cn/problem/AT_${getProblemId()}`;
  3258. const result = await checkLinkExistence(url);
  3259. if (getProblemId() && result) {
  3260. const problemLink = $("<a style='display: inline-block;vertical-align: middle;'>")
  3261. .attr("id", "problemLink")
  3262. .attr("href", url)
  3263. .attr("target", "_blank")
  3264. .html(`<button style="height: 29px;border: 1px solid #ccc;" class="html2mdButton"><img style="width:45px; margin-right:2px;" src="https://cdn.luogu.com.cn/fe/logo.png"></button>`);
  3265. problemLink.appendTo('.h2');
  3266. }
  3267. }
  3268.  
  3269. // 字数超限确认
  3270. function showWordsExceededDialog(button, textLength, realTextLength) {
  3271. return new Promise(resolve => {
  3272. const styleElement = GM_addStyle(darkenPageStyle);
  3273. $(button).removeClass("translated");
  3274. $(button).text("字数超限");
  3275. $(button).css("cursor", "not-allowed");
  3276. $(button).prop("disabled", true);
  3277. let htmlString = `
  3278. <div class="AtBetter_modal">
  3279. <h2>字符数超限! </h2>
  3280. <p>即将翻译的内容共 <strong>${realTextLength}</strong> 字符</p>
  3281. <p>这超出了当前翻译服务的 <strong>${textLength}</strong> 字符上限,请更换翻译服务,或在设置面板中开启“分段翻译”</p>
  3282. <div style="display:flex; padding:5px 0px; align-items: center;">
  3283. `+ helpCircleHTML + `
  3284. <p>
  3285. 注意,可能您选择了错误的翻译按钮<br>
  3286. 由于实现方式,区域中会出现多个翻译按钮,请点击更小的子区域中的翻译按钮
  3287. </p>
  3288. </div>
  3289. <p>您确定要继续翻译吗?</p>
  3290. <div class="buttons">
  3291. <button id="continueButton">继续</button><button id="cancelButton">取消</button>
  3292. </div>
  3293. </div>
  3294. `;
  3295. $('body').before(htmlString);
  3296. $("#continueButton").click(function () {
  3297. $(styleElement).remove();
  3298. $('.AtBetter_modal').remove();
  3299. resolve(true);
  3300. });
  3301. $("#cancelButton").click(function () {
  3302. $(styleElement).remove();
  3303. $('.AtBetter_modal').remove();
  3304. resolve(false);
  3305. });
  3306. });
  3307. }
  3308.  
  3309. // 跳过折叠块确认
  3310. function skiFoldingBlocks() {
  3311. return new Promise(resolve => {
  3312. const styleElement = GM_addStyle(darkenPageStyle);
  3313. let htmlString = `
  3314. <div class="AtBetter_modal">
  3315. <h4>是否跳过折叠块?</h4>
  3316. <p></p>
  3317. <div style="display:grid; padding:5px 0px; align-items: center;">
  3318. <p>
  3319. 即将翻译的区域中包含折叠块,可能不需要翻译,现在您需要选择是否跳过这些折叠块,
  3320. </p>
  3321. <p>
  3322. 如果其中有您需要翻译的折叠块,可以稍后再单独点击这些折叠块内的翻译按钮进行翻译
  3323. </p>
  3324. </div>
  3325. <p>要跳过折叠块吗?(建议选择跳过)</p>
  3326. <div class="buttons">
  3327. <button id="cancelButton">否</button><button id="skipButton">跳过</button>
  3328. </div>
  3329. </div>
  3330. `;
  3331. $('body').before(htmlString);
  3332. $("#skipButton").click(function () {
  3333. $(styleElement).remove();
  3334. $('.AtBetter_modal').remove();
  3335. resolve(true);
  3336. });
  3337. $("#cancelButton").click(function () {
  3338. $(styleElement).remove();
  3339. $('.AtBetter_modal').remove();
  3340. resolve(false);
  3341. });
  3342. });
  3343. }
  3344.  
  3345. // latex替换
  3346. function replaceBlock(text, matches, replacements) {
  3347. try {
  3348. for (let i = 0; i < matches.length; i++) {
  3349. let match = matches[i];
  3350. let replacement = '';
  3351. if (replaceSymbol === "1") {
  3352. replacement = `【${i + 1}】`;
  3353. } else if (replaceSymbol === "2") {
  3354. replacement = `{${i + 1}}`;
  3355. } else if (replaceSymbol === "3") {
  3356. replacement = `[${i + 1}]`;
  3357. }
  3358. text = text.replace(match, replacement);
  3359. replacements[replacement] = match;
  3360. }
  3361. } catch (e) { }
  3362. return text;
  3363. }
  3364.  
  3365. // latex还原
  3366. function recoverBlock(translatedText, matches, replacements) {
  3367. if (matches == null) return translatedText;
  3368. for (let i = 0; i < matches.length; i++) {
  3369. let match = matches[i];
  3370. let replacement = replacements[`【${i + 1}】`] || replacements[`[${i + 1}]`] || replacements[`{${i + 1}}`];
  3371.  
  3372. let latexMatch = '\\$\\$([\\s\\S]*?)\\$\\$|\\$(.*?)\\$|\\$([\\s\\S]*?)\\$|';
  3373.  
  3374. let regex = new RegExp(latexMatch + `【\\s*${i + 1}\\s*】|\\[\\s*${i + 1}\\s*\\]|{\\s*${i + 1}\\s*}`, 'g');
  3375. translatedText = translatedText.replace(regex, function (match, p1, p2, p3) {
  3376. // LaTeX中的不替换
  3377. if (p1 || p2 || p3) {
  3378. return match;
  3379. }
  3380. return replacement;
  3381. });
  3382.  
  3383.  
  3384. regex = new RegExp(latexMatch + `【\\s*${i + 1}(?![】\\d])|(?<![【\\d])${i + 1}\\s*】|\\[\\s*${i + 1}(?![\\]\\d])|(?<![\\[\\d])${i + 1}\\s*\\]|{\\s*${i + 1}(?![}\\d])|(?<![{\\d])${i + 1}\\s*}`, 'g');
  3385. translatedText = translatedText.replace(regex, function (match, p1, p2, p3) {
  3386. // LaTeX中的不替换
  3387. if (p1 || p2 || p3) {
  3388. return match;
  3389. }
  3390. return " " + replacement;
  3391. });
  3392. }
  3393. return translatedText;
  3394. }
  3395.  
  3396. // 翻译框/翻译处理器
  3397. var translatedText = "";
  3398. async function translateProblemStatement(text, element_node, button) {
  3399. let status = 0;
  3400. let id = getRandomNumber(8);
  3401. let matches = [];
  3402. let replacements = {};
  3403. // 创建元素并放在element_node的后面
  3404. const translateDiv = document.createElement('div');
  3405. translateDiv.setAttribute('id', id);
  3406. translateDiv.classList.add('translate-problem-statement');
  3407. const spanElement = document.createElement('span');
  3408. translateDiv.appendChild(spanElement);
  3409. element_node.insertAdjacentElement('afterend', translateDiv);
  3410. // 替换latex公式
  3411. if (translation != "openai") {
  3412. // 使用GPT翻译时不必替换latex公式
  3413. let regex = /\$\$([\s\S]*?)\$\$|\$(.*?)\$|\$([\s\S]*?)\$/g;
  3414. matches = matches.concat(text.match(regex));
  3415. text = replaceBlock(text, matches, replacements);
  3416. }
  3417. // 字符数上限
  3418. const translationLimits = {
  3419. deepl: 5000,
  3420. iflyrec: 2000,
  3421. youdao: 600,
  3422. google: 5000,
  3423. caiyun: 5000
  3424. };
  3425. if (translationLimits.hasOwnProperty(translation) && text.length > translationLimits[translation]) {
  3426. const shouldContinue = await showWordsExceededDialog(button, translationLimits[translation], text.length);
  3427. if (!shouldContinue) {
  3428. status = 1;
  3429. return {
  3430. translateDiv: translateDiv,
  3431. status: status
  3432. };
  3433. }
  3434. }
  3435. // 翻译
  3436. async function translate(translation) {
  3437. try {
  3438. if (translation == "deepl") {
  3439. translateDiv.innerHTML = "正在使用 deepl 翻译中……请稍等";
  3440. translatedText = await translate_deepl(text);
  3441. } else if (translation == "iflyrec") {
  3442. translateDiv.innerHTML = "正在使用 讯飞听见 翻译中……请稍等";
  3443. translatedText = await translate_iflyrec(text);
  3444. } else if (translation == "youdao") {
  3445. translateDiv.innerHTML = "正在使用 有道 翻译中……请稍等";
  3446. translatedText = await translate_youdao_mobile(text);
  3447. } else if (translation == "google") {
  3448. translateDiv.innerHTML = "正在使用 google 翻译中……请稍等";
  3449. translatedText = await translate_gg(text);
  3450. } else if (translation == "caiyun") {
  3451. translateDiv.innerHTML = "正在使用 彩云小译 翻译中……请稍等";
  3452. await translate_caiyun_startup();
  3453. translatedText = await translate_caiyun(text);
  3454. } else if (translation == "openai") {
  3455. translateDiv.innerHTML = "正在使用 ChatGPT 翻译中……" +
  3456. "<br><br>应用的配置:" + opneaiConfig.configurations[opneaiConfig.choice].note +
  3457. "<br><br>使用 ChatGPT 翻译需要很长的时间,请耐心等待";
  3458. translatedText = await translate_openai(text);
  3459.  
  3460. }
  3461. if (/^翻译出错/.test(translatedText)) status = 2;
  3462. } catch (error) {
  3463. status = 2;
  3464. translatedText = error;
  3465. }
  3466. }
  3467. await translate(translation);
  3468.  
  3469. // 还原latex公式
  3470. translatedText = translatedText.replace(/】\s*【/g, '】 【');
  3471. translatedText = translatedText.replace(/\]\s*\[/g, '] [');
  3472. translatedText = translatedText.replace(/\}\s*\{/g, '} {');
  3473. if (translation != "openai") {
  3474. translatedText = recoverBlock(translatedText, matches, replacements);
  3475. }
  3476.  
  3477. // 结果复制按钮
  3478. // 创建一个隐藏的元素来保存 translatedText 的值
  3479. var textElement = document.createElement("div");
  3480. textElement.style.display = "none";
  3481. textElement.textContent = translatedText;
  3482. translateDiv.parentNode.insertBefore(textElement, translateDiv);
  3483.  
  3484. // panel
  3485. var panelDiv = document.createElement("div");
  3486. $(panelDiv).addClass("translate-problem-statement-panel");
  3487. // 收起按钮
  3488. var closeButton = document.createElement("div");
  3489. closeButton.innerHTML = putawayIcon;
  3490. $(closeButton).addClass("borderlessButton");
  3491. $(panelDiv).append(closeButton);
  3492. // 复制按钮
  3493. var copyButton = document.createElement("div");
  3494. copyButton.innerHTML = copyIcon;
  3495. $(copyButton).addClass("borderlessButton");
  3496. $(panelDiv).append(copyButton);
  3497.  
  3498. var buttonState = "expand";
  3499. closeButton.addEventListener("click", function () {
  3500. if (buttonState === "expand") {
  3501. this.innerHTML = unfoldIcon;
  3502. $(translateDiv).css({
  3503. display: "none",
  3504. transition: "height 2s"
  3505. });
  3506. buttonState = "collapse";
  3507. } else if (buttonState === "collapse") {
  3508. // 执行收起操作
  3509. this.innerHTML = putawayIcon;
  3510. $(translateDiv).css({
  3511. display: "",
  3512. transition: "height 2s"
  3513. });
  3514. buttonState = "expand";
  3515. }
  3516. });
  3517.  
  3518. copyButton.addEventListener("click", function () {
  3519. var translatedText = textElement.textContent;
  3520. GM_setClipboard(translatedText);
  3521. // $(this).addClass("copied").text("Copied");
  3522. // // 更新复制按钮文本
  3523. // setTimeout(() => {
  3524. // $(this).removeClass("copied");
  3525. // $(this).text("Copy");
  3526. // }, 2000);
  3527. });
  3528. translateDiv.parentNode.insertBefore(panelDiv, translateDiv);
  3529.  
  3530. // 转义LaTex中的特殊符号
  3531. const escapeRules = [
  3532. { pattern: /(?<!\\)>(?!\s)/g, replacement: " &gt; " }, // >符号
  3533. { pattern: /(?<!\\)</g, replacement: " &lt; " }, // <符号
  3534. { pattern: /(?<!\\)\*/g, replacement: " &#42; " }, // *符号
  3535. { pattern: /(?<!\\)_/g, replacement: " &#95; " }, // _符号
  3536. { pattern: /(?<!\\)\\\\(?=\s)/g, replacement: "\\\\\\\\" }, // \\符号
  3537. { pattern: /(?<!\\)\\(?![\\a-zA-Z0-9])/g, replacement: "\\\\" }, // \符号
  3538. ];
  3539.  
  3540. let latexMatches = [...translatedText.matchAll(/\$\$([\s\S]*?)\$\$|\$(.*?)\$|\$([\s\S]*?)\$/g)];
  3541.  
  3542. for (const match of latexMatches) {
  3543. const matchedText = match[0];
  3544. var escapedText = matchedText;
  3545. for (const rule of escapeRules) {
  3546. escapedText = escapedText.replaceAll(rule.pattern, rule.replacement);
  3547. }
  3548. escapedText = escapedText.replace(/\$\$/g, "$$$$$$$$");// $$符号(因为后面需要作为replacement)
  3549. translatedText = translatedText.replace(matchedText, escapedText);
  3550. }
  3551.  
  3552. // markdown修正
  3553. const mdRuleMap = [
  3554. { pattern: /(\s_[\u4e00-\u9fa5]+_)([\u4e00-\u9fa5]+)/g, replacement: "$1 $2" }, // 斜体
  3555. { pattern: /(_[\u4e00-\u9fa5]+_\s)([\u4e00-\u9fa5]+)/g, replacement: " $1$2" },
  3556. { pattern: /(_[\u4e00-\u9fa5]+_)([\u4e00-\u9fa5]+)/g, replacement: " $1 $2" },
  3557. { pattern: /(([\s\S]*?))/g, replacement: "($1)" }, // 中文()
  3558. // { pattern: /:/g, replacement: ":" }, // 中文:
  3559. { pattern: /\*\* (.*?) \*\*/g, replacement: "\*\*$1\*\*" } // 加粗
  3560. ];
  3561. mdRuleMap.forEach(({ pattern, replacement }) => {
  3562. translatedText = translatedText.replace(pattern, replacement);
  3563. });
  3564.  
  3565. // 渲染MarkDown
  3566. var md = window.markdownit();
  3567. var html = md.render(translatedText);
  3568. translateDiv.innerHTML = html;
  3569. // 渲染Latex
  3570. if (typeof renderMathInElement === 'function') {
  3571. renderMathInElement(translateDiv, {
  3572. delimiters: [{
  3573. left: "$$",
  3574. right: "$$",
  3575. display: true
  3576. }, {
  3577. left: "$",
  3578. right: "$",
  3579. display: false
  3580. }]
  3581. });
  3582. }
  3583. return {
  3584. translateDiv: translateDiv,
  3585. status: status,
  3586. copyDiv: textElement,
  3587. panelDiv: panelDiv
  3588. };
  3589.  
  3590. }
  3591.  
  3592. // ChatGPT
  3593. async function translate_openai(raw) {
  3594. var openai_retext = "";
  3595. var data = {
  3596. model: (openai_model !== null && openai_model !== "") ? openai_model : 'gpt-3.5-turbo',
  3597. messages: [{
  3598. role: "user",
  3599. content: "请将下面的文本翻译为中文,这是一道编程竞赛题描述的一部分,注意术语的翻译,注意保持其中的latex公式不翻译,你只需要回复翻译后的内容即可,不要回复任何其他内容:\n\n" + raw
  3600. }],
  3601. temperature: 0.7,
  3602. ...Object.assign({}, ...openai_data)
  3603. };
  3604. return new Promise(function (resolve, reject) {
  3605. GM_xmlhttpRequest({
  3606. method: 'POST',
  3607. url: (openai_proxy !== null && openai_proxy !== "") ? openai_proxy : 'https://api.openai.com/v1/chat/completions',
  3608.  
  3609. data: JSON.stringify(data),
  3610. headers: {
  3611. 'Content-Type': 'application/json',
  3612. 'Authorization': 'Bearer ' + openai_key,
  3613. ...Object.assign({}, ...openai_header)
  3614. },
  3615. responseType: 'json',
  3616. onload: function (response) {
  3617. if (!response.response) {
  3618. reject("发生了未知的错误,如果你启用了代理API,请确认是否填写正确,并确保代理能够正常工作。\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  3619. }
  3620. else if (!response.response.choices || response.response.choices.length < 1 || !response.response.choices[0].message) {
  3621. resolve("翻译出错,请重试\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈\n\n报错信息:" + JSON.stringify(response.response, null, ''));
  3622. } else {
  3623. openai_retext = response.response.choices[0].message.content;
  3624. resolve(openai_retext);
  3625. }
  3626. },
  3627. onerror: function (response) {
  3628. reject("发生了未知的错误,请确认你是否能正常访问OpenAi的接口,如果使用代理API,请检查是否正常工作\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码响应报文的敏感部分\n\n响应报文:" + JSON.stringify(response));
  3629. },
  3630. });
  3631. });
  3632. }
  3633.  
  3634. //--谷歌翻译--start
  3635. async function translate_gg(raw) {
  3636. return new Promise((resolve, reject) => {
  3637. const url = 'https://translate.google.com/m';
  3638. const params = `tl=zh-CN&q=${encodeURIComponent(raw)}`;
  3639.  
  3640. GM_xmlhttpRequest({
  3641. method: 'GET',
  3642. url: `${url}?${params}`,
  3643. onload: function (response) {
  3644. const html = response.responseText;
  3645. const translatedText = $(html).find('.result-container').text();
  3646. resolve(translatedText);
  3647. },
  3648. onerror: function (response) {
  3649. reject("发生了未知的错误,请确认你是否能正常访问Google翻译,\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码报错信息的敏感部分\n\n响应报文:" + JSON.stringify(response))
  3650. }
  3651. });
  3652. });
  3653. }
  3654. //--谷歌翻译--end
  3655.  
  3656. //--有道翻译m--start
  3657. async function translate_youdao_mobile(raw) {
  3658. const options = {
  3659. method: "POST",
  3660. url: 'http://m.youdao.com/translate',
  3661. data: "inputtext=" + encodeURIComponent(raw) + "&type=AUTO",
  3662. anonymous: true,
  3663. headers: {
  3664. "Content-Type": "application/x-www-form-urlencoded",
  3665. 'Host': 'm.youdao.com',
  3666. 'Origin': 'http://m.youdao.com',
  3667. 'Referer': 'http://m.youdao.com/translate',
  3668. }
  3669. }
  3670. return await BaseTranslate('有道翻译mobile', raw, options, res => /id="translateResult">\s*?<li>([\s\S]*?)<\/li>\s*?<\/ul/.exec(res)[1])
  3671. }
  3672. //--有道翻译m--end
  3673.  
  3674. //--彩云翻译--start
  3675. async function translate_caiyun_startup() {
  3676. const browser_id = CryptoJS.MD5(Math.random().toString()).toString();
  3677. sessionStorage.setItem('caiyun_id', browser_id);
  3678. const options = {
  3679. method: "POST",
  3680. url: 'https://api.interpreter.caiyunai.com/v1/user/jwt/generate',
  3681. headers: {
  3682. "Content-Type": "application/json",
  3683. "X-Authorization": "token:qgemv4jr1y38jyq6vhvi",
  3684. "Origin": "https://fanyi.caiyunapp.com",
  3685. },
  3686. data: JSON.stringify({ browser_id }),
  3687. }
  3688. const res = await Request(options);
  3689. sessionStorage.setItem('caiyun_jwt', JSON.parse(res.responseText).jwt);
  3690. }
  3691.  
  3692. async function translate_caiyun(raw) {
  3693. const source = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
  3694. const dic = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"].reduce((dic, current, index) => { dic[current] = source[index]; return dic }, {});
  3695. // 解码
  3696. const decodeUnicode = str => {
  3697. const decoder = new TextDecoder();
  3698. const data = Uint8Array.from(atob(str), c => c.charCodeAt(0));
  3699. return decoder.decode(data);
  3700. };
  3701. const decoder = line => decodeUnicode([...line].map(i => dic[i] || i).join(""));
  3702. const options = {
  3703. method: "POST",
  3704. url: 'https://api.interpreter.caiyunai.com/v1/translator',
  3705. data: JSON.stringify({
  3706. "source": raw.split('\n'),
  3707. "trans_type": "auto2zh",
  3708. "detect": true,
  3709. "browser_id": sessionStorage.getItem('caiyun_id')
  3710. }),
  3711. headers: {
  3712. "X-Authorization": "token:qgemv4jr1y38jyq6vhvi",
  3713. "T-Authorization": sessionStorage.getItem('caiyun_jwt')
  3714. }
  3715. }
  3716. return await BaseTranslate('彩云小译', raw, options, res => JSON.parse(res).target.map(decoder).join('\n'))
  3717. }
  3718. //--彩云翻译--end
  3719.  
  3720. //--Deepl翻译--start
  3721. function getTimeStamp(iCount) {
  3722. const ts = Date.now();
  3723. if (iCount !== 0) {
  3724. iCount = iCount + 1;
  3725. return ts - (ts % iCount) + iCount;
  3726. } else {
  3727. return ts;
  3728. }
  3729. }
  3730.  
  3731. async function translate_deepl(raw) {
  3732. const id = (Math.floor(Math.random() * 99999) + 100000) * 1000;
  3733. const data = {
  3734. jsonrpc: '2.0',
  3735. method: 'LMT_handle_texts',
  3736. id,
  3737. params: {
  3738. splitting: 'newlines',
  3739. lang: {
  3740. source_lang_user_selected: 'auto',
  3741. target_lang: 'ZH',
  3742. },
  3743. texts: [{
  3744. text: raw,
  3745. requestAlternatives: 3
  3746. }],
  3747. timestamp: getTimeStamp(raw.split('i').length - 1)
  3748. }
  3749. }
  3750. let postData = JSON.stringify(data);
  3751. if ((id + 5) % 29 === 0 || (id + 3) % 13 === 0) {
  3752. postData = postData.replace('"method":"', '"method" : "');
  3753. } else {
  3754. postData = postData.replace('"method":"', '"method": "');
  3755. }
  3756. const options = {
  3757. method: 'POST',
  3758. url: 'https://www2.deepl.com/jsonrpc',
  3759. data: postData,
  3760. headers: {
  3761. 'Content-Type': 'application/json',
  3762. 'Host': 'www2.deepl.com',
  3763. 'Origin': 'https://www.deepl.com',
  3764. 'Referer': 'https://www.deepl.com/',
  3765. },
  3766. anonymous: true,
  3767. nocache: true,
  3768. }
  3769. return await BaseTranslate('Deepl翻译', raw, options, res => JSON.parse(res).result.texts[0].text)
  3770. }
  3771.  
  3772. //--Deepl翻译--end
  3773.  
  3774. //--讯飞听见翻译--end
  3775. async function translate_iflyrec(text) {
  3776. const options = {
  3777. method: "POST",
  3778. url: 'https://www.iflyrec.com/TranslationService/v1/textTranslation',
  3779. data: JSON.stringify({
  3780. "from": "2",
  3781. "to": "1",
  3782. "contents": [{
  3783. "text": text,
  3784. "frontBlankLine": 0
  3785. }]
  3786. }),
  3787. anonymous: true,
  3788. headers: {
  3789. 'Content-Type': 'application/json',
  3790. 'Origin': 'https://www.iflyrec.com',
  3791. },
  3792. responseType: "json",
  3793. };
  3794. return await BaseTranslate('讯飞翻译', text, options, res => JSON.parse(res).biz[0].translateResult.replace(/\\n/g, "\n\n"));
  3795. }
  3796. //--讯飞听见翻译--end
  3797.  
  3798. //--异步请求包装工具--start
  3799. async function PromiseRetryWrap(task, options, ...values) {
  3800. const { RetryTimes, ErrProcesser } = options || {};
  3801. let retryTimes = RetryTimes || 5;
  3802. const usedErrProcesser = ErrProcesser || (err => { throw err });
  3803. if (!task) return;
  3804. while (true) {
  3805. try {
  3806. return await task(...values);
  3807. } catch (err) {
  3808. if (!--retryTimes) {
  3809. console.warn(err);
  3810. return usedErrProcesser(err);
  3811. }
  3812. }
  3813. }
  3814. }
  3815.  
  3816. async function BaseTranslate(name, raw, options, processer) {
  3817. let errtext;
  3818. const toDo = async () => {
  3819. var tmp;
  3820. try {
  3821. const data = await Request(options);
  3822. tmp = data.responseText;
  3823. let result = await processer(tmp);
  3824. return result;
  3825. } catch (err) {
  3826. errtext = tmp;
  3827. throw {
  3828. responseText: tmp,
  3829. err: err
  3830. }
  3831. }
  3832. }
  3833. return await PromiseRetryWrap(toDo, { RetryTimes: 3, ErrProcesser: () => "翻译出错,请查看报错信息,并重试或更换翻译接口\n\n如果无法解决,请前往 https://greatest.deepsurf.us/zh-CN/scripts/471106/feedback 反馈 请注意打码报错信息的敏感部分\n\n报错信息:" + errtext })
  3834. }
  3835.  
  3836.  
  3837. function Request(options) {
  3838. return new Promise((reslove, reject) => GM_xmlhttpRequest({ ...options, onload: reslove, onerror: reject }))
  3839. }
  3840.  
  3841. //--异步请求包装工具--end
  3842.  
  3843. // 开始
  3844. document.addEventListener("DOMContentLoaded", function () {
  3845. function checkJQuery(retryDelay) {
  3846. if (typeof jQuery === 'undefined') {
  3847. console.warn("JQuery未加载," + retryDelay + "毫秒后重试");
  3848. setTimeout(function () {
  3849. var newRetryDelay = Math.min(retryDelay * 2, 2000);
  3850. checkJQuery(newRetryDelay);
  3851. }, retryDelay);
  3852. } else {
  3853. init();
  3854. settingPanel();
  3855. checkScriptVersion();
  3856. toZH_CN();
  3857. var newElement = $("<div></div>").addClass("alert alert-info AtBetter_alert")
  3858. .html(`AtCoder Better! —— 正在等待页面资源加载……`)
  3859. var tip_SegmentedTranslation = $("<div></div>").addClass("alert alert-danger AtBetter_alert")
  3860. .html(`AtCoder Better! —— 注意!分段翻译已开启,这会造成负面效果,
  3861. <p>除非你现在需要翻译超长篇的博客或者题目,否则请前往设置关闭分段翻译</p>`)
  3862.  
  3863. async function processPage() {
  3864. if (enableSegmentedTranslation) $("#main-container").prepend(tip_SegmentedTranslation); //显示分段翻译警告
  3865. if (showJumpToLuogu && is_problem) At2luogu();
  3866.  
  3867. Promise.resolve()
  3868. .then(() => {
  3869. if (showLoading) newElement.html('AtCoder Better! —— 正在加载按钮……');
  3870. return delay(100).then(() => addConversionButton());
  3871. })
  3872. .then(() => {
  3873. if (showLoading) {
  3874. newElement.html('AtCoder Better! —— 加载已完成');
  3875. newElement.removeClass('alert-info').addClass('alert-success');
  3876. setTimeout(function () {
  3877. newElement.remove();
  3878. }, 3000);
  3879. }
  3880. })
  3881. .catch((error) => {
  3882. console.warn(error);
  3883. });
  3884. }
  3885.  
  3886. function delay(ms) {
  3887. return new Promise((resolve) => setTimeout(resolve, ms));
  3888. }
  3889.  
  3890. if (showLoading) $("#main-container").prepend(newElement);
  3891.  
  3892. if (loaded) {
  3893. processPage();
  3894. } else {
  3895. // 页面完全加载完成后执行
  3896. window.onload = function () {
  3897. processPage();
  3898. };
  3899. }
  3900. }
  3901. }
  3902. checkJQuery(50);
  3903. });
  3904.  
  3905. // 配置自动迁移代码(将在10个小版本后移除-1.19)
  3906. if (GM_getValue("openai_key") || GM_getValue("api2d_key")) {
  3907. const newConfig = { "choice": -1, "configurations": [] };
  3908. if (GM_getValue("openai_key")) {
  3909. let config1 = {
  3910. "note": "我的配置1",
  3911. "model": GM_getValue("openai_model"),
  3912. "key": GM_getValue("openai_key"),
  3913. "proxy": GM_getValue("openai_proxy"),
  3914. "_header": "",
  3915. "_data": ""
  3916. }
  3917. if (GM_getValue("translation") === "openai") newConfig.choice = 0;
  3918. newConfig.configurations.push(config1);
  3919. }
  3920. if (GM_getValue("api2d_key")) {
  3921. let config2 = {
  3922. "note": "api2d",
  3923. "model": GM_getValue("api2d_model"),
  3924. "key": GM_getValue("api2d_key"),
  3925. "proxy": GM_getValue("api2d_request_entry") + '/v1/chat/completions',
  3926. "_header": GM_getValue("x_api2d_no_cache") ? "" : " x-api2d-no-cache : 1",
  3927. "_data": ""
  3928. }
  3929. if (GM_getValue("translation") === "api2d") {
  3930. if (GM_getValue("openai_key")) newConfig.choice = 1;
  3931. else newConfig.choice = 0;
  3932. }
  3933. newConfig.configurations.push(config2);
  3934. }
  3935. GM_setValue("chatgpt-config", newConfig);
  3936. const keysToDelete = ["openai_key", "openai_model", "openai_proxy", "api2d_key", "api2d_model", "api2d_request_entry", "x_api2d_no_cache", "showOpneAiAdvanced"];
  3937. keysToDelete.forEach(key => {
  3938. if (GM_getValue(key) != undefined) GM_deleteValue(key);
  3939. });
  3940. if (GM_getValue("translation") === "api2d") GM_setValue("translation", "openai");
  3941. location.reload();
  3942. }