From e6268034262f238f4740fe39a1d257b9dbfe08cf Mon Sep 17 00:00:00 2001 From: Narno Date: Tue, 29 Jul 2014 12:36:16 +0200 Subject: [PATCH] Revamping of the notification system - new notification system - adds support of MOHW and BFH --- extension/_locales/en/messages.json | 2 +- extension/background.js | 61 +++++++++++++++++++--------- extension/home-27.png | Bin 0 -> 1248 bytes extension/manifest.json | 2 +- extension/options.html | 4 +- 5 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 extension/home-27.png diff --git a/extension/_locales/en/messages.json b/extension/_locales/en/messages.json index cf76fac..39c0a2a 100644 --- a/extension/_locales/en/messages.json +++ b/extension/_locales/en/messages.json @@ -6,7 +6,7 @@ "message": "Displays your Battlelog friends count (offline, online or playing)." }, "browserActionDefaultTitle": { - "message": "$count$ Battlelog friend(s) $status$", + "message": "$count$ friend(s) $status$", "placeholders": { "count": { "content": "$1", diff --git a/extension/background.js b/extension/background.js index 2b0e1c7..9e2a853 100644 --- a/extension/background.js +++ b/extension/background.js @@ -122,15 +122,21 @@ function showNotification() { NotificationsCount(function (count, status) { - var notification = webkitNotifications.createNotification( - 'icon-48.png', - 'Battlelog friends', - chrome.i18n.getMessage('browserActionDefaultTitle', [count, status]) - ); - notification.show(); - setTimeout(function() { - notification.cancel(); - },5000); + var opt = { + type: "basic", + title: "Battlelog friends", + message: chrome.i18n.getMessage('browserActionDefaultTitle', [count, status]), + iconUrl: "icon-48.png", + buttons: [ + { title: "Open Battlelog", iconUrl: "home-27.png" }, // http://glyphicons.com + ] + }; + var notification = chrome.notifications.create('showFriends', opt, function() { + // auto clear after 5s + setTimeout(function() { + chrome.notifications.clear('showFriends', function(){}); + }, 5000); + }); }); } @@ -138,6 +144,19 @@ return url.indexOf(HOME_URL) == 0; } + function openBattlelogInTab() { + // check if Battle is already open + chrome.tabs.getAllInWindow(undefined, function(tabs) { + for (var i = 0, tab; tab = tabs[i]; i++) { + if (tab.url && isBattlelogUrl(tab.url)) { + chrome.tabs.update(tab.id, {selected: true}); + return; + } + } + chrome.tabs.create({url: HOME_URL}); + }); + } + // Chrome alarm chrome.alarms.create('badge', {periodInMinutes: 1}); if (JSON.parse(localStorage.isActivated) && localStorage.frequency) { @@ -154,20 +173,24 @@ // browser action chrome.browserAction.onClicked.addListener(function () { - // check if Battle is already open - chrome.tabs.getAllInWindow(undefined, function(tabs) { - for (var i = 0, tab; tab = tabs[i]; i++) { - if (tab.url && isBattlelogUrl(tab.url)) { - chrome.tabs.update(tab.id, {selected: true}); - return; - } - } - chrome.tabs.create({url: HOME_URL}); - }); + openBattlelogInTab(); // force update on click updateBadge(); showNotification(); }); + + // notification action + chrome.notifications.onClicked.addListener(function () { + //console.log("The notification was clicked"); + openBattlelogInTab(); + }); + + // notification button action + chrome.notifications.onButtonClicked.addListener(function () { + //console.log("The notification button was clicked"); + openBattlelogInTab(); + }); + updateBadge(); })(); \ No newline at end of file diff --git a/extension/home-27.png b/extension/home-27.png new file mode 100644 index 0000000000000000000000000000000000000000..8b0bcb1d63393a6c4148f3835a898ad66ae50e15 GIT binary patch literal 1248 zcmaJ>TZq(F7!EF4yK3u$qOMqCe5iuCoMe(o;?C+!GNU8TI*bGEqnYH)OxPqRCTE=4 zEroSa@X{8cAfn*q#oL33iWK@Fg(`?bEff{;r3ii47B3IJ6be0=o!Q+7*+6psbI$+$ z|M%Z=vOKzb)!@(|MNzAYd&~-1H7s8n zUdk^X}&d4DC7@ z=Ac{>N}&Op?w-jA9+(`h+LPn9<}f=)=;4k|4EPXRbjSCCSnp(*u3eqT$uZB+T@^f@ zVP;8 z*=3j}#-Yyh?RJ}MOB{+CJkT_a7ernZS)#$l69Kk5Y!GkhTQFg4M{bB+6wrx9tA<)Q z!w{ykA^2gbG-o)7dx;_`<2zQ!15V(5KZ&cW9peg|r}0VcxH=I+z5-*^ifmGk`j$SJ z#s%ayiHF7B-oj6MjECiAh&PlL^T&^HUvYC@*0P>=mP6?(WNRkG` zv|<+e*kTZ4E3jeWG{L&_*wms}-H4!tQB+09>$gg|i7<+rD5MR8-deJ3H%Ru|l0x>V z!pJ=WokE0sx?2g|{R9C?g-#u+He0u##HLcDGisXZu&S&O8IoH~WO{gKLDu@g3!*9j zKq5|yBzpj;f-0#>UQSDeG%zHE;Rzwf*0GB{*lW|QhkKIeCat1-R?r|hVI5evS{`Ob z8s0?MbZr#G!+g?)o=X5-X%@>bu-H9b(6@a}G7O10H-%&~H^(p_!yAz){o%&3vt+`L z7tL(7^Xi{Jejl8oS1v8D`?h)MuS?uF<+JB+|NY$1e!4u6`O+AWKJzP^o@vynZ7-Np zUp+Z@Xi4q!^Y*6eQ&(S7Gs_;`Tm9YU)yJ-!8M<(ErU8Ckd3pD<6*JQp%L9|f$Ng`< zSbOHqxzi`!et&Xr`^VSl&xikV_kVl3YsVY;?(zTD>{z;

Game

Notification