Skip to content
This repository
Browse code

Added Chrome desktop notifications.

  • Loading branch information...
commit d98a3c8d165676d9b2c72acbd3220b8030b92ef5 1 parent 77edd87
Sash Nagarkar snoshy authored chromakode committed

Showing 2 changed files with 54 additions and 1 deletion. Show diff stats Hide diff stats

  1. +53 1 background.html
  2. +1 0  manifest.json
54 background.html
@@ -13,6 +13,53 @@
13 13 this.fullname[info.name] = info;
14 14 },
15 15
  16 + checkMail: function(params, callback) {
  17 + console.log('Checking reddit mail..');
  18 + $.ajax({
  19 + url: 'http://www.reddit.com/message/unread/.json',
  20 + success: function(resp) {
  21 + if (resp.data) {
  22 + var newMsgCount = 0;
  23 + var notifText = '';
  24 + var notifTitle = '';
  25 + var newIdx = -1;
  26 +
  27 + if (redditInfo.lastMailCheckTime != null) {
  28 + for (i = 0; i < resp.data.children.length; i++) {
  29 + if (new Date(resp.data.children[i].data.created_utc*1000) >
  30 + redditInfo.lastMailCheckTime) {
  31 + newMsgCount++;
  32 + if (newIdx == -1) { newIdx = i; }
  33 + }
  34 + }
  35 +
  36 + if (newMsgCount == 1) {
  37 + notifTitle = resp.data.children[newIdx].data.author + ': ' +
  38 + resp.data.children[newIdx].data.subject;
  39 + notifText = resp.data.children[newIdx].data.body;
  40 + } else if (newMsgCount > 1) {
  41 + notifTitle = 'Reddit: New Messages!';
  42 + notifText = 'You have ' + resp.data.children.length + ' new messages.';
  43 + }
  44 + }
  45 +
  46 + if (newMsgCount > 0) {
  47 + webkitNotifications.createNotification(
  48 + 'images/reddit_mail_icon.svg',
  49 + notifTitle,
  50 + notifText
  51 + ).show();
  52 + }
  53 +
  54 + redditInfo.lastMailCheckTime = new Date();
  55 + }
  56 + },
  57 + error: function() {
  58 + console.log('Reddit mail check failed!');
  59 + }
  60 + });
  61 + },
  62 +
16 63 _queryInfo: function(params, callback) {
17 64 console.log('Performing AJAX info call for ', params);
18 65 params.limit = 1;
@@ -110,7 +157,8 @@
110 157
111 158 modhash: null,
112 159 url: {},
113   - fullname: {}
  160 + fullname: {},
  161 + lastMailCheckTime: null,
114 162 };
115 163
116 164 tabStatus = {
@@ -280,6 +328,10 @@
280 328 }
281 329 }
282 330
  331 + window.setInterval(function() {
  332 + redditInfo.checkMail();
  333 + }, 300000);
  334 +
283 335 chrome.extension.onRequest.addListener(onRequest);
284 336 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
285 337 if (changeInfo.status == 'loading') {
1  manifest.json
@@ -4,6 +4,7 @@
4 4 "description": "Shine displays a bar over pages from reddit to help you submit, vote on, save, and view comments for web pages.",
5 5 "permissions": [
6 6 "tabs",
  7 + "notifications",
7 8 "http://*/*"
8 9 ],
9 10 "icons": {

0 comments on commit d98a3c8

Please sign in to comment.
Something went wrong with that request. Please try again.