Skip to content

Instantly share code, notes, and snippets.

@cheesinglee
Created September 1, 2014 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheesinglee/1a84c5d97253c0660353 to your computer and use it in GitHub Desktop.
Save cheesinglee/1a84c5d97253c0660353 to your computer and use it in GitHub Desktop.
// Saves options to chrome.storage
function save_options() {
var username = document.getElementById('username').value;
var apikey = document.getElementById('apikey').value;
chrome.storage.sync.set({
username: username,
apikey: apikey
}, function() {
// Update status to let user know options were saved.
chrome.runtime.sendMessage({greeting:"fetchmodel"}) ;
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({
username: 'BigML Username',
apikey: 'BigML API Key'
}, function(items) {
document.getElementById('username').value = items.username;
document.getElementById('apikey').value = items.apikey;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment