1
+ chrome . storage . sync . get ( 'problemset' , function ( data ) {
2
+ // if option disabled, return, else inject script
3
+ if ( ! data . problemset ) {
4
+ return ;
5
+ }
6
+
7
+ // global page constants
8
+ const contestURL = $ ( '#sidebar th a' ) . attr ( 'href' ) ; // '/contest/<no.>'
9
+ const probLetter = $ ( '.header > .title' ) . text ( ) [ 0 ] ;
10
+
11
+ // add all submissions tab to the menu
12
+ const tab = $ ( '.second-level-menu-list' ) [ 0 ] . lastElementChild ;
13
+ const allSubmissions = $ ( tab ) . clone ( true ) [ 0 ] ;
14
+ const allSubmissionsURL = contestURL + '/status/' + probLetter ;
15
+ $ ( 'a' , allSubmissions ) . text ( 'all submissions' ) ;
16
+ $ ( 'a' , allSubmissions ) . attr ( 'href' , allSubmissionsURL ) ;
17
+ tab . after ( allSubmissions ) ;
18
+
19
+ // add star favourite problem icon
20
+ const starContest = $ ( '#sidebar > div:nth-child(1) > table > tbody > tr:last-child' ) ;
21
+ $ ( '> td > span > center > span > img' , starContest ) . attr ( 'alt' , 'Add contest to favourites' ) ;
22
+ $ ( '> td > span > center > span > img' , starContest ) . attr ( 'title' , 'Add contest to favourites' ) ;
23
+
24
+ const starProblem = $ ( ( '<tr><td class="left bottom" colspan="1"><span class="contest-state-regular">Problem: <span id="put"></span></span></td></tr>' ) ) ;
25
+ $ ( starContest ) . after ( starProblem ) ;
26
+
27
+ // make selector to get probem-star
28
+ const row = probLetter . charCodeAt ( 0 ) - 65 + 2 ;
29
+ const selector = "#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(" + String ( row ) + ") span:nth-child(2) > span >img"
30
+ const url = contestURL + ' ' + selector ;
31
+
32
+ $ ( "#put" ) . load ( url , function ( ) {
33
+ const star = $ ( '#put' ) [ 0 ] . childNodes [ 0 ] ;
34
+
35
+ } ) ;
36
+ } ) ;
0 commit comments