@@ -105,11 +105,6 @@ function initContext() {
105105 context . bindType = item . bindType || { } ;
106106 context . bindPattern = item . bindPattern || { } ;
107107 context . bindConfig = item . bindConfig || { } ;
108- context . config = context . bindConfig [ id ] || { } ;
109- context . config . filetype = context . config . filetype || context . bindType [ id ] || '.gs' ;
110- context . config . ignorePattern = context . config . ignorePattern || context . bindPattern [ id ] || [ ] ;
111- context . config . manifestEnabled = context . config . manifestEnabled || false ;
112- context . gist = context . bindRepo [ id ] && context . bindRepo [ id ] . gist ;
113108 resolve ( scm ) ;
114109 } ) ;
115110 } )
@@ -125,7 +120,7 @@ function initContext() {
125120 $ ( '#repo-owner-list' ) . append ( content ) ;
126121 if ( first ) {
127122 $ ( '#selected-repo-owner' ) . text ( owner ) ;
128- first = false ;
123+ first = false ;
129124 }
130125 } ) ;
131126 return scm ;
@@ -254,9 +249,19 @@ function initPageEvent() {
254249 } )
255250
256251 $ ( document ) . on ( 'click' , '#config-button' , ( ) => {
257- $ ( '#filetype' ) . text ( context . config . filetype ) ;
258- $ ( '#manage-manifest' ) . prop ( "checked" , context . config . manifestEnabled ) ;
259- $ ( '#ignore-pattern' ) . val ( context . config . ignorePattern . join ( ';' ) ) ;
252+ let config = getConfig ( ) ;
253+ if ( ! config ) {
254+ config = {
255+ filetype : '.gs' ,
256+ ignorePattern : [ ] ,
257+ manifestEnabled : true ,
258+ }
259+ }
260+ if ( config ) {
261+ $ ( '#selected-suffix' ) . text ( config . filetype ) ;
262+ $ ( '#manage-manifest' ) . prop ( "checked" , config . manifestEnabled ) ;
263+ $ ( '#ignore-pattern' ) . val ( config . ignorePattern . join ( ';' ) ) ;
264+ }
260265 changeModalState ( 'config' , true ) ;
261266 } ) ;
262267
@@ -274,10 +279,12 @@ function initPageEvent() {
274279 } )
275280
276281 $ ( document ) . on ( 'click' , '#save-config' , ( ) => {
277- context . config . filetype = $ ( '#filetype' ) . text ( ) ;
278- context . config . manifestEnabled = $ ( '#manage-manifest' ) . prop ( "checked" ) ;
279- context . config . ignorePattern = $ ( '#ignore-pattern' ) . val ( ) . split ( ';' ) . filter ( p => p !== '' ) ;
280- context . bindConfig [ getId ( ) ] = context . config ;
282+ const config = {
283+ filetype : $ ( '#selected-suffix' ) . text ( ) ,
284+ manifestEnabled : $ ( '#manage-manifest' ) . prop ( "checked" ) ,
285+ ignorePattern : $ ( '#ignore-pattern' ) . val ( ) . split ( ';' ) . filter ( p => p !== '' )
286+ }
287+ context . bindConfig [ getId ( ) ] = config ;
281288 try {
282289 chrome . storage . sync . set ( {
283290 bindConfig : context . bindConfig
@@ -298,25 +305,22 @@ function initPageEvent() {
298305 let label ;
299306 switch ( type ) {
300307 case 'repo' :
301- if ( getRepo ( ) && target . attr ( 'data' ) === context . repo . fullName ) return ;
302- //update context.repo with name and fullName
308+ if ( getRepo ( ) && target . attr ( 'data' ) === getRepo ( ) . fullName ) return ;
303309 const fullName = target . attr ( 'data' ) ;
304310 content = {
305311 fullName : fullName ,
306312 gist : fullName === 'gist'
307313 }
308314 label = fullName ;
309- context . gist = content . gist ;
310315 break ;
311316 case 'branch' :
312- if ( context [ type ] && target . text ( ) === context [ type ] ) return ;
317+ if ( getBranch ( ) && target . text ( ) === getBranch ( ) ) return ;
313318 content = target . attr ( 'data' ) ;
314319 label = target . attr ( 'data' ) ;
315320 break ;
316321 default :
317322 return ;
318323 }
319- context [ type ] = content ;
320324 const bindName = `bind${ type . capitalize ( ) } ` ;
321325 Object . assign ( context [ bindName ] , {
322326 [ getId ( ) ] : content
@@ -378,14 +382,15 @@ function showDiff(code, type) {
378382 } )
379383 . concat ( gasFiles )
380384 . filter ( file => {
381- if ( context . config . manifestEnabled && file === 'appsscript.json' ) {
385+ const config = getConfig ( ) ;
386+ if ( config . manifestEnabled && file === 'appsscript.json' ) {
382387 return true ;
383388 }
384- for ( let i = 0 ; i < context . config . ignorePattern . length ; i ++ ) {
385- let p = new RegExp ( context . config . ignorePattern [ i ] ) ;
386- if ( p . test ( file ) ) return false ;
389+ for ( let i = 0 ; i < config . ignorePattern . length ; i ++ ) {
390+ let p = new RegExp ( svconfig . ignorePattern [ i ] ) ;
391+ if ( svp . test ( file ) ) return false ;
387392 }
388- const regex = new RegExp ( `(.*?)(${ context . config . filetype } |\.html)$` )
393+ const regex = new RegExp ( `(.*?)(${ context . bindConfig [ getId ( ) ] . filetype } |\.html)$` )
389394 const match = file . match ( regex ) ;
390395 return match && match [ 1 ] && match [ 2 ] ;
391396 } )
@@ -434,7 +439,7 @@ function showDiff(code, type) {
434439 $ ( '#scm-diff-handler' ) . prop ( 'disabled' , true ) ;
435440 $ ( '.scm-comment' ) . hide ( ) ;
436441 } else {
437- if ( type === 'push' && ! context . gist ) { //push to repo must have commit comment
442+ if ( type === 'push' && ! isGist ( ) ) { //push to repo must have commit comment
438443 $ ( '.scm-comment' ) . show ( ) ;
439444 $ ( '.gist-desc' ) . hide ( ) ;
440445 $ ( '#scm-diff-handler' ) . prop ( 'disabled' , true ) ;
@@ -472,18 +477,16 @@ function updateRepo(repos) {
472477 $ ( '.repo-menu' ) . append ( content ) ;
473478 } ) ;
474479 showLog ( "Repository updated" ) ;
475- if ( context . repo ) {
476- $ ( '#scm-bind-repo' ) . text ( context . repo . fullName ) ;
477-
478- //highlight current repo in repos list
479- // $(`[data="${context.repo.fullName}"]`).css('background-color', 'lightgray');
480- return context . repo . fullName ;
480+ const repo = getRepo ( ) ;
481+ if ( repo ) {
482+ $ ( '#scm-bind-repo' ) . text ( repo . fullName ) ;
483+ return repo . fullName ;
481484 }
482485 return null ;
483486}
484487
485488function updateGist ( ) {
486- if ( ! context . gist ) {
489+ if ( ! isGist ( ) ) {
487490 return null ;
488491 }
489492 return scm . getAllGists ( )
@@ -500,7 +503,6 @@ function updateGist() {
500503 }
501504 $ ( '#scm-bind-branch' ) . text ( gist ) ;
502505 //update context and storage
503- context . branch = gist ;
504506 Object . assign ( context . bindBranch , {
505507 [ getId ( ) ] : gist
506508 } ) ;
@@ -512,7 +514,7 @@ function updateGist() {
512514}
513515
514516function updateBranch ( ) {
515- if ( ! context . repo || context . gist ) {
517+ if ( ! getRepo ( ) || isGist ( ) ) {
516518 return null ;
517519 }
518520 return scm . getAllBranches ( )
@@ -535,7 +537,6 @@ function updateBranch() {
535537 }
536538 $ ( '#scm-bind-branch' ) . text ( branch ) ;
537539 //update context and storage
538- context . branch = branch ;
539540 Object . assign ( context . bindBranch , {
540541 [ getId ( ) ] : branch
541542 } ) ;
0 commit comments