diff options
Diffstat (limited to 'options.js')
| -rw-r--r-- | options.js | 32 | 
1 files changed, 32 insertions, 0 deletions
| diff --git a/options.js b/options.js new file mode 100644 index 0000000..ce07520 --- /dev/null +++ b/options.js @@ -0,0 +1,32 @@ +// Saves options to chrome.storage +function save_options() { +  var color = document.getElementById('color').value; +  var likesColor = document.getElementById('like').checked; +  chrome.storage.sync.set({ +    favoriteColor: color, +    likesColor: likesColor +  }, function() { +    // Update status to let user know options were saved. +    var status = document.getElementById('status'); +    status.textContent = 'Options saved.'; +    setTimeout(function() { +      status.textContent = ''; +    }, 750); +  }); +} + +// Restores select box and checkbox state using the preferences +// stored in chrome.storage. +function restore_options() { +  // Use default value color = 'red' and likesColor = true. +  chrome.storage.sync.get({ +    favoriteColor: 'red', +    likesColor: true +  }, function(items) { +    document.getElementById('color').value = items.favoriteColor; +    document.getElementById('like').checked = items.likesColor; +  }); +} +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', +    save_options);
\ No newline at end of file | 
