Atcoder Better!

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

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

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