File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424 }
2525
2626 /**
27- * Save the updated options to storage.
27+ * Accepts a new set of options, merges them with existing options already
28+ * stored in `chrome.storage` and saves the union of both to storage.
2829 */
29- function storeOptions ( ) {
30- var showTomster = this . checked ;
30+ function storeOptions ( newOptions ) {
31+ chrome . storage . sync . get ( 'options' , function ( data ) {
32+ var options = data . options || { } ;
33+ Object . assign ( options , newOptions ) ;
34+
35+ chrome . storage . sync . set (
36+ {
37+ options : options ,
38+ } ,
39+ function optionsSaved ( ) {
40+ console . log ( 'saved!' , newOptions ) ;
41+ } ,
42+ ) ;
43+ } ) ;
44+ }
3145
32- chrome . storage . sync . set (
33- {
34- options : { showTomster : showTomster } ,
35- } ,
36- function optionsSaved ( ) {
37- console . log ( 'saved!' ) ;
38- } ,
39- ) ;
46+ /**
47+ * Save the updated Tomster setting to storage.
48+ */
49+ function saveTomsterSetting ( ) {
50+ storeOptions ( { showTomster : this . checked } ) ;
4051 }
4152
4253 document . addEventListener ( 'DOMContentLoaded' , loadOptions ) ;
4354 document
4455 . querySelector ( '[data-settings=tomster]' )
45- . addEventListener ( 'click' , storeOptions ) ;
56+ . addEventListener ( 'click' , saveTomsterSetting ) ;
4657} ) ( ) ;
You can’t perform that action at this time.
0 commit comments