Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
Revamping of the notification system
Browse files Browse the repository at this point in the history
- new notification system
- adds support of MOHW and BFH
  • Loading branch information
ArnaudLigny committed Jul 29, 2014
1 parent 9d834ed commit e626803
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion extension/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 42 additions & 19 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,41 @@

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);
});
});
}

function isBattlelogUrl(url) {
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) {
Expand All @@ -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();
})();
Binary file added extension/home-27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_extName__",
"description": "__MSG_extDescription__",
"version": "0.0.3",
"version": "0.0.4",
"background": {
"persistent": false,
"scripts": [
Expand Down
4 changes: 3 additions & 1 deletion extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ <h1>
<form id="options">
<h2>Game</h2>
<select id="game" name="game">
<option value="bf3">BF3</option>
<option value="bf4">BF4</option>
<option value="bf3">BF3</option>
<option value="bfh">Hardline</option>
<option value="mohw">Medal of Honor</option>
</select>
<h2>Notification</h2>
<input type="checkbox" name="isActivated" checked>
Expand Down

0 comments on commit e626803

Please sign in to comment.