Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
Added "View author" button in notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
julkue committed Mar 4, 2016
1 parent 2923dfa commit 5a4c2db
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Firefox:
## Installation

- [Firefox add-ons marketplace][firefox-download-link]
- [Chrome add-ons marketplace][chrome-download-link]
- [Chrome web store][chrome-download-link]
- Download a release [directly][release-link]

[installation]: https://github.com/julmot/news-feed-for-github#installation
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "news-feed-for-github",
"version": "1.0.0",
"version": "1.1.0",
"description": "GitHub news feed notifications directly in the browser",
"authors": [
{
Expand Down
Binary file added extension/icons/icon-80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "News Feed for GitHub",
"description": "GitHub news feed notifications directly in the browser",
"version": "1.0.0",
"version": "1.1.0",
"homepage_url": "https://github.com/julmot/news-feed-for-github",
"icons": {
"48": "icons/icon-48.png",
Expand All @@ -26,6 +26,7 @@
},
"permissions": [
"https://*.github.com/*",
"https://*.githubusercontent.com/*",
"notifications",
"tabs"
],
Expand Down
13 changes: 11 additions & 2 deletions extension/scripts/NewsFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NewsFeed {
xhr(options) {
let xmlhttp = new XMLHttpRequest();
let url = options["url"];
if(typeof options["cache"] !== "boolean" || options["cache"]) {
if(typeof options["cache"] !== "boolean" || !options["cache"]) {
let divider = "&";
if(url.indexOf("?") === -1) {
divider = "?";
Expand All @@ -25,12 +25,21 @@ class NewsFeed {
if(typeof options["responseType"] === "string") {
xmlhttp.responseType = options["responseType"];
}
if(typeof options["withCredentials"] !== "boolean" || options["withCredentials"]) {
xmlhttp.withCredentials = true;
} else {
xmlhttp.withCredentials = false;
}
xmlhttp.withCredentials = true;
xmlhttp.onreadystatechange = () => {
if(xmlhttp.readyState === XMLHttpRequest.DONE) {
if(xmlhttp.status === 200) {
if(typeof options["success"] === "function") {
options["success"](xmlhttp.responseText);
if(options["responseType"] === "blob") {
options["success"](xmlhttp.response);
} else {
options["success"](xmlhttp.responseText);
}
}
} else {
if(typeof options["error"] === "function") {
Expand Down
8 changes: 3 additions & 5 deletions extension/scripts/NewsFeedChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
"use strict";
class NewsFeedChecker extends NewsFeed {

constructor(cbnp, cbe) {
constructor() {
super();
}

initialize(cbnp, cbe) {
this.interval = 15000;
this.cbNewPost = cbnp;
this.cbErr = cbe;

this.initialize();
}

initialize() {
setInterval(() => {
this.fetch();
}, this.interval);
Expand Down
59 changes: 42 additions & 17 deletions extension/scripts/NewsFeedTransmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,68 @@
* with this source code.
*****************************************************/
"use strict";
class NewsFeedTransmitter {
class NewsFeedTransmitter extends NewsFeedChecker {

constructor() {
let checker = new NewsFeedChecker(this.notifyPost, this.notifyError);
super();
super.initialize(
this.notifyPost.bind(this),
this.notifyError.bind(this)
);
}

notifyPost(post) {
console.debug(post);
let message = post["title"][0]["_text"];
let authorImage = post["thumbnail"][0]["_attr"]["url"]["_value"];
let authorURL = post["author"][0]["uri"][0]["_text"];
let author = post["author"][0]["name"][0]["_text"];

console.info(post);
console.debug(`Author: '${author}'`);
console.debug(`Author URL: ${authorURL}`);
console.debug(`Author image: ${authorImage}`);

if(typeof chrome === "object" && typeof chrome.notifications === "object") {
chrome.notifications.create({
"type": "basic",
"iconUrl": chrome.extension.getURL("icons/icon-96.png"),
"title": "GitHub news feed",
"message": message
});
}
super.xhr({
"cache": true,
"url": authorImage,
"responseType": "blob",
"success": (blob) => {
let blobURL = window.URL.createObjectURL(blob);
if(typeof chrome === "object" && typeof chrome.notifications === "object") {
// as FF does not support the callback function
// it is necessary to generate the id manually
let notifyPostID = (0.5).toString(36).substr(2, 16);
chrome.notifications.create(notifyPostID, {
"type": "basic",
"iconUrl": chrome.extension.getURL("icons/icon-80.png"),
"title": "GitHub news feed",
"message": message,
"buttons": [{
"title": `View ${author}`,
"iconUrl": blobURL
}]
});
chrome.notifications.onButtonClicked.addListener((notifId, btnIdx) => {
if(notifId === notifyPostID) {
if(btnIdx === 0) {
window.open(authorURL);
}
}
});
}
},
"error": (err) => {
this.notifyError(err);
}
});
}

notifyError(err) {
if(sessionStorage.getItem("previousError") === err){
if(sessionStorage.getItem("previousError") === err) {
return;
}
sessionStorage.setItem("previousError", err);
console.error(err);
if(typeof chrome === "object" && typeof chrome.notifications === "object") {
chrome.notifications.create({
"type": "basic",
"iconUrl": chrome.extension.getURL("icons/icon-96.png"),
"iconUrl": chrome.extension.getURL("icons/icon-80.png"),
"title": "GitHub news feed",
"message": err
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "news-feed-for-github",
"version": "1.0.0",
"version": "1.1.0",
"description": "GitHub news feed notifications directly in the browser",
"author": {
"name": "Julian Motz",
Expand Down
Binary file modified screenshots/chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 5a4c2db

@julkue
Copy link
Owner Author

@julkue julkue commented on 5a4c2db Mar 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: There is a bug tracked here: https://bugzilla.mozilla.org/show_bug.cgi?id=1254291
If it is solved, there is no need for let notifyPostID = (0.5).toString(36).substr(2, 16); anymore.

Please sign in to comment.