OLD | NEW |
1 <!-- | 1 <!-- |
2 A background page that manages notifications. | 2 A background page that manages notifications. |
3 | 3 |
4 Copyright 2010 the Chromium Authors | 4 Copyright 2010 the Chromium Authors |
5 | 5 |
6 Use of this source code is governed by a BSD-style license that can be found | 6 Use of this source code is governed by a BSD-style license that can be found |
7 in the "LICENSE" file. | 7 in the "LICENSE" file. |
8 | 8 |
9 Brian Kennish <bkennish@chromium.org> | 9 Brian Kennish <bkennish@chromium.org> |
10 --> | 10 --> |
11 <script> | 11 <!doctype html> |
12 /* | 12 <html> |
13 Displays a notification with the current time. Requires "notifications" | 13 <head> |
14 permission in the manifest file (or calling | 14 <title>Background Page</title> |
15 "webkitNotifications.requestPermission" beforehand). | 15 <script src="background.js"></script> |
16 */ | 16 </head> |
17 function show() { | 17 <body> |
18 var time = /(..)(:..)/(Date()); // The prettyprinted time. | 18 </body> |
19 var hour = time[1] % 12 || 12; // The prettyprinted hour. | 19 </html> |
20 var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day. | |
21 var notification = webkitNotifications.createNotification( | |
22 '48.png', // The image. | |
23 hour + time[2] + ' ' + period, // The title. | |
24 'Time to make the toast.' // The body. | |
25 ); | |
26 notification.show(); | |
27 } | |
28 | |
29 // Conditionally initialize the options. | |
30 if (!localStorage.isInitialized) { | |
31 localStorage.isActivated = true; // The display activation. | |
32 localStorage.frequency = 1; // The display frequency, in minutes. | |
33 localStorage.isInitialized = true; // The option initialization. | |
34 } | |
35 | |
36 // Test for notification support. | |
37 if (webkitNotifications) { | |
38 // While activated, show notifications at the display frequency. | |
39 if (JSON.parse(localStorage.isActivated)) { show(); } | |
40 | |
41 var interval = 0; // The display interval, in minutes. | |
42 | |
43 setInterval(function() { | |
44 interval++; | |
45 | |
46 if ( | |
47 JSON.parse(localStorage.isActivated) && | |
48 localStorage.frequency <= interval | |
49 ) { | |
50 show(); | |
51 interval = 0; | |
52 } | |
53 }, 60000); | |
54 } else { | |
55 // Show a new tab with an error message. | |
56 chrome.tabs.create({url: 'error.html'}); | |
57 } | |
58 </script> | |
OLD | NEW |