2016-03-29 15:44:43 +02:00
|
|
|
/* global Module */
|
|
|
|
|
|
|
|
/* Magic Mirror
|
|
|
|
* Module: NewsFeed
|
|
|
|
*
|
|
|
|
* By Michael Teeuw http://michaelteeuw.nl
|
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
Module.register("newsfeed",{
|
2016-03-29 15:44:43 +02:00
|
|
|
|
|
|
|
// Default module config.
|
|
|
|
defaults: {
|
2016-04-20 14:39:38 +02:00
|
|
|
feeds: [
|
|
|
|
{
|
|
|
|
title: "New York Times",
|
|
|
|
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
|
|
|
|
encoding: "UTF-8" //ISO-8859-1
|
|
|
|
}
|
|
|
|
],
|
|
|
|
showSourceTitle: true,
|
2016-03-29 15:44:43 +02:00
|
|
|
showPublishDate: true,
|
2016-04-12 11:06:59 +02:00
|
|
|
showDescription: false,
|
2017-03-11 17:36:47 -06:00
|
|
|
wrapTitle: true,
|
|
|
|
wrapDescription: true,
|
2017-11-15 12:21:02 +07:00
|
|
|
truncDescription: true,
|
|
|
|
lengthDescription: 400,
|
2017-03-10 16:56:28 +01:00
|
|
|
hideLoading: false,
|
2017-11-15 12:21:02 +07:00
|
|
|
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
2016-04-12 11:06:59 +02:00
|
|
|
updateInterval: 10 * 1000,
|
2016-04-05 14:35:11 -04:00
|
|
|
animationSpeed: 2.5 * 1000,
|
2016-08-26 22:06:03 +02:00
|
|
|
maxNewsItems: 0, // 0 for unlimited
|
2017-03-21 19:39:51 +01:00
|
|
|
ignoreOldItems: false,
|
|
|
|
ignoreOlderThan: 24 * 60 * 60 * 1000, // 1 day
|
2016-12-01 19:48:53 -03:00
|
|
|
removeStartTags: "",
|
|
|
|
removeEndTags: "",
|
2016-08-27 00:32:47 +02:00
|
|
|
startTags: [],
|
Added ability to set a list of prohibited words that will be filtered out of newsfeed
Resolves #1071
`prohibitedWords` config parameter is an array of words. If set and case insensitive greedy match is found anywhere in the title then that newsfeed item will not be displayed. Readme updated with instructions.
Users should be careful on the words selection as careless setting may remove many or all items from the newsfeed. Some obvious mistakes like `space, comma, dot` etc. can be prevented programatically, but I left it out of this PR
Example:
with `prohibitedWords: ['dodgers']`
Original `newsItems`:
```
0:{title: "New York City, Russia, Los Angeles Dodgers: Your Wednesday Briefing", description: "Here’s what you need to know to start your day.", pubdate: "Wed, 01 Nov 2017 09:37:36 GMT", url: "https://www.nytimes.com/2017/11/01/briefing/new-yo…ssia-los-angeles-dodgers.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
1:{title: "A Mangled School Bus, Bodies Everywhere; ‘It Was Surreal’", description: "A truck ramming bicyclists. The driver emerging wi…e attack, it was as confusing as it was gruesome.", pubdate: "Wed, 01 Nov 2017 09:27:41 GMT", url: "https://www.nytimes.com/2017/10/31/nyregion/nyc-sc…r-attack-truck-witnesses.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
2:{title: "Dodgers 3, Astros 1 | Series tied, 3-3: With a Rally and a Romp, Dodgers Top Astros and Force Game 7", description: "Down by a run with just four innings left in Game …nst a dominating Justin Verlander. Game 7 awaits.", pubdate: "Wed, 01 Nov 2017 07:21:07 GMT", url: "https://www.nytimes.com/2017/11/01/sports/dodgers-win-game-6.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
3:{title: "José Andrés Fed Puerto Rico, and May Change How Aid Is Given", description: "The chef’s huge effort is just the latest led by c…ocally based way to feed people after a disaster.", pubdate: "Wed, 01 Nov 2017 06:40:09 GMT", url: "https://www.nytimes.com/2017/10/30/dining/jose-andres-puerto-rico.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
```
Filtered `newsItems`:
```
0:{title: "A Mangled School Bus, Bodies Everywhere; ‘It Was Surreal’", description: "A truck ramming bicyclists. The driver emerging wi…e attack, it was as confusing as it was gruesome.", pubdate: "Wed, 01 Nov 2017 09:27:41 GMT", url: "https://www.nytimes.com/2017/10/31/nyregion/nyc-sc…r-attack-truck-witnesses.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
1:{title: "José Andrés Fed Puerto Rico, and May Change How Aid Is Given", description: "The chef’s huge effort is just the latest led by c…ocally based way to feed people after a disaster.", pubdate: "Wed, 01 Nov 2017 06:40:09 GMT", url: "https://www.nytimes.com/2017/10/30/dining/jose
```
2017-11-01 03:40:32 -07:00
|
|
|
endTags: [],
|
2018-01-29 21:26:34 +01:00
|
|
|
prohibitedWords: [],
|
2018-06-26 20:01:28 -04:00
|
|
|
scrollLength: 500,
|
|
|
|
logFeedWarnings: false
|
2016-03-29 15:44:43 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Define required scripts.
|
|
|
|
getScripts: function() {
|
2016-04-05 14:35:11 -04:00
|
|
|
return ["moment.js"];
|
2016-03-29 15:44:43 +02:00
|
|
|
},
|
|
|
|
|
2016-05-11 12:38:41 +02:00
|
|
|
// Define required translations.
|
|
|
|
getTranslations: function() {
|
2017-03-30 21:15:51 +02:00
|
|
|
// The translations for the default modules are defined in the core translation files.
|
|
|
|
// Therefor we can just return false. Otherwise we should have returned a dictionary.
|
|
|
|
// If you're trying to build your own module including translations, check out the documentation.
|
2016-05-11 12:38:41 +02:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2016-03-29 15:44:43 +02:00
|
|
|
// Define start sequence.
|
|
|
|
start: function() {
|
2016-04-05 14:35:11 -04:00
|
|
|
Log.info("Starting module: " + this.name);
|
2016-03-29 15:44:43 +02:00
|
|
|
|
|
|
|
// Set locale.
|
|
|
|
moment.locale(config.language);
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-03-29 15:44:43 +02:00
|
|
|
this.newsItems = [];
|
|
|
|
this.loaded = false;
|
|
|
|
this.activeItem = 0;
|
2018-01-29 21:26:34 +01:00
|
|
|
this.scrollPosition = 0;
|
2016-03-30 12:20:46 +02:00
|
|
|
|
2016-04-20 14:39:38 +02:00
|
|
|
this.registerFeeds();
|
2016-03-31 13:05:23 +02:00
|
|
|
|
2018-05-15 20:32:02 -04:00
|
|
|
this.isShowingDescription = this.config.showDescription;
|
2016-03-30 12:20:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Override socket notification handler.
|
|
|
|
socketNotificationReceived: function(notification, payload) {
|
2016-04-05 14:35:11 -04:00
|
|
|
if (notification === "NEWS_ITEMS") {
|
2016-04-20 14:39:38 +02:00
|
|
|
this.generateFeed(payload);
|
2016-03-30 12:20:46 +02:00
|
|
|
|
2016-04-20 14:39:38 +02:00
|
|
|
if (!this.loaded) {
|
|
|
|
this.scheduleUpdateInterval();
|
2016-03-30 12:20:46 +02:00
|
|
|
}
|
2016-04-20 14:39:38 +02:00
|
|
|
|
2016-05-11 12:38:41 +02:00
|
|
|
this.loaded = true;
|
2016-03-30 12:20:46 +02:00
|
|
|
}
|
2016-03-29 15:44:43 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Override dom generator.
|
|
|
|
getDom: function() {
|
|
|
|
var wrapper = document.createElement("div");
|
|
|
|
|
2016-04-20 14:39:38 +02:00
|
|
|
if (this.config.feedUrl) {
|
|
|
|
wrapper.className = "small bright";
|
|
|
|
wrapper.innerHTML = "The configuration options for the newsfeed module have changed.<br>Please check the documentation.";
|
|
|
|
return wrapper;
|
|
|
|
}
|
2016-04-05 13:16:23 +02:00
|
|
|
|
2016-03-29 15:44:43 +02:00
|
|
|
if (this.activeItem >= this.newsItems.length) {
|
|
|
|
this.activeItem = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.newsItems.length > 0) {
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2017-01-06 21:57:30 +01:00
|
|
|
// this.config.showFullArticle is a run-time configuration, triggered by optional notifications
|
2017-01-04 10:46:31 +01:00
|
|
|
if (!this.config.showFullArticle && (this.config.showSourceTitle || this.config.showPublishDate)) {
|
2016-04-20 14:39:38 +02:00
|
|
|
var sourceAndTimestamp = document.createElement("div");
|
|
|
|
sourceAndTimestamp.className = "light small dimmed";
|
|
|
|
|
2016-12-01 19:48:53 -03:00
|
|
|
if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== "") {
|
|
|
|
sourceAndTimestamp.innerHTML = this.newsItems[this.activeItem].sourceTitle;
|
|
|
|
}
|
|
|
|
if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== "" && this.config.showPublishDate) {
|
|
|
|
sourceAndTimestamp.innerHTML += ", ";
|
|
|
|
}
|
|
|
|
if (this.config.showPublishDate) {
|
|
|
|
sourceAndTimestamp.innerHTML += moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow();
|
|
|
|
}
|
|
|
|
if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== "" || this.config.showPublishDate) {
|
|
|
|
sourceAndTimestamp.innerHTML += ":";
|
|
|
|
}
|
2016-04-20 14:39:38 +02:00
|
|
|
|
|
|
|
wrapper.appendChild(sourceAndTimestamp);
|
2016-03-29 15:44:43 +02:00
|
|
|
}
|
|
|
|
|
2016-08-27 00:32:47 +02:00
|
|
|
//Remove selected tags from the beginning of rss feed items (title or description)
|
|
|
|
|
2017-02-06 01:19:03 +01:00
|
|
|
if (this.config.removeStartTags == "title" || this.config.removeStartTags == "both") {
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2016-08-27 00:32:47 +02:00
|
|
|
for (f=0; f<this.config.startTags.length;f++) {
|
|
|
|
if (this.newsItems[this.activeItem].title.slice(0,this.config.startTags[f].length) == this.config.startTags[f]) {
|
|
|
|
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].title.slice(this.config.startTags[f].length,this.newsItems[this.activeItem].title.length);
|
2016-12-01 19:48:53 -03:00
|
|
|
}
|
2016-08-27 00:32:47 +02:00
|
|
|
}
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2016-08-27 01:16:31 +02:00
|
|
|
}
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2017-02-06 01:19:03 +01:00
|
|
|
if (this.config.removeStartTags == "description" || this.config.removeStartTags == "both") {
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2018-05-15 20:32:02 -04:00
|
|
|
if (this.isShowingDescription) {
|
2016-08-27 00:32:47 +02:00
|
|
|
for (f=0; f<this.config.startTags.length;f++) {
|
|
|
|
if (this.newsItems[this.activeItem].description.slice(0,this.config.startTags[f].length) == this.config.startTags[f]) {
|
|
|
|
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].description.slice(this.config.startTags[f].length,this.newsItems[this.activeItem].description.length);
|
2016-12-01 19:48:53 -03:00
|
|
|
}
|
2016-08-27 00:32:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2016-08-27 00:32:47 +02:00
|
|
|
}
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2016-08-27 00:32:47 +02:00
|
|
|
//Remove selected tags from the end of rss feed items (title or description)
|
|
|
|
|
|
|
|
if (this.config.removeEndTags) {
|
|
|
|
for (f=0; f<this.config.endTags.length;f++) {
|
|
|
|
if (this.newsItems[this.activeItem].title.slice(-this.config.endTags[f].length)==this.config.endTags[f]) {
|
|
|
|
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].title.slice(0,-this.config.endTags[f].length);
|
2016-12-01 19:48:53 -03:00
|
|
|
}
|
2016-08-27 00:32:47 +02:00
|
|
|
}
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2018-05-15 20:32:02 -04:00
|
|
|
if (this.isShowingDescription) {
|
2016-08-27 00:32:47 +02:00
|
|
|
for (f=0; f<this.config.endTags.length;f++) {
|
|
|
|
if (this.newsItems[this.activeItem].description.slice(-this.config.endTags[f].length)==this.config.endTags[f]) {
|
|
|
|
this.newsItems[this.activeItem].description = this.newsItems[this.activeItem].description.slice(0,-this.config.endTags[f].length);
|
2016-12-01 19:48:53 -03:00
|
|
|
}
|
2016-08-27 00:32:47 +02:00
|
|
|
}
|
2016-08-26 22:06:03 +02:00
|
|
|
}
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2016-08-27 00:32:47 +02:00
|
|
|
}
|
2017-01-04 11:01:07 +01:00
|
|
|
|
2017-01-04 10:46:31 +01:00
|
|
|
if(!this.config.showFullArticle){
|
|
|
|
var title = document.createElement("div");
|
2017-03-11 17:36:47 -06:00
|
|
|
title.className = "bright medium light" + (!this.config.wrapTitle ? " no-wrap" : "");
|
2017-01-04 10:46:31 +01:00
|
|
|
title.innerHTML = this.newsItems[this.activeItem].title;
|
|
|
|
wrapper.appendChild(title);
|
|
|
|
}
|
2017-01-04 11:01:07 +01:00
|
|
|
|
2018-05-15 20:32:02 -04:00
|
|
|
if (this.isShowingDescription) {
|
2016-04-12 11:06:59 +02:00
|
|
|
var description = document.createElement("div");
|
2017-03-11 17:36:47 -06:00
|
|
|
description.className = "small light" + (!this.config.wrapDescription ? " no-wrap" : "");
|
2017-11-15 12:21:02 +07:00
|
|
|
var txtDesc = this.newsItems[this.activeItem].description;
|
|
|
|
description.innerHTML = (this.config.truncDescription ? (txtDesc.length > this.config.lengthDescription ? txtDesc.substring(0, this.config.lengthDescription) + "..." : txtDesc) : txtDesc);
|
2016-04-12 11:06:59 +02:00
|
|
|
wrapper.appendChild(description);
|
|
|
|
}
|
2017-01-04 11:01:07 +01:00
|
|
|
|
2017-01-04 10:46:31 +01:00
|
|
|
if (this.config.showFullArticle) {
|
|
|
|
var fullArticle = document.createElement("iframe");
|
|
|
|
fullArticle.className = "";
|
2018-04-17 00:25:58 +02:00
|
|
|
fullArticle.style.width = "100vw";
|
2018-01-29 21:26:34 +01:00
|
|
|
// very large height value to allow scrolling
|
2018-04-17 00:25:58 +02:00
|
|
|
fullArticle.height = "3000";
|
|
|
|
fullArticle.style.height = "3000";
|
2017-01-07 22:42:11 +01:00
|
|
|
fullArticle.style.top = "0";
|
|
|
|
fullArticle.style.left = "0";
|
2017-01-04 10:46:31 +01:00
|
|
|
fullArticle.style.border = "none";
|
2018-01-29 21:26:34 +01:00
|
|
|
fullArticle.src = typeof this.newsItems[this.activeItem].url === "string" ? this.newsItems[this.activeItem].url : this.newsItems[this.activeItem].url.href;
|
2018-01-20 23:32:44 +01:00
|
|
|
fullArticle.style.zIndex = 1;
|
2017-01-04 10:46:31 +01:00
|
|
|
wrapper.appendChild(fullArticle);
|
|
|
|
}
|
2017-01-04 11:01:07 +01:00
|
|
|
|
2017-03-10 16:56:28 +01:00
|
|
|
if (this.config.hideLoading) {
|
|
|
|
this.show();
|
|
|
|
}
|
2016-04-12 11:06:59 +02:00
|
|
|
|
2016-03-29 15:44:43 +02:00
|
|
|
} else {
|
2017-03-10 16:56:28 +01:00
|
|
|
if (this.config.hideLoading) {
|
|
|
|
this.hide();
|
|
|
|
} else {
|
|
|
|
wrapper.innerHTML = this.translate("LOADING");
|
|
|
|
wrapper.className = "small dimmed";
|
|
|
|
}
|
2016-03-29 15:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
},
|
|
|
|
|
2016-04-20 14:39:38 +02:00
|
|
|
/* registerFeeds()
|
|
|
|
* registers the feeds to be used by the backend.
|
2016-03-29 15:44:43 +02:00
|
|
|
*/
|
2016-04-20 14:39:38 +02:00
|
|
|
registerFeeds: function() {
|
|
|
|
for (var f in this.config.feeds) {
|
|
|
|
var feed = this.config.feeds[f];
|
|
|
|
this.sendSocketNotification("ADD_FEED", {
|
|
|
|
feed: feed,
|
|
|
|
config: this.config
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-30 21:15:51 +02:00
|
|
|
/* generateFeed()
|
2016-04-20 14:39:38 +02:00
|
|
|
* Generate an ordered list of items for this configured module.
|
|
|
|
*
|
2017-03-30 21:15:51 +02:00
|
|
|
* attribute feeds object - An object with feeds returned by the node helper.
|
2016-04-20 14:39:38 +02:00
|
|
|
*/
|
|
|
|
generateFeed: function(feeds) {
|
|
|
|
var newsItems = [];
|
|
|
|
for (var feed in feeds) {
|
|
|
|
var feedItems = feeds[feed];
|
|
|
|
if (this.subscribedToFeed(feed)) {
|
|
|
|
for (var i in feedItems) {
|
|
|
|
var item = feedItems[i];
|
|
|
|
item.sourceTitle = this.titleForFeed(feed);
|
2017-03-21 19:39:51 +01:00
|
|
|
if (!(this.config.ignoreOldItems && ((Date.now() - new Date(item.pubdate)) > this.config.ignoreOlderThan))) {
|
|
|
|
newsItems.push(item);
|
|
|
|
}
|
2016-04-20 14:39:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newsItems.sort(function(a,b) {
|
|
|
|
var dateA = new Date(a.pubdate);
|
|
|
|
var dateB = new Date(b.pubdate);
|
|
|
|
return dateB - dateA;
|
2016-03-30 12:20:46 +02:00
|
|
|
});
|
2016-06-06 00:16:49 +02:00
|
|
|
if(this.config.maxNewsItems > 0) {
|
|
|
|
newsItems = newsItems.slice(0, this.config.maxNewsItems);
|
|
|
|
}
|
Added ability to set a list of prohibited words that will be filtered out of newsfeed
Resolves #1071
`prohibitedWords` config parameter is an array of words. If set and case insensitive greedy match is found anywhere in the title then that newsfeed item will not be displayed. Readme updated with instructions.
Users should be careful on the words selection as careless setting may remove many or all items from the newsfeed. Some obvious mistakes like `space, comma, dot` etc. can be prevented programatically, but I left it out of this PR
Example:
with `prohibitedWords: ['dodgers']`
Original `newsItems`:
```
0:{title: "New York City, Russia, Los Angeles Dodgers: Your Wednesday Briefing", description: "Here’s what you need to know to start your day.", pubdate: "Wed, 01 Nov 2017 09:37:36 GMT", url: "https://www.nytimes.com/2017/11/01/briefing/new-yo…ssia-los-angeles-dodgers.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
1:{title: "A Mangled School Bus, Bodies Everywhere; ‘It Was Surreal’", description: "A truck ramming bicyclists. The driver emerging wi…e attack, it was as confusing as it was gruesome.", pubdate: "Wed, 01 Nov 2017 09:27:41 GMT", url: "https://www.nytimes.com/2017/10/31/nyregion/nyc-sc…r-attack-truck-witnesses.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
2:{title: "Dodgers 3, Astros 1 | Series tied, 3-3: With a Rally and a Romp, Dodgers Top Astros and Force Game 7", description: "Down by a run with just four innings left in Game …nst a dominating Justin Verlander. Game 7 awaits.", pubdate: "Wed, 01 Nov 2017 07:21:07 GMT", url: "https://www.nytimes.com/2017/11/01/sports/dodgers-win-game-6.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
3:{title: "José Andrés Fed Puerto Rico, and May Change How Aid Is Given", description: "The chef’s huge effort is just the latest led by c…ocally based way to feed people after a disaster.", pubdate: "Wed, 01 Nov 2017 06:40:09 GMT", url: "https://www.nytimes.com/2017/10/30/dining/jose-andres-puerto-rico.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
```
Filtered `newsItems`:
```
0:{title: "A Mangled School Bus, Bodies Everywhere; ‘It Was Surreal’", description: "A truck ramming bicyclists. The driver emerging wi…e attack, it was as confusing as it was gruesome.", pubdate: "Wed, 01 Nov 2017 09:27:41 GMT", url: "https://www.nytimes.com/2017/10/31/nyregion/nyc-sc…r-attack-truck-witnesses.html?partner=rss&emc=rss", sourceTitle: "New York Times"}
1:{title: "José Andrés Fed Puerto Rico, and May Change How Aid Is Given", description: "The chef’s huge effort is just the latest led by c…ocally based way to feed people after a disaster.", pubdate: "Wed, 01 Nov 2017 06:40:09 GMT", url: "https://www.nytimes.com/2017/10/30/dining/jose
```
2017-11-01 03:40:32 -07:00
|
|
|
|
|
|
|
if(this.config.prohibitedWords.length > 0) {
|
|
|
|
newsItems = newsItems.filter(function(value){
|
|
|
|
for (var i=0; i < this.config.prohibitedWords.length; i++) {
|
|
|
|
if (value["title"].toLowerCase().indexOf(this.config.prohibitedWords[i].toLowerCase()) > -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
2016-04-20 14:39:38 +02:00
|
|
|
this.newsItems = newsItems;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* subscribedToFeed(feedUrl)
|
|
|
|
* Check if this module is configured to show this feed.
|
|
|
|
*
|
|
|
|
* attribute feedUrl string - Url of the feed to check.
|
|
|
|
*
|
|
|
|
* returns bool
|
|
|
|
*/
|
|
|
|
subscribedToFeed: function(feedUrl) {
|
|
|
|
for (var f in this.config.feeds) {
|
|
|
|
var feed = this.config.feeds[f];
|
|
|
|
if (feed.url === feedUrl) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2017-03-30 21:15:51 +02:00
|
|
|
/* titleForFeed(feedUrl)
|
2016-04-20 14:39:38 +02:00
|
|
|
* Returns title for a specific feed Url.
|
|
|
|
*
|
|
|
|
* attribute feedUrl string - Url of the feed to check.
|
|
|
|
*
|
|
|
|
* returns string
|
|
|
|
*/
|
|
|
|
titleForFeed: function(feedUrl) {
|
|
|
|
for (var f in this.config.feeds) {
|
|
|
|
var feed = this.config.feeds[f];
|
|
|
|
if (feed.url === feedUrl) {
|
2016-12-01 19:48:53 -03:00
|
|
|
return feed.title || "";
|
2016-04-20 14:39:38 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-01 19:48:53 -03:00
|
|
|
return "";
|
2016-03-29 15:44:43 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/* scheduleUpdateInterval()
|
|
|
|
* Schedule visual update.
|
|
|
|
*/
|
|
|
|
scheduleUpdateInterval: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.updateDom(self.config.animationSpeed);
|
|
|
|
|
2017-01-04 10:46:31 +01:00
|
|
|
timer = setInterval(function() {
|
2016-03-29 15:44:43 +02:00
|
|
|
self.activeItem++;
|
|
|
|
self.updateDom(self.config.animationSpeed);
|
|
|
|
}, this.config.updateInterval);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* capitalizeFirstLetter(string)
|
|
|
|
* Capitalizes the first character of a string.
|
|
|
|
*
|
|
|
|
* argument string string - Input string.
|
|
|
|
*
|
|
|
|
* return string - Capitalized output string.
|
|
|
|
*/
|
|
|
|
capitalizeFirstLetter: function(string) {
|
2016-04-05 14:35:11 -04:00
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
2016-08-27 00:32:47 +02:00
|
|
|
},
|
2017-01-04 11:01:07 +01:00
|
|
|
|
2017-01-08 14:38:16 +01:00
|
|
|
resetDescrOrFullArticleAndTimer: function() {
|
2018-05-15 20:32:02 -04:00
|
|
|
this.isShowingDescription = this.config.showDescription;
|
2017-01-08 14:38:16 +01:00
|
|
|
this.config.showFullArticle = false;
|
2018-01-29 21:26:34 +01:00
|
|
|
this.scrollPosition = 0;
|
|
|
|
// reset bottom bar alignment
|
|
|
|
document.getElementsByClassName("region bottom bar")[0].style.bottom = "0";
|
|
|
|
document.getElementsByClassName("region bottom bar")[0].style.top = "inherit";
|
2017-01-08 14:38:16 +01:00
|
|
|
if(!timer){
|
|
|
|
this.scheduleUpdateInterval();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-01-04 10:46:31 +01:00
|
|
|
notificationReceived: function(notification, payload, sender) {
|
2017-01-06 21:57:30 +01:00
|
|
|
Log.info(this.name + " - received notification: " + notification);
|
|
|
|
if(notification == "ARTICLE_NEXT"){
|
|
|
|
var before = this.activeItem;
|
|
|
|
this.activeItem++;
|
|
|
|
if (this.activeItem >= this.newsItems.length) {
|
|
|
|
this.activeItem = 0;
|
2017-01-04 10:46:31 +01:00
|
|
|
}
|
2017-01-08 14:38:16 +01:00
|
|
|
this.resetDescrOrFullArticleAndTimer();
|
2017-01-06 21:57:30 +01:00
|
|
|
Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
|
|
|
|
this.updateDom(100);
|
|
|
|
} else if(notification == "ARTICLE_PREVIOUS"){
|
|
|
|
var before = this.activeItem;
|
|
|
|
this.activeItem--;
|
|
|
|
if (this.activeItem < 0) {
|
|
|
|
this.activeItem = this.newsItems.length - 1;
|
2017-01-04 10:46:31 +01:00
|
|
|
}
|
2017-01-08 14:38:16 +01:00
|
|
|
this.resetDescrOrFullArticleAndTimer();
|
2017-01-06 21:57:30 +01:00
|
|
|
Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
|
|
|
|
this.updateDom(100);
|
|
|
|
}
|
2017-01-08 14:38:16 +01:00
|
|
|
// if "more details" is received the first time: show article summary, on second time show full article
|
|
|
|
else if(notification == "ARTICLE_MORE_DETAILS"){
|
2018-01-29 21:26:34 +01:00
|
|
|
// full article is already showing, so scrolling down
|
|
|
|
if(this.config.showFullArticle == true){
|
|
|
|
this.scrollPosition += this.config.scrollLength;
|
|
|
|
window.scrollTo(0, this.scrollPosition);
|
|
|
|
Log.info(this.name + " - scrolling down");
|
|
|
|
Log.info(this.name + " - ARTICLE_MORE_DETAILS, scroll position: " + this.config.scrollLength);
|
|
|
|
}
|
|
|
|
else {
|
2018-07-07 16:35:07 +02:00
|
|
|
this.showFullArticle();
|
2018-01-29 21:26:34 +01:00
|
|
|
}
|
2018-04-17 00:25:58 +02:00
|
|
|
} else if(notification == "ARTICLE_SCROLL_UP"){
|
|
|
|
if(this.config.showFullArticle == true){
|
|
|
|
this.scrollPosition -= this.config.scrollLength;
|
|
|
|
window.scrollTo(0, this.scrollPosition);
|
|
|
|
Log.info(this.name + " - scrolling up");
|
|
|
|
Log.info(this.name + " - ARTICLE_SCROLL_UP, scroll position: " + this.config.scrollLength);
|
|
|
|
}
|
2017-01-06 21:57:30 +01:00
|
|
|
} else if(notification == "ARTICLE_LESS_DETAILS"){
|
2017-01-08 14:38:16 +01:00
|
|
|
this.resetDescrOrFullArticleAndTimer();
|
2017-01-06 21:57:30 +01:00
|
|
|
Log.info(this.name + " - showing only article titles again");
|
|
|
|
this.updateDom(100);
|
2018-07-07 16:35:07 +02:00
|
|
|
} else if (notification == "ARTICLE_TOGGLE_FULL"){
|
|
|
|
if (this.config.showFullArticle){
|
|
|
|
this.activeItem++;
|
|
|
|
this.resetDescrOrFullArticleAndTimer();
|
|
|
|
} else {
|
|
|
|
this.showFullArticle();
|
|
|
|
}
|
2017-01-06 21:57:30 +01:00
|
|
|
} else {
|
|
|
|
Log.info(this.name + " - unknown notification, ignoring: " + notification);
|
2017-01-04 10:46:31 +01:00
|
|
|
}
|
|
|
|
},
|
2016-08-27 00:32:47 +02:00
|
|
|
|
2018-07-07 16:35:07 +02:00
|
|
|
showFullArticle: function() {
|
|
|
|
this.isShowingDescription = !this.isShowingDescription;
|
|
|
|
this.config.showFullArticle = !this.isShowingDescription;
|
|
|
|
// make bottom bar align to top to allow scrolling
|
|
|
|
if(this.config.showFullArticle == true){
|
|
|
|
document.getElementsByClassName("region bottom bar")[0].style.bottom = "inherit";
|
|
|
|
document.getElementsByClassName("region bottom bar")[0].style.top = "-90px";
|
|
|
|
}
|
|
|
|
clearInterval(timer);
|
|
|
|
timer = null;
|
|
|
|
Log.info(this.name + " - showing " + this.isShowingDescription ? "article description" : "full article");
|
|
|
|
this.updateDom(100);
|
|
|
|
}
|
|
|
|
|
2016-03-29 15:44:43 +02:00
|
|
|
});
|