1+ var defaultOptions =
2+ {
3+ allow_quote :'1' ,
4+ allow_code :'0' ,
5+ splow_quote :'1' ,
6+ splow_code :'0' ,
7+ splow_outp :'1' ,
8+ spl_qopen :'0' ,
9+ spl_qsz :'20' ,
10+ spl_qxsz :'35' ,
11+ spl_copen :'1' ,
12+ spl_csz :'20' ,
13+ spl_popen :'0' ,
14+ spl_psz :'20'
15+ } ;
16+
17+ function Save ( ) {
18+ var localOptions = { } ;
19+ for ( var k in defaultOptions )
20+ {
21+ if ( ! defaultOptions . hasOwnProperty ( k ) )
22+ continue ; // trashy stuff
23+ var numericDefault = parseInt ( defaultOptions [ k ] ) ;
24+ if ( isNaN ( numericDefault ) )
25+ continue ; // trashy stuff #2
26+ var numericItem ;
27+ if ( numericDefault > 1 )
28+ numericItem = document . getElementById ( k ) . value ;
29+ else
30+ numericItem = document . getElementById ( k ) . checked ?1 :0 ;
31+ localOptions [ k ] = numericItem ;
32+ }
33+ chrome . storage . sync . set ( localOptions ,
34+ function ( ) {
35+ var targetStatus = document . getElementById ( 'status' ) ;
36+ targetStatus . textContent = 'Options Saved.'
37+ setTimeout ( function ( ) { targetStatus . textContent = '' ; } , 1500 ) ;
38+ } ) ;
39+ }
40+ function Load ( ) {
41+ chrome . storage . sync . get ( defaultOptions ,
42+ function ( items ) {
43+ for ( var k in items )
44+ {
45+ if ( ! defaultOptions . hasOwnProperty ( k ) )
46+ continue ; // unknown option
47+ var numericDefault = parseInt ( defaultOptions [ k ] ) ;
48+ if ( isNaN ( numericDefault ) )
49+ continue ; // shouldn't happen
50+ var numericItem = parseInt ( items [ k ] ) ;
51+ if ( isNaN ( numericItem ) )
52+ numericItem = numericDefault ; // invalid stored option. load fallback.
53+
54+ if ( numericDefault > 1 )
55+ document . getElementById ( k ) . value = numericItem ;
56+ else
57+ document . getElementById ( k ) . checked = ( numericItem != 0 ) ?1 :0 ;
58+ }
59+ } ) ;
60+ }
61+ document . addEventListener ( 'DOMContentLoaded' , Load ) ;
62+ document . getElementById ( 'save' ) . addEventListener ( 'click' , Save ) ;
0 commit comments