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.
6 Displays a notification with the current time. Requires "notifications"
7 permission in the manifest file (or calling
8 "Notification.requestPermission" beforehand).
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 new Notification(hour + time[2] + ' ' + period, {
16 body: 'Time to make the toast.'
20 // Conditionally initialize the options.
21 if (!localStorage.isInitialized) {
22 localStorage.isActivated = true; // The display activation.
23 localStorage.frequency = 1; // The display frequency, in minutes.
24 localStorage.isInitialized = true; // The option initialization.
27 // Test for notification support.
28 if (window.Notification) {
29 // While activated, show notifications at the display frequency.
30 if (JSON.parse(localStorage.isActivated)) { show(); }
32 var interval = 0; // The display interval, in minutes.
34 setInterval(function() {
38 JSON.parse(localStorage.isActivated) &&
39 localStorage.frequency <= interval