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

Side by Side Diff: chrome/common/extensions/docs/examples/api/notifications/background.js

Issue 8309001: Adding `content_security_policy` to a few sample extensions. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: License and whitespace. Created 9 years, 1 month 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 /*
6 Displays a notification with the current time. Requires "notifications"
7 permission in the manifest file (or calling
8 "webkitNotifications.requestPermission" beforehand).
9 */
10 function show() {
11 var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time.
12 var hour = time[1] % 12 || 12; // The prettyprinted hour.
13 var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day.
14 var notification = window.webkitNotifications.createNotification(
15 '48.png', // The image.
16 hour + time[2] + ' ' + period, // The title.
17 'Time to make the toast.' // The body.
18 );
19 notification.show();
20 }
21
22 // Conditionally initialize the options.
23 if (!localStorage.isInitialized) {
24 localStorage.isActivated = true; // The display activation.
25 localStorage.frequency = 1; // The display frequency, in minutes.
26 localStorage.isInitialized = true; // The option initialization.
27 }
28
29 // Test for notification support.
30 if (window.webkitNotifications) {
31 // While activated, show notifications at the display frequency.
32 if (JSON.parse(localStorage.isActivated)) { show(); }
33
34 var interval = 0; // The display interval, in minutes.
35
36 setInterval(function() {
37 interval++;
38
39 if (
40 JSON.parse(localStorage.isActivated) &&
41 localStorage.frequency <= interval
42 ) {
43 show();
44 interval = 0;
45 }
46 }, 60000);
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698