diff --git a/_locales/en_US/messages.json b/_locales/en_US/messages.json index b023d65..2538bf7 100644 --- a/_locales/en_US/messages.json +++ b/_locales/en_US/messages.json @@ -524,7 +524,7 @@ } }, "orangered_description": { - "message": "When checked, $MOSTLY_HARMLESS$ will check for new $ORANGERED$s at the interval you set. If you get an $ORANGERED$, it will display a desktop notification for the length of time you choose.", + "message": "When checked, $MOSTLY_HARMLESS$ will check for new $ORANGERED$s at the interval you set. If you get an $ORANGERED$, it will display a desktop notification until you click or close it, or until $MOSTLY_HARMLESS$ checks again and you no longer have an $ORANGERED$.", "placeholders": { "MOSTLY_HARMLESS": { "content": "Mostly Harmless" diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index b023d65..2538bf7 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -524,7 +524,7 @@ } }, "orangered_description": { - "message": "When checked, $MOSTLY_HARMLESS$ will check for new $ORANGERED$s at the interval you set. If you get an $ORANGERED$, it will display a desktop notification for the length of time you choose.", + "message": "When checked, $MOSTLY_HARMLESS$ will check for new $ORANGERED$s at the interval you set. If you get an $ORANGERED$, it will display a desktop notification until you click or close it, or until $MOSTLY_HARMLESS$ checks again and you no longer have an $ORANGERED$.", "placeholders": { "MOSTLY_HARMLESS": { "content": "Mostly Harmless" diff --git a/_locales/hi/messages.json b/_locales/hi/messages.json index b023d65..2538bf7 100644 --- a/_locales/hi/messages.json +++ b/_locales/hi/messages.json @@ -524,7 +524,7 @@ } }, "orangered_description": { - "message": "When checked, $MOSTLY_HARMLESS$ will check for new $ORANGERED$s at the interval you set. If you get an $ORANGERED$, it will display a desktop notification for the length of time you choose.", + "message": "When checked, $MOSTLY_HARMLESS$ will check for new $ORANGERED$s at the interval you set. If you get an $ORANGERED$, it will display a desktop notification until you click or close it, or until $MOSTLY_HARMLESS$ checks again and you no longer have an $ORANGERED$.", "placeholders": { "MOSTLY_HARMLESS": { "content": "Mostly Harmless" diff --git a/fancy-settings/manifest.js b/fancy-settings/manifest.js index cb0db8f..26f1abb 100755 --- a/fancy-settings/manifest.js +++ b/fancy-settings/manifest.js @@ -102,21 +102,6 @@ this.manifest = { return chrome.i18n.getMessage('orangered_interval_minutes', value.toString()); } - }, - { - "tab": chrome.i18n.getMessage('tab_preferences'), - "group": chrome.i18n.getMessage('group_orangered_notifications'), - "name": "mailDisplayTime", - "type": "slider", - "label": "", - "max": 60, - "min": 10, - "step": 1, - "display": true, - "displayModifier": function (value) { - return chrome.i18n.getMessage('orangered_display_time', value.toString()); - } - }, { "tab": chrome.i18n.getMessage('tab_preferences'), diff --git a/js/common.js b/js/common.js index 23d544f..a39e7ed 100644 --- a/js/common.js +++ b/js/common.js @@ -9,7 +9,6 @@ settings = new Store('settings', { 'waitForClick': false, 'checkMail': true, 'mailInterval': 5, - 'mailDisplayTime': 30, 'mailSound': false, 'excludedDomains': 'secure.ingdirect.com\nchaseonline.chase.com\nonline.wellsfargo.com\nmail.google.com\ndocs.google.com', 'excludedRegex': 'chrome://.*\nchrome-extension://.*\nview-source://.*\nftp://.*\nhttps?://www\\.google\\.com/search.*\nhttps?://search\\.yahoo\\.com/search.*\nhttps?://www\\.bing\\.com/search.*\nhttps?://www\\.reddit\\.com/(?:r/(?:\\w|\\+)+/?)?(?:$|\\?count)' @@ -349,11 +348,15 @@ RedditAPI.prototype.apiTransmit = function (type, url, data, cback) { cback(JSON.parse(req.responseText)); } - notificationArea.innerHTML = ''; - notificationArea.style.display = 'none'; + if (notificationArea) { + notificationArea.innerHTML = ''; + notificationArea.style.display = 'none'; + } return JSON.parse(req.responseText); } else { - notificationArea.innerHTML = '' + chrome.i18n.getMessage('api_error', req.status.toString()) + '' + if (notificationArea) { + notificationArea.innerHTML = '' + chrome.i18n.getMessage('api_error', req.status.toString()) + '' + } throw chrome.i18n.getMessage('api_error', req.status.toString()); } } @@ -843,6 +846,8 @@ reddit = new RedditAPI('www.reddit.com'); * @constructor */ function Background() { + this.notificationIsShown = false; + this.notification = null; return true; } @@ -910,29 +915,31 @@ Background.prototype.watchMail = function () { var mailProcess, pop; function showNotification (hasMail) { - var notification, notificationTimeout, mailInterval; + var mailInterval; mailInterval = settings.get('mailInterval') * 1000 * 60; - - if (hasMail === true) { + + if (hasMail === true && background.notificationIsShown === false) { if (settings.get('mailSound') === true) { pop.play(); } - notification = webkitNotifications.createNotification( + background.notification = webkitNotifications.createNotification( '/pix/mail.png', // icon url - can be relative chrome.i18n.getMessage('orangered_received'), // notification title chrome.i18n.getMessage('orangered_action') // notification body text ); - notificationTimeout = window.setTimeout(function () { - notification.cancel(); - }, settings.get('mailDisplayTime') * 1000); - notification.onclick = function () { + background.notification.onclick = function () { chrome.tabs.create({'url': 'http://' + reddit.domain + '/message/unread/', 'selected': true}); - notification.cancel(); - window.clearTimeout(notificationTimeout); + background.notification.cancel(); }; - notification.show(); + background.notification.onclose = function () { + background.notificationIsShown = false; + }; + background.notificationIsShown = true; + background.notification.show(); + } else if (hasMail === false && background.notificationIsShown === true) { + background.notification.cancel(); } window.setTimeout(checkPrefs, mailInterval);