| OLD | NEW |
| 1 // Copyright (c) 2011 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.experimental.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'); |
| 11 var textarea = document.querySelector('textarea'); | 11 var textarea = document.querySelector('textarea'); |
| 12 | 12 |
| 13 // Load any CSS that may have previously been saved. | 13 // Load any CSS that may have previously been saved. |
| 14 loadChanges(); | 14 loadChanges(); |
| 15 | 15 |
| 16 submitButton.addEventListener('click', saveChanges); | 16 submitButton.addEventListener('click', saveChanges); |
| 17 resetButton.addEventListener('click', reset); | 17 resetButton.addEventListener('click', reset); |
| 18 | 18 |
| 19 function saveChanges() { | 19 function saveChanges() { |
| 20 // Get the current CSS snippet from the form. | 20 // Get the current CSS snippet from the form. |
| 21 var cssCode = textarea.value; | 21 var cssCode = textarea.value; |
| 22 // Check that there's some code there. | 22 // Check that there's some code there. |
| 23 if (!cssCode) { | 23 if (!cssCode) { |
| 24 message('Error: No CSS specified'); | 24 message('Error: No CSS specified'); |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 // Save it locally (un-synchronized) 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 if (items.css) { | 36 if (items.css) { |
| 37 textarea.value = items.css; | 37 textarea.value = items.css; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 textarea.value = ''; | 49 textarea.value = ''; |
| 50 } | 50 } |
| 51 | 51 |
| 52 function message(msg) { | 52 function message(msg) { |
| 53 var message = document.querySelector('.message'); | 53 var message = document.querySelector('.message'); |
| 54 message.innerText = msg; | 54 message.innerText = msg; |
| 55 setTimeout(function() { | 55 setTimeout(function() { |
| 56 message.innerText = ''; | 56 message.innerText = ''; |
| 57 }, 3000); | 57 }, 3000); |
| 58 } | 58 } |
| OLD | NEW |