@@ -12,6 +12,7 @@ import {
12
12
// addStyle,
13
13
} from "./utils" ;
14
14
import zenAble from "./zen/zenMode" ;
15
+ import hideFailCases from "./submission/hideFailCases" ;
15
16
16
17
// WTF! ant message didn't go well with chrome extension?
17
18
const message = {
@@ -339,8 +340,7 @@ int main()
339
340
window . open (
340
341
`https://pythontutor.com/visualize.html#code=${ encodeURIComponent (
341
342
code
342
- ) } &cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=${
343
- languageMap [ language ]
343
+ ) } &cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=${ languageMap [ language ]
344
344
} &rawInputLstJSON=%5B%5D&textReferences=false`
345
345
) ;
346
346
}
@@ -349,6 +349,7 @@ function insertButton() {
349
349
const buttons = document . querySelectorAll ( "button" ) ;
350
350
for ( var i = 0 ; i < buttons . length ; ++ i ) {
351
351
if ( buttons [ i ] . innerText . includes ( "执行代码" ) ) {
352
+
352
353
// const container = document.createElement("div");
353
354
354
355
// buttons[i].parentElement.prepend(container);
@@ -475,13 +476,33 @@ function insertButton() {
475
476
visDebugButton . onclick = goToVisDebug ;
476
477
477
478
buttons [ i ] . parentElement . prepend ( visDebugButton ) ;
478
- return true ;
479
+ inserted = true ;
480
+ } else if ( buttons [ i ] . innerText . includes ( "提交" ) ) {
481
+ const click = buttons [ i ] . onclick
482
+ buttons [ i ] . onclick = ( ...args ) => {
483
+ click . call ( buttons [ i ] , ...args ) ;
484
+
485
+ // try to hide failed test cases
486
+ let tries = 0 ;
487
+ const hideFailCasesJob = setInterval ( ( ) => {
488
+ if ( hideFailCases ( ) ) {
489
+ clearInterval ( hideFailCasesJob ) ;
490
+ }
491
+ // 300 times means 30s
492
+ if ( tries > 300 ) return ;
493
+ tries ++ ;
494
+ } , 100 )
495
+ }
496
+
497
+
498
+ submitProxied = true
479
499
}
480
500
}
481
501
return false ;
482
502
}
483
503
let inserted = false ;
484
504
let retried = 0 ;
505
+ let submitProxied = false
485
506
const MAX_TRY = 10 ;
486
507
487
508
// 去除智能提示
@@ -492,14 +513,14 @@ const MAX_TRY = 10;
492
513
// }
493
514
// `);
494
515
const timerId = setInterval ( ( ) => {
495
- if ( inserted ) return clearInterval ( timerId ) ;
516
+ if ( inserted && submitProxied ) return clearInterval ( timerId ) ;
496
517
if ( retried > MAX_TRY ) {
497
518
clearInterval ( timerId ) ;
498
519
return console . error ( "初始化 chrome 插件 content script 失败" ) ;
499
520
}
500
- if ( insertButton ( ) ) {
521
+ insertButton ( )
522
+ if ( inserted && submitProxied ) {
501
523
window . location . title = "" ;
502
- inserted = true ;
503
524
// 可进入禅定模式
504
525
zenAble ( ) ;
505
526
}
@@ -521,3 +542,32 @@ const timerId = setInterval(() => {
521
542
// document.body.appendChild(app);
522
543
523
544
// ReactDOM.render(<Main />, app);
545
+
546
+
547
+
548
+
549
+ // history.pushState = (f => function pushState() {
550
+ // var ret = f.apply(this, arguments);
551
+ // window.dispatchEvent(new Event('pushstate'));
552
+ // window.dispatchEvent(new Event('locationchange'));
553
+ // return ret;
554
+ // })(history.pushState);
555
+
556
+ // history.replaceState = (f => function replaceState() {
557
+ // var ret = f.apply(this, arguments);
558
+ // window.dispatchEvent(new Event('replacestate'));
559
+ // window.dispatchEvent(new Event('locationchange'));
560
+ // return ret;
561
+ // })(history.replaceState);
562
+
563
+ // window.addEventListener('popstate', () => {
564
+ // window.dispatchEvent(new Event('locationchange'))
565
+ // });
566
+
567
+ // window.addEventListener('locationchange', function (e) {
568
+ // const url = e.target.location.href;
569
+ // console.log('hideFailCases')
570
+ // if (url.endsWith("submissions/")) {
571
+
572
+ // }
573
+ // })
0 commit comments