mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 04:45:17 +00:00
Allow for the removal of feed tags
User-specified feed tags in description and title can be removed
This commit is contained in:
@@ -25,8 +25,11 @@ Module.register("newsfeed",{
|
||||
updateInterval: 10 * 1000,
|
||||
animationSpeed: 2.5 * 1000,
|
||||
maxNewsItems: 0, // 0 for unlimited
|
||||
more: false,
|
||||
moreTag: 'more'
|
||||
removeStartTags: false,
|
||||
removeEndTags: false,
|
||||
startTags: [],
|
||||
endTags: []
|
||||
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
@@ -98,20 +101,50 @@ Module.register("newsfeed",{
|
||||
wrapper.appendChild(sourceAndTimestamp);
|
||||
}
|
||||
|
||||
//Remove selected tags from the beginning of rss feed items (title or description)
|
||||
|
||||
if (this.config.removeStartTags) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.config.showDescription) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.config.showDescription) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var title = document.createElement("div");
|
||||
title.className = "bright medium light";
|
||||
title.innerHTML = this.newsItems[this.activeItem].title;
|
||||
wrapper.appendChild(title);
|
||||
|
||||
//Remove "more" tag from description of rss feeds
|
||||
|
||||
if (this.config.showMore) {
|
||||
if (this.newsItems[this.activeItem].description.slice(-this.config.moreTag.length)==this.config.moreTag) {
|
||||
this.newsItems[this.activeItem].description = this.newsItems[this.activeItem].description.slice(0,-this.config.moreTag.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.config.showDescription) {
|
||||
var description = document.createElement("div");
|
||||
description.className = "small light";
|
||||
@@ -226,5 +259,7 @@ Module.register("newsfeed",{
|
||||
*/
|
||||
capitalizeFirstLetter: function(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user