From 5e42f11675bb301a4f9329e8e5d50ec136e6f0df Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 14:13:42 -0400 Subject: Update options page * Copy sample code from the docs http://developer.chrome.com/extensions/options * Include Chrome UI Bootstrap CSS https://github.com/roykolak/chrome-bootstrap --- options.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 options.js (limited to 'options.js') 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 -- cgit v1.2.3 From 949c5d450519983939bc9f119e6a9f3c6e82d19b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 14:47:42 -0400 Subject: options.js: convert spaces to tabs --- options.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'options.js') diff --git a/options.js b/options.js index ce07520..3d3ac29 100644 --- a/options.js +++ b/options.js @@ -1,32 +1,33 @@ // 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); - }); + 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; - }); + // 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 +save_options); \ No newline at end of file -- cgit v1.2.3 From 859fc43f1156e2adfbe1580de7a9ba5728818760 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 15:08:47 -0400 Subject: Store options & load values from storage --- options.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'options.js') diff --git a/options.js b/options.js index 3d3ac29..23bb4c5 100644 --- a/options.js +++ b/options.js @@ -1,10 +1,10 @@ // Saves options to chrome.storage function save_options() { - var color = document.getElementById('color').value; - var likesColor = document.getElementById('like').checked; + var button_click_behaviour = document.getElementById('button-click-behaviour').value; + var file_format = document.getElementById('file-format').value; chrome.storage.sync.set({ - favoriteColor: color, - likesColor: likesColor + button_click_behaviour: button_click_behaviour, + file_format: file_format }, function() { // Update status to let user know options were saved. var status = document.getElementById('status'); @@ -20,11 +20,11 @@ function save_options() { function restore_options() { // Use default value color = 'red' and likesColor = true. chrome.storage.sync.get({ - favoriteColor: 'red', - likesColor: true + button_click_behaviour: 'window', + file_format: 'text' }, function(items) { - document.getElementById('color').value = items.favoriteColor; - document.getElementById('like').checked = items.likesColor; + document.getElementById('button-click-behaviour').value = items.button_click_behaviour; + document.getElementById('file-format').value = items.file_format; }); } -- cgit v1.2.3 From dae3bcc4249c0c98f19df2a3cab671773942f887 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Mar 2014 15:10:19 -0400 Subject: Options: update status text on save Move to the right side of the save button and show it for a longer amount of time. --- options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'options.js') diff --git a/options.js b/options.js index 23bb4c5..b1d1192 100644 --- a/options.js +++ b/options.js @@ -11,7 +11,7 @@ function save_options() { status.textContent = 'Options saved.'; setTimeout(function() { status.textContent = ''; - }, 750); + }, 1000); }); } -- cgit v1.2.3