1var Notifications = {}; 2 3$(document).ready(function () { 4 if (!window.webkitNotifications) { 5 return; 6 } 7 8 var notificationsEnabled = (window.webkitNotifications.checkPermission() === 0), 9 toggle = $('#toggle_notifications'); 10 11 toggle.show(); 12 updateMenuTitle(); 13 $(transmission).bind('downloadComplete seedingComplete', function (event, torrent) { 14 if (notificationsEnabled) { 15 var title = (event.type == 'downloadComplete' ? 'Download' : 'Seeding') + ' complete', 16 content = torrent.getName(), 17 notification; 18 19 notification = window.webkitNotifications.createNotification('style/transmission/images/logo.png', title, content); 20 notification.show(); 21 setTimeout(function () { 22 notification.cancel(); 23 }, 5000); 24 }; 25 }); 26 27 function updateMenuTitle() { 28 toggle.html((notificationsEnabled ? 'Disable' : 'Enable') + ' Notifications'); 29 } 30 31 Notifications.toggle = function () { 32 if (window.webkitNotifications.checkPermission() !== 0) { 33 window.webkitNotifications.requestPermission(function () { 34 notificationsEnabled = (window.webkitNotifications.checkPermission() === 0); 35 updateMenuTitle(); 36 }); 37 } else { 38 notificationsEnabled = !notificationsEnabled; 39 updateMenuTitle(); 40 } 41 }; 42});