@@ -340,7 +340,8 @@ int main()
340
340
window . open (
341
341
`https://pythontutor.com/visualize.html#code=${ encodeURIComponent (
342
342
code
343
- ) } &cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=${ languageMap [ language ]
343
+ ) } &cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=${
344
+ languageMap [ language ]
344
345
} &rawInputLstJSON=%5B%5D&textReferences=false`
345
346
) ;
346
347
}
@@ -360,9 +361,19 @@ function getCodeLanguage() {
360
361
361
362
}
362
363
function insertButton ( ) {
364
+ const customBtnStyle = {
365
+ "line-height" : "1" ,
366
+ cursor : "pointer" ,
367
+ "vertical-align" : "text-top" ,
368
+ } ;
363
369
const buttons = document . querySelectorAll ( "button" ) ;
370
+
364
371
for ( var i = 0 ; i < buttons . length ; ++ i ) {
365
372
if ( buttons [ i ] . innerText . includes ( "运行" ) ) {
373
+
374
+ // 停止观察器
375
+ // observer.disconnect();
376
+
366
377
// const container = document.createElement("div");
367
378
368
379
// buttons[i].parentElement.prepend(container);
@@ -390,8 +401,8 @@ function insertButton() {
390
401
// buttons[i].parentElement.prepend(copyButton);
391
402
const writeSolutionButton = document . createElement ( "a" ) ;
392
403
writeSolutionButton . innerText = "写题解" ;
393
- writeSolutionButton . style [ "margin-right" ] = "20px" ;
394
- writeSolutionButton . style [ "line-height" ] = "32px" ;
404
+ Object . assign ( writeSolutionButton . style , customBtnStyle ) ;
405
+ writeSolutionButton . className = buttons [ i ] . className ;
395
406
396
407
writeSolutionButton . onclick = ( ) => {
397
408
// d: "<a href="/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/">1579. 保证图可完全遍历</a>"
@@ -474,17 +485,17 @@ function insertButton() {
474
485
475
486
// ReactDOM.render(<SolutionButton />, writeSolutionButton);
476
487
477
- buttons [ i ] . parentElement . prepend ( writeSolutionButton ) ;
488
+ buttons [ i ] . parentElement . parentElement . prepend ( writeSolutionButton ) ;
478
489
// ele.appendChild(writeSolutionButton);
479
490
480
491
const visDebugButton = document . createElement ( "a" ) ;
481
492
visDebugButton . innerText = "可视化调试" ;
482
- visDebugButton . style [ "margin-right" ] = "20px" ;
483
- visDebugButton . style [ "line-height" ] = "32px" ;
493
+ Object . assign ( visDebugButton . style , customBtnStyle ) ;
494
+ visDebugButton . className = buttons [ i ] . className ;
484
495
485
496
visDebugButton . onclick = goToVisDebug ;
486
497
487
- buttons [ i ] . parentElement . prepend ( visDebugButton ) ;
498
+ buttons [ i ] . parentElement . parentElement . prepend ( visDebugButton ) ;
488
499
inserted = true ;
489
500
} else if ( buttons [ i ] . innerText . includes ( "提交" ) ) {
490
501
const click = buttons [ i ] . onclick ;
@@ -500,18 +511,17 @@ function insertButton() {
500
511
// 300 times means 30s
501
512
if ( tries > 300 ) return ;
502
513
tries ++ ;
503
- } , 100 )
504
- }
505
-
514
+ } , 100 ) ;
515
+ } ;
506
516
507
- submitProxied = true
517
+ submitProxied = true ;
508
518
}
509
519
}
510
520
return false ;
511
521
}
512
522
let inserted = false ;
513
523
let retried = 0 ;
514
- let submitProxied = false
524
+ let submitProxied = false ;
515
525
const MAX_TRY = 10 ;
516
526
517
527
// 去除智能提示
@@ -521,13 +531,15 @@ const MAX_TRY = 10;
521
531
// visibility: hidden !important;
522
532
// }
523
533
// `);
534
+
524
535
const timerId = setInterval ( ( ) => {
525
536
if ( inserted && submitProxied ) return clearInterval ( timerId ) ;
526
537
if ( retried > MAX_TRY ) {
527
538
clearInterval ( timerId ) ;
528
539
return console . error ( "初始化 chrome 插件 content script 失败" ) ;
529
540
}
530
541
insertButton ( ) ;
542
+
531
543
// if (inserted && submitProxied) {
532
544
// window.location.title = "";
533
545
// // 可进入禅定模式
@@ -552,9 +564,6 @@ const timerId = setInterval(() => {
552
564
553
565
// ReactDOM.render(<Main />, app);
554
566
555
-
556
-
557
-
558
567
// history.pushState = (f => function pushState() {
559
568
// var ret = f.apply(this, arguments);
560
569
// window.dispatchEvent(new Event('pushstate'));
@@ -579,4 +588,4 @@ const timerId = setInterval(() => {
579
588
// if (url.endsWith("submissions/")) {
580
589
581
590
// }
582
- // })
591
+ // })
0 commit comments