@@ -19,7 +19,6 @@ console.time();
1919var TIME = new Date ( ) . getTime ( ) ,
2020 BOOKMARKS = { } ,
2121 TAGS = { } ,
22- ALL_LOADED = false ,
2322 SEARCH = [ ] ,
2423 TABLE = {
2524 4 : document . querySelector ( '.table[data-table-index="4"]' ) ,
@@ -44,20 +43,26 @@ var TIME = new Date().getTime(),
4443
4544TABLE [ 0 ] . data = {
4645 table : [ ] ,
46+ id : 'BY_DOMAIN' ,
47+ loaded : false ,
4748 page : 1 ,
4849 column : 0 ,
4950 order_by : 'desc'
5051} ;
5152
5253TABLE [ 1 ] . data = {
5354 table : [ ] ,
55+ id : 'BY_PAGE' ,
56+ loaded : false ,
5457 page : 1 ,
5558 column : 0 ,
5659 order_by : 'desc'
5760} ;
5861
5962TABLE [ 2 ] . data = {
6063 table : [ ] ,
64+ id : 'BY_PARAM' ,
65+ loaded : false ,
6166 page : 1 ,
6267 column : 0 ,
6368 order_by : 'desc'
@@ -238,30 +243,35 @@ function initTableHeaders() {
238243 this . dataset . orderBy = this . dataset . orderBy === 'asc' ? 'desc' : 'asc' ;
239244 }
240245
241- if ( ALL_LOADED ) {
246+ if ( table . data . loaded === true ) {
242247 table . data . table = sort ( table . data . table , this . dataset . columnIndex , this . dataset . orderBy ) ;
243248
244249 renderTable ( Number ( table . dataset . tableIndex ) ) ;
245250 } else {
246- var self = this ;
247-
248- chrome . storage . local . get ( 'all' , function ( items ) {
249- ALL_LOADED = true ;
251+ var self = this ,
252+ id = table . data . id ;
253+
254+ chrome . storage . local . get ( id , function ( items ) {
255+ table . data . loaded = true ;
256+
257+ if ( id === 'BY_DOMAIN' ) {
258+ TABLE [ 0 ] . data . table = sort ( items [ 'BY_DOMAIN' ] , TABLE [ 0 ] . data . column , TABLE [ 0 ] . data . order_by ) ;
259+ } else if ( id === 'BY_PAGE' ) {
260+ for ( var i = 0 , l = items [ 'BY_PAGE' ] . length ; i < l ; i ++ ) {
261+ if ( BOOKMARKS [ 'https://' + items [ 'BY_PAGE' ] [ i ] [ 2 ] ] ) {
262+ items [ 'BY_PAGE' ] [ i ] [ 3 ] = 1 ;
263+ }
250264
251- for ( var i = 0 , l = items . all [ 1 ] . length ; i < l ; i ++ ) {
252- if ( BOOKMARKS [ 'https://' + items . all [ 1 ] [ i ] [ 2 ] ] ) {
253- items . all [ 1 ] [ i ] [ 3 ] = 1 ;
265+ if ( TAGS [ items [ 'BY_PAGE' ] [ i ] [ 2 ] ] ) {
266+ items [ 'BY_PAGE' ] [ i ] [ 4 ] = TAGS [ items [ 'BY_PAGE' ] [ i ] [ 2 ] ] ;
267+ }
254268 }
255269
256- if ( TAGS [ items . all [ 1 ] [ i ] [ 2 ] ] ) {
257- items . all [ 1 ] [ i ] [ 4 ] = TAGS [ items . all [ 1 ] [ i ] [ 2 ] ] ;
258- }
270+ TABLE [ 1 ] . data . table = sort ( items [ 'BY_PAGE' ] , TABLE [ 1 ] . data . column , TABLE [ 1 ] . data . order_by ) ;
271+ } else if ( id === 'BY_PARAM' ) {
272+ TABLE [ 2 ] . data . table = sort ( items [ 'BY_PARAM' ] , TABLE [ 2 ] . data . column , TABLE [ 2 ] . data . order_by ) ;
259273 }
260274
261- TABLE [ 0 ] . data . table = sort ( items . all [ 0 ] , TABLE [ 0 ] . data . column , TABLE [ 0 ] . data . order_by ) ;
262- TABLE [ 1 ] . data . table = sort ( items . all [ 1 ] , TABLE [ 1 ] . data . column , TABLE [ 1 ] . data . order_by ) ;
263- TABLE [ 2 ] . data . table = sort ( items . all [ 2 ] , TABLE [ 2 ] . data . column , TABLE [ 2 ] . data . order_by ) ;
264-
265275 table . data . table = sort ( table . data . table , self . dataset . columnIndex , self . dataset . orderBy ) ;
266276
267277 renderTable ( Number ( table . dataset . tableIndex ) ) ;
@@ -753,27 +763,15 @@ function renderTable(index, array) {
753763 }
754764 }
755765
756- if ( ALL_LOADED ) {
766+ if ( TABLE [ 0 ] . data . loaded ) {
757767 create ( ) ;
758768 } else {
759769 var self = this ;
760770
761- chrome . storage . local . get ( 'all ' , function ( items ) {
762- ALL_LOADED = true ;
771+ chrome . storage . local . get ( 'BY_DOMAIN ' , function ( items ) {
772+ TABLE [ 0 ] . data . loaded = true ;
763773
764- for ( var i = 0 , l = items . all [ 1 ] . length ; i < l ; i ++ ) {
765- if ( BOOKMARKS [ 'https://' + items . all [ 1 ] [ i ] [ 2 ] ] ) {
766- items . all [ 1 ] [ i ] [ 3 ] = 1 ;
767- }
768-
769- if ( TAGS [ items . all [ 1 ] [ i ] [ 2 ] ] ) {
770- items . all [ 1 ] [ i ] [ 4 ] = TAGS [ items . all [ 1 ] [ i ] [ 2 ] ] ;
771- }
772- }
773-
774- TABLE [ 0 ] . data . table = sort ( items . all [ 0 ] , TABLE [ 0 ] . data . column , TABLE [ 0 ] . data . order_by ) ;
775- TABLE [ 1 ] . data . table = sort ( items . all [ 1 ] , TABLE [ 1 ] . data . column , TABLE [ 1 ] . data . order_by ) ;
776- TABLE [ 2 ] . data . table = sort ( items . all [ 2 ] , TABLE [ 2 ] . data . column , TABLE [ 2 ] . data . order_by ) ;
774+ TABLE [ 0 ] . data . table = sort ( items [ 'BY_DOMAIN' ] , TABLE [ 0 ] . data . column , TABLE [ 0 ] . data . order_by ) ;
777775
778776 create ( ) ;
779777 } ) ;
@@ -848,7 +846,7 @@ function renderTable(index, array) {
848846 }
849847
850848 button . addEventListener ( 'click' , function ( ) {
851- if ( ALL_LOADED ) {
849+ if ( TABLE [ index ] . data . loaded ) {
852850 var prev = this . parentNode . querySelector ( '.selected' ) ;
853851
854852 this . parentNode . parentNode . data . page = Number ( this . innerText ) ;
@@ -861,25 +859,30 @@ function renderTable(index, array) {
861859
862860 renderTable ( Number ( this . parentNode . parentNode . dataset . tableIndex ) ) ;
863861 } else {
864- var self = this ;
865-
866- chrome . storage . local . get ( 'all' , function ( items ) {
867- ALL_LOADED = true ;
868-
869- for ( var i = 0 , l = items . all [ 1 ] . length ; i < l ; i ++ ) {
870- if ( BOOKMARKS [ 'https://' + items . all [ 1 ] [ i ] [ 2 ] ] ) {
871- items . all [ 1 ] [ i ] [ 3 ] = 1 ;
862+ var self = this ,
863+ id = TABLE [ index ] . data . id ;
864+
865+ chrome . storage . local . get ( id , function ( items ) {
866+ TABLE [ index ] . data . loaded = true ;
867+
868+ if ( id === 'BY_DOMAIN' ) {
869+ TABLE [ 0 ] . data . table = sort ( items [ 'BY_DOMAIN' ] , TABLE [ 0 ] . data . column , TABLE [ 0 ] . data . order_by ) ;
870+ } else if ( id === 'BY_PAGE' ) {
871+ for ( var i = 0 , l = items [ 'BY_PAGE' ] . length ; i < l ; i ++ ) {
872+ if ( BOOKMARKS [ 'https://' + items [ 'BY_PAGE' ] [ i ] [ 2 ] ] ) {
873+ items [ 'BY_PAGE' ] [ i ] [ 3 ] = 1 ;
874+ }
875+
876+ if ( TAGS [ items [ 'BY_PAGE' ] [ i ] [ 2 ] ] ) {
877+ items [ 'BY_PAGE' ] [ i ] [ 4 ] = TAGS [ items [ 'BY_PAGE' ] [ i ] [ 2 ] ] ;
878+ }
872879 }
873880
874- if ( TAGS [ items . all [ 1 ] [ i ] [ 2 ] ] ) {
875- items . all [ 1 ] [ i ] [ 4 ] = TAGS [ items . all [ 1 ] [ i ] [ 2 ] ] ;
876- }
881+ TABLE [ 1 ] . data . table = sort ( items [ 'BY_PAGE' ] , TABLE [ 1 ] . data . column , TABLE [ 1 ] . data . order_by ) ;
882+ } else if ( id === 'BY_PARAM' ) {
883+ TABLE [ 2 ] . data . table = sort ( items [ 'BY_PARAM' ] , TABLE [ 2 ] . data . column , TABLE [ 2 ] . data . order_by ) ;
877884 }
878885
879- TABLE [ 0 ] . data . table = sort ( items . all [ 0 ] , TABLE [ 0 ] . data . column , TABLE [ 0 ] . data . order_by ) ;
880- TABLE [ 1 ] . data . table = sort ( items . all [ 1 ] , TABLE [ 1 ] . data . column , TABLE [ 1 ] . data . order_by ) ;
881- TABLE [ 2 ] . data . table = sort ( items . all [ 2 ] , TABLE [ 2 ] . data . column , TABLE [ 2 ] . data . order_by ) ;
882-
883886 var prev = self . parentNode . querySelector ( '.selected' ) ;
884887
885888 self . parentNode . parentNode . data . page = Number ( self . innerText ) ;
0 commit comments