OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Store settings in the synchronized repository. | 5 // Store settings in the synchronized repository. |
6 var storage = chrome.storage.sync; | 6 var storage = chrome.storage.sync; |
7 | 7 |
8 // Get at the DOM controls used in the sample. | 8 // Get at the DOM controls used in the sample. |
9 var resetButton = document.querySelector('button.reset'); | 9 var resetButton = document.querySelector('button.reset'); |
10 var submitButton = document.querySelector('button.submit'); | 10 var submitButton = document.querySelector('button.submit'); |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 // Save it using the Chrome extension storage API. | 27 // Save it using the Chrome extension storage API. |
28 storage.set({'css': cssCode}, function() { | 28 storage.set({'css': cssCode}, function() { |
29 // Notify that we saved. | 29 // Notify that we saved. |
30 message('Settings saved'); | 30 message('Settings saved'); |
31 }); | 31 }); |
32 } | 32 } |
33 | 33 |
34 function loadChanges() { | 34 function loadChanges() { |
35 storage.get('css', function(items) { | 35 storage.get('css', function(items) { |
| 36 // To avoid checking items.css we could specify storage.get({css: ''}) to |
| 37 // return a default value of '' if there is no css value yet. |
36 if (items.css) { | 38 if (items.css) { |
37 textarea.value = items.css; | 39 textarea.value = items.css; |
38 message('Loaded saved CSS.'); | 40 message('Loaded saved CSS.'); |
39 } | 41 } |
40 }); | 42 }); |
41 } | 43 } |
42 | 44 |
43 function reset() { | 45 function reset() { |
44 // Remove the saved value from storage | 46 // Remove the saved value from storage. storage.clear would achieve the same |
| 47 // thing. |
45 storage.remove('css', function(items) { | 48 storage.remove('css', function(items) { |
46 message('Reset stored CSS'); | 49 message('Reset stored CSS'); |
47 }); | 50 }); |
48 // Refresh the text area. | 51 // Refresh the text area. |
49 textarea.value = ''; | 52 textarea.value = ''; |
50 } | 53 } |
51 | 54 |
52 function message(msg) { | 55 function message(msg) { |
53 var message = document.querySelector('.message'); | 56 var message = document.querySelector('.message'); |
54 message.innerText = msg; | 57 message.innerText = msg; |
55 setTimeout(function() { | 58 setTimeout(function() { |
56 message.innerText = ''; | 59 message.innerText = ''; |
57 }, 3000); | 60 }, 3000); |
58 } | 61 } |
OLD | NEW |