Skip to content

Commit

Permalink
XML->JSON and fix extension
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarOk1412 committed Feb 10, 2017
1 parent 2e40aa6 commit b64e84e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Zds-Notificateur",
"version": "2.1",
"version": "2.2",
"homepage_url": "https://zestedesavoir.com",
"description": "Une extension pour connaitre le nombre de notifications et de MP de ZesteDeSavoir sans avoir besoin d'ouvrir le site",

Expand Down
20 changes: 9 additions & 11 deletions Firefox/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,28 @@ function getNotificationsFromAPI() {
xhr.onload = function (e) {
if (xhr.readyState === 4) {
var result = xhr.status;

if(result === 401) {
_connected = false;
if(_debug) console.log("Not connected");
//Change popup image
chrome.browserAction.setIcon({path:"icons/notconnected.png"});
} else if (result === 200) {
_connected = true;
var parser = new DOMParser();
var rootDOM = parser.parseFromString(xhr.response, "application/xml");
if(rootDOM.documentElement.nodeName === "parsererror") {
var rootDOM = JSON.parse(xhr.response);
if(rootDOM.details) {
if(_debug) console.log("Error while parsing");
} else {
//Get new notifications
var resultsNotification = rootDOM.documentElement.getElementsByTagName("results")[0].childNodes;
var resultsNotification = rootDOM.results;
var countNotifications = 0;
for(var notif = 0; notif < resultsNotification.length; ++notif) {
//If a notification is new we have is_read === False
if(resultsNotification[notif].childNodes[2].innerHTML === "False") {
if(!resultsNotification[notif].is_read) {
countNotifications += 1;
var titleNotif = resultsNotification[notif].childNodes[1].innerHTML
var senderNotif = resultsNotification[notif].childNodes[4].childNodes[1].innerHTML;
var senderAvatarNotif = resultsNotification[notif].childNodes[4].childNodes[5].innerHTML;
var dateNotif = resultsNotification[notif].childNodes[5].innerHTML;
var titleNotif = resultsNotification[notif].title
var senderNotif = resultsNotification[notif].sender.username;
var senderAvatarNotif = resultsNotification[notif].sender.avatar_url;
var dateNotif = resultsNotification[notif].pubdate;
var date = new Date((dateNotif || "").replace(/-/g,"/").replace(/[TZ]/g," "));
var minutes = '' + date.getMinutes();
if(minutes.length < 2) {
Expand All @@ -80,7 +78,7 @@ function getNotificationsFromAPI() {
formatedDate = "Hier";
}
}
var urlNotif = "https://zestedesavoir.com" + resultsNotification[notif].childNodes[3].innerHTML;
var urlNotif = "https://zestedesavoir.com" + resultsNotification[notif].url;
if(_debug) console.log(urlNotif + " by " + senderNotif);
addNotification(titleNotif, senderNotif, senderAvatarNotif, formatedDate, urlNotif);
}
Expand Down

0 comments on commit b64e84e

Please sign in to comment.