diff --git a/README.md b/README.md index 48061b7..2ec18e4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bower.json b/bower.json index 4480512..dc6aef9 100644 --- a/bower.json +++ b/bower.json @@ -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": [ { diff --git a/extension/icons/icon-80.png b/extension/icons/icon-80.png new file mode 100644 index 0000000..3ec91eb Binary files /dev/null and b/extension/icons/icon-80.png differ diff --git a/extension/manifest.json b/extension/manifest.json index cf5388d..9548fab 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -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", @@ -26,6 +26,7 @@ }, "permissions": [ "https://*.github.com/*", + "https://*.githubusercontent.com/*", "notifications", "tabs" ], diff --git a/extension/scripts/NewsFeed.js b/extension/scripts/NewsFeed.js index 6a26f0e..43f6d73 100644 --- a/extension/scripts/NewsFeed.js +++ b/extension/scripts/NewsFeed.js @@ -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 = "?"; @@ -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") { diff --git a/extension/scripts/NewsFeedChecker.js b/extension/scripts/NewsFeedChecker.js index c2977b4..baf3069 100644 --- a/extension/scripts/NewsFeedChecker.js +++ b/extension/scripts/NewsFeedChecker.js @@ -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); diff --git a/extension/scripts/NewsFeedTransmitter.js b/extension/scripts/NewsFeedTransmitter.js index 145375d..f9e5849 100644 --- a/extension/scripts/NewsFeedTransmitter.js +++ b/extension/scripts/NewsFeedTransmitter.js @@ -6,35 +6,60 @@ * 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); @@ -42,7 +67,7 @@ class NewsFeedTransmitter { 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 }); diff --git a/package.json b/package.json index 8ad0663..772e26e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/screenshots/chrome.png b/screenshots/chrome.png index b040d93..4f64491 100644 Binary files a/screenshots/chrome.png and b/screenshots/chrome.png differ