@@ -211,7 +211,7 @@ function getProviedTestCases(includeArray = true) {
211
211
// }
212
212
213
213
function goToVisDebug ( ) {
214
- const language = document . querySelector ( "#lang-select" ) . innerText ;
214
+ const language = getCodeLanguage ( ) ;
215
215
const supportedLanguages = [ "Python3" , "JavaScript" , "C++" ] ;
216
216
const languageMap = {
217
217
Python3 : "3" ,
@@ -345,11 +345,24 @@ int main()
345
345
) ;
346
346
}
347
347
348
+ function getCodeLanguage ( ) {
349
+ const langMap = {
350
+ "cpp" : "C++" ,
351
+ "python3" : "Python3" ,
352
+ "java" : "Java" ,
353
+ "c" : "C" ,
354
+ "javascript" : "JavaScript" ,
355
+ }
356
+ const l = window ?. monaco ?. editor ?. getModels ( ) [ 0 ] ?. getLanguageId ( ) ||
357
+ localStorage . getItem ( "global_lang" )
358
+
359
+ return langMap [ l . toLowerCase ( ) ]
360
+
361
+ }
348
362
function insertButton ( ) {
349
363
const buttons = document . querySelectorAll ( "button" ) ;
350
364
for ( var i = 0 ; i < buttons . length ; ++ i ) {
351
- if ( buttons [ i ] . innerText . includes ( "执行代码" ) ) {
352
-
365
+ if ( buttons [ i ] . innerText . includes ( "运行" ) ) {
353
366
// const container = document.createElement("div");
354
367
355
368
// buttons[i].parentElement.prepend(container);
@@ -363,18 +376,18 @@ function insertButton() {
363
376
// );
364
377
365
378
// const writeSolutionButton = document.createElement("div");
366
- const copyButton = buttons [ i ] . cloneNode ( true ) ;
367
- copyButton . innerText = "复制用例" ;
368
- copyButton . style [ "margin-left" ] = "10px" ;
369
- copyButton . onclick = ( ) => {
370
- const cases = getProviedTestCases ( ) ;
371
- if ( cases . filter ( Boolean ) . length === 0 ) return bjwd ( ) ;
372
- copyToClipboard ( cases . join ( "\n" ) ) ;
373
- message . success ( {
374
- content : "复制成功~" ,
375
- } ) ;
376
- } ;
377
- buttons [ i ] . parentElement . prepend ( copyButton ) ;
379
+ // const copyButton = buttons[i].cloneNode(true);
380
+ // copyButton.innerText = "复制用例";
381
+ // copyButton.style["margin-left"] = "10px";
382
+ // copyButton.onclick = () => {
383
+ // const cases = getProviedTestCases();
384
+ // if (cases.filter(Boolean).length === 0) return bjwd();
385
+ // copyToClipboard(cases.join("\n"));
386
+ // message.success({
387
+ // content: "复制成功~",
388
+ // });
389
+ // };
390
+ // buttons[i].parentElement.prepend(copyButton);
378
391
const writeSolutionButton = document . createElement ( "a" ) ;
379
392
writeSolutionButton . innerText = "写题解" ;
380
393
writeSolutionButton . style [ "margin-right" ] = "20px" ;
@@ -383,29 +396,25 @@ function insertButton() {
383
396
writeSolutionButton . onclick = ( ) => {
384
397
// d: "<a href="/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/">1579. 保证图可完全遍历</a>"
385
398
386
- const ele = document . querySelector ( `[data-cypress="QuestionTitle"]` ) ;
399
+ const desc = document . querySelector (
400
+ "[data-track-load=\"description_content\"]"
401
+ ) . innerHTML ;
387
402
388
- if ( ! ele ) {
403
+ if ( ! desc ) {
389
404
return message . warn ( {
390
405
content : "获取题目描述失败,请先切换到题目描述标签" ,
391
406
} ) ;
392
407
}
393
- const d = ele . innerHTML ;
394
- const title = d . match ( / ( \d + .+ ) (? = < ) / ) [ 1 ] ;
395
- const link = window . location . origin + d . match ( / h r e f = " ( .* ?) " / ) [ 1 ] ;
396
- const language = document . querySelector ( "#lang-select" ) . innerText ;
408
+ const title = document . title ;
409
+ const link = window . location . href ;
410
+ const language = getCodeLanguage ( ) ;
397
411
// let code = document.querySelector(
398
412
// ".monaco-scrollable-element,.editor-scrollable"
399
413
// ).innerText;
400
414
const code = window ?. monaco ?. editor ?. getModels ( ) [ 0 ] ?. getValue ( ) ;
401
415
402
- const desc = document . querySelector ( "#question-detail-main-tabs" )
403
- ?. children [ 1 ] ?. children [ 0 ] ?. children [ 1 ] ?. innerText ;
404
- if ( ! desc ) {
405
- return message . warn ( {
406
- content : "获取题目描述失败,请先切换到题目描述标签" ,
407
- } ) ;
408
- }
416
+ // const desc = document.querySelector("#question-detail-main-tabs")?.children[1]?.children[0]?.children[1]?.innerText;
417
+
409
418
const hide = message . loading ( "正在存储题目信息,请稍后~" , 0 ) ;
410
419
writeSolutionButton . setAttribute ( "disabled" , true ) ;
411
420
// Dismiss manually and asynchronously
@@ -478,7 +487,7 @@ function insertButton() {
478
487
buttons [ i ] . parentElement . prepend ( visDebugButton ) ;
479
488
inserted = true ;
480
489
} else if ( buttons [ i ] . innerText . includes ( "提交" ) ) {
481
- const click = buttons [ i ] . onclick
490
+ const click = buttons [ i ] . onclick ;
482
491
buttons [ i ] . onclick = ( ...args ) => {
483
492
click . call ( buttons [ i ] , ...args ) ;
484
493
@@ -518,12 +527,12 @@ const timerId = setInterval(() => {
518
527
clearInterval ( timerId ) ;
519
528
return console . error ( "初始化 chrome 插件 content script 失败" ) ;
520
529
}
521
- insertButton ( )
522
- if ( inserted && submitProxied ) {
523
- window . location . title = "" ;
524
- // 可进入禅定模式
525
- zenAble ( ) ;
526
- }
530
+ insertButton ( ) ;
531
+ // if (inserted && submitProxied) {
532
+ // window.location.title = "";
533
+ // // 可进入禅定模式
534
+ // zenAble();
535
+ // }
527
536
retried ++ ;
528
537
} , 1000 ) ;
529
538
0 commit comments