@@ -5,8 +5,8 @@ let currentUrl;
5
5
let gas ;
6
6
let scm ;
7
7
let context = { } ;
8
- const LEVEL_ERROR = 'Warning ' ;
9
- const LEVEL_WARN = 'Info ' ;
8
+ const LEVEL_ERROR = 'Error ' ;
9
+ const LEVEL_WARN = 'Warn ' ;
10
10
const LEVEL_INFO = 'Notice' ;
11
11
const observer = new MutationObserver ( ( e ) => {
12
12
let url = window . location . href ;
@@ -57,10 +57,6 @@ function load() {
57
57
break ;
58
58
case 'nothing' :
59
59
break ;
60
- case 'need relogin' :
61
- initLoginContent ( ) ;
62
- showLog ( 'Extension has been updated, please relogin' , LEVEL_WARN ) ;
63
- break ;
64
60
default :
65
61
showLog ( err , LEVEL_ERROR ) ;
66
62
break ;
@@ -351,14 +347,19 @@ function auth() {
351
347
context . gapiToken = token ;
352
348
chrome . storage . sync . set ( {
353
349
"gapiToken" : token
354
- } ) ;
350
+ } ) ;
355
351
resolve ( token ) ;
356
352
}
357
353
} ) ;
358
354
} ) ;
359
355
}
360
356
361
357
function prepareCode ( ) {
358
+ if ( ! getRepo ( ) ) {
359
+ return new Promise ( ( resolve , reject ) => {
360
+ reject ( new Error ( "Repository is not set" ) ) ;
361
+ } )
362
+ }
362
363
return Promise . all ( [ gas . getGasCode ( ) , scm . getCode ( ) ] )
363
364
. then ( ( data ) => {
364
365
return {
@@ -370,7 +371,7 @@ function prepareCode() {
370
371
371
372
function showDiff ( code , type ) {
372
373
if ( Object . keys ( code . scm ) . length === 0 && type === 'pull' ) {
373
- showLog ( 'There is nothing to pull' , LEVEL_WARN ) ;
374
+ showLog ( 'There is nothing to pull' , LEVEL_INFO ) ;
374
375
return ;
375
376
}
376
377
//setting the diff model
@@ -417,7 +418,7 @@ function showDiff(code, type) {
417
418
} , '' ) ;
418
419
419
420
if ( diff === '' ) {
420
- showLog ( 'Everything already up-to-date' , LEVEL_WARN ) ;
421
+ showLog ( 'Everything already up-to-date' , LEVEL_INFO ) ;
421
422
return ;
422
423
}
423
424
@@ -529,7 +530,7 @@ function updateBranch() {
529
530
if ( branches . length === 0 ) {
530
531
branch = '' ;
531
532
if ( scm . name === 'github' ) {
532
- showLog ( 'This repository is empty, try to create a new branch such as [master ] in Github' , LEVEL_WARN ) ;
533
+ showLog ( 'This repository is empty, try to create a new branch such as [main ] in Github' , LEVEL_WARN ) ;
533
534
} else {
534
535
showLog ( 'This repository is empty, first create a new branch' , LEVEL_WARN ) ;
535
536
}
@@ -621,9 +622,16 @@ function showLog(message, level = LEVEL_INFO) {
621
622
622
623
$ . get ( chrome . runtime . getURL ( 'content/alert.html' ) )
623
624
. then ( ( content ) => {
625
+ const colorClass = level == LEVEL_ERROR ? "nN3Fac" : "ptNZqd" ;
624
626
$ ( "[jsname=cFQkCb]" ) . removeClass ( "LcqFFc" ) ;
625
- $ ( "[jsname=cFQkCb] > [jsname=NR4lfb]" ) . css ( "flex-basis" , "150px" )
626
- $ ( '.Vod31b' ) . html ( content . replace ( / _ T I M E S T A M P _ / g, new Date ( ) . toLocaleTimeString ( ) ) . replace ( / _ L E V E L _ / g, level ) . replace ( / _ M E S S A G E _ / , message ) ) ;
627
+ const currentOffset = $ ( "[jsname=cFQkCb] > [jsname=NR4lfb]" ) . css ( "flex-basis" ) ;
628
+ const offset = ( currentOffset === "0px" || currentOffset === "auto" ) ? "150px" : currentOffset ;
629
+ $ ( "[jsname=cFQkCb] > [jsname=NR4lfb]" ) . css ( "flex-basis" , offset ) ;
630
+ $ ( '.Vod31b' ) . html ( content
631
+ . replace ( / _ C O L O R _ C L A S S _ / , colorClass )
632
+ . replace ( / _ T I M E S T A M P _ / g, new Date ( ) . toLocaleTimeString ( ) )
633
+ . replace ( / _ L E V E L _ / g, level )
634
+ . replace ( / _ M E S S A G E _ / , message ) ) ;
627
635
} )
628
636
}
629
637
0 commit comments