Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1082)

Side by Side Diff: chrome/common/extensions/docs/examples/api/storage/stylizr/options.js

Issue 8916013: Added storage sample. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Storage sample Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Store settings in the synchronized repository.
6 var storage = chrome.experimental.storage.sync;
7
8 // Get at the DOM controls used in the sample.
9 var resetButton = document.querySelector('button.reset');
10 var submitButton = document.querySelector('button.submit');
11 var textarea = document.querySelector('textarea');
12
13 // Load any CSS that may have previously been saved.
14 loadChanges();
15
16 submitButton.addEventListener('click', saveChanges);
17 resetButton.addEventListener('click', reset);
18
19 function saveChanges() {
20 // Get the current CSS snippet from the form.
21 var cssCode = textarea.value;
22 // Check that there's some code there.
23 if (!cssCode) {
24 message('Error: No CSS specified');
25 return;
26 }
27 // Save it locally (un-synchronized) using the Chrome extension storage API.
28 storage.set({'css': cssCode}, function() {
29 // Notify that we saved.
30 message('Settings saved');
31 });
32 }
33
34 function loadChanges() {
35 storage.get('css', function(items) {
36 if (items.css) {
37 textarea.value = items.css;
38 message('Loaded saved CSS.');
39 }
40 });
41 }
42
43 function reset() {
44 // Remove the saved value from storage
45 storage.remove('css', function(items) {
46 message('Reset stored CSS');
47 });
48 // Refresh the text area.
49 textarea.value = '';
50 }
51
52 function message(msg) {
53 var message = document.querySelector('.message');
54 message.innerText = msg;
55 setTimeout(function() {
56 message.innerText = '';
57 }, 3000);
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698