OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 /* | 5 /* |
6 Displays a notification with the current time. Requires "notifications" | 6 Displays a notification with the current time. Requires "notifications" |
7 permission in the manifest file (or calling | 7 permission in the manifest file (or calling |
8 "webkitNotifications.requestPermission" beforehand). | 8 "Notification.requestPermission" beforehand). |
9 */ | 9 */ |
10 function show() { | 10 function show() { |
11 var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time. | 11 var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time. |
12 var hour = time[1] % 12 || 12; // The prettyprinted hour. | 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. | 13 var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day. |
14 var notification = window.webkitNotifications.createNotification( | 14 new Notification(hour + time[2] + ' ' + period, { |
15 '48.png', // The image. | 15 icon: '48.png', |
16 hour + time[2] + ' ' + period, // The title. | 16 body: 'Time to make the toast.' |
17 'Time to make the toast.' // The body. | 17 }); |
18 ); | |
19 notification.show(); | |
20 } | 18 } |
21 | 19 |
22 // Conditionally initialize the options. | 20 // Conditionally initialize the options. |
23 if (!localStorage.isInitialized) { | 21 if (!localStorage.isInitialized) { |
24 localStorage.isActivated = true; // The display activation. | 22 localStorage.isActivated = true; // The display activation. |
25 localStorage.frequency = 1; // The display frequency, in minutes. | 23 localStorage.frequency = 1; // The display frequency, in minutes. |
26 localStorage.isInitialized = true; // The option initialization. | 24 localStorage.isInitialized = true; // The option initialization. |
27 } | 25 } |
28 | 26 |
29 // Test for notification support. | 27 // Test for notification support. |
30 if (window.webkitNotifications) { | 28 if ("Notification" in window) { |
not at google - send to devlin
2014/08/01 16:52:28
i preferred it the old way, "if (window.Notificati
tfarina
2014/08/02 00:54:05
Done.
| |
31 // While activated, show notifications at the display frequency. | 29 // While activated, show notifications at the display frequency. |
32 if (JSON.parse(localStorage.isActivated)) { show(); } | 30 if (JSON.parse(localStorage.isActivated)) { show(); } |
33 | 31 |
34 var interval = 0; // The display interval, in minutes. | 32 var interval = 0; // The display interval, in minutes. |
35 | 33 |
36 setInterval(function() { | 34 setInterval(function() { |
37 interval++; | 35 interval++; |
38 | 36 |
39 if ( | 37 if ( |
40 JSON.parse(localStorage.isActivated) && | 38 JSON.parse(localStorage.isActivated) && |
41 localStorage.frequency <= interval | 39 localStorage.frequency <= interval |
42 ) { | 40 ) { |
43 show(); | 41 show(); |
44 interval = 0; | 42 interval = 0; |
45 } | 43 } |
46 }, 60000); | 44 }, 60000); |
47 } | 45 } |
OLD | NEW |