Merge pull request #416 from yo-less/master

Tags at the beginning and/or end of newsfeed items
This commit is contained in:
Michael Teeuw 2016-08-27 12:00:28 +02:00 committed by GitHub
commit 2ae0c98b4c
2 changed files with 84 additions and 4 deletions

View File

@ -108,7 +108,37 @@ The following properties can be configured:
<br><b>Default value:</b> <code>0</code> <br><b>Default value:</b> <code>0</code>
</td> </td>
</tr> </tr>
removeStartTags: false,
removeEndTags: false,
startTags: [],
endTags: []
<tr>
<td><code>removeStartTags</code></td>
<td>Some newsfeeds feature tags at the <B>beginning</B> of their titles or descriptions, such as <em>[VIDEO]</em>.
This setting allows for the removal of specified tags from the beginning of an item's description and/or title.<br>
<br><b>Possible values:</b><code>'none'</code>,<code>description</code>, <code>title</code>, <code>both</code>
</td>
</tr>
<tr>
<td><code>startTags</code></td>
<td>List the tags you would like to have removed at the beginning of the feed item<br>
<br><b>Possible values:</b> <code>['TAG']</code> or <code>['TAG1','TAG2',...]</code>
</td>
</tr>
<tr>
<td><code>removeEndTags</code></td>
<td>Remove specified tags from the <B>end</B> of an item's description and/or title.<br>
<br><b>Possible values:</b><code>description</code>, <code>title</code>, <code>both</code>
</td>
</tr>
<tr>
<td><code>endTags</code></td>
<td>List the tags you would like to have removed at the end of the feed item<br>
<br><b>Possible values:</b> <code>['TAG']</code> or <code>['TAG1','TAG2',...]</code>
</td>
</tr>
</tbody> </tbody>
</table> </table>

View File

@ -24,7 +24,12 @@ Module.register("newsfeed",{
reloadInterval: 5 * 60 * 1000, // every 5 minutes reloadInterval: 5 * 60 * 1000, // every 5 minutes
updateInterval: 10 * 1000, updateInterval: 10 * 1000,
animationSpeed: 2.5 * 1000, animationSpeed: 2.5 * 1000,
maxNewsItems: 0 // 0 for unlimited maxNewsItems: 0, // 0 for unlimited
removeStartTags: '',
removeEndTags: '',
startTags: [],
endTags: []
}, },
// Define required scripts. // Define required scripts.
@ -96,6 +101,49 @@ Module.register("newsfeed",{
wrapper.appendChild(sourceAndTimestamp); wrapper.appendChild(sourceAndTimestamp);
} }
//Remove selected tags from the beginning of rss feed items (title or description)
if (this.config.removeStartTags == 'title' || 'both') {
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.removeStartTags == 'description' || 'both') {
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"); var title = document.createElement("div");
title.className = "bright medium light"; title.className = "bright medium light";
title.innerHTML = this.newsItems[this.activeItem].title; title.innerHTML = this.newsItems[this.activeItem].title;
@ -215,5 +263,7 @@ Module.register("newsfeed",{
*/ */
capitalizeFirstLetter: function(string) { capitalizeFirstLetter: function(string) {
return string.charAt(0).toUpperCase() + string.slice(1); return string.charAt(0).toUpperCase() + string.slice(1);
} },
}); });