@@ -4,6 +4,11 @@ let inter = null;
44
55chrome . runtime . onMessage . addListener ( function ( request , sender , sendResponse ) {
66 if ( request . message === "start" ) {
7+ if ( Object . keys ( request . answer_key ) . length === 0 ) {
8+ toast ( "Please enter the answer key" , "error" ) ;
9+ return ;
10+ }
11+
712 attempt ( request . answer_key , request . time ) ;
813 } else if ( request . message === "stop" ) {
914 stopAttempt ( ) ;
@@ -15,12 +20,14 @@ const attempt = (ans_key, time) => {
1520 const len = ans . length ;
1621 let i = 0 ;
1722
23+ toast ( "Started attempting the test" ) ;
1824 function attemptQuestion ( ) {
1925 document . querySelector ( `#${ ans [ i ] } _${ i + 1 } ` ) . click ( ) ;
2026 document . querySelector ( "#main_div > div.tableWidthPercent > div.onlineTestLeftDiv > div.qnav > span.saveNextButton > a" ) . click ( ) ;
2127 i ++ ;
2228
2329 if ( i === len ) {
30+ toast ( "Finished attempting the test" ) ;
2431 clearInterval ( inter ) ;
2532 document . querySelector ( '#activator' ) . click ( ) ;
2633 document . querySelector ( 'input[name="rd"][value="Y"]' ) . click ( ) ;
@@ -36,6 +43,30 @@ const attempt = (ans_key, time) => {
3643function stopAttempt ( ) {
3744 if ( inter ) {
3845 clearInterval ( inter ) ;
39- console . log ( "Stopped the attempt " ) ;
46+ toast ( "Stopped attempting the test " ) ;
4047 }
48+ }
49+
50+ function toast ( message , type = "success" ) {
51+ const div = document . createElement ( "div" ) ;
52+ div . id = "toast" ;
53+ const text = document . createTextNode ( message ) ;
54+ div . appendChild ( text ) ;
55+ const styleList = [
56+ 'background-color: ' + ( type === 'success' ? '#350054' : '#ff0000' ) ,
57+ 'color: ' + ( type === 'success' ? '#fff' : '#fff' ) ,
58+ ] ;
59+ div . style . cssText = styleList . join ( ";" ) ;
60+ document . body . appendChild ( div ) ;
61+ setTimeout ( ( ) => {
62+ div . style . opacity = "1" ;
63+ div . style . transform = "translateY(0)" ;
64+ } , 1 ) ;
65+ setTimeout ( ( ) => {
66+ div . style . opacity = "0" ;
67+ div . style . transform = "translateY(-100%)" ;
68+ setTimeout ( ( ) => {
69+ document . body . removeChild ( div ) ;
70+ } , 500 ) ;
71+ } , 2000 ) ;
4172}
0 commit comments