presse/daily.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-05-23 13:59:38 +02:00
javascript: (function()
{
var map = {
"www.mediapart.fr": "https://www.mediapart.fr/articles/feed",
2024-06-05 12:20:57 +02:00
"www.lemonde.fr": "https://www.lemonde.fr/rss/une.xml",
2024-08-28 14:57:38 +02:00
"www.nytimes.com": "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml",
2024-08-30 16:26:46 +02:00
"reporterre.net": "https://reporterre.net/spip.php?page=backend-simple",
"lesjours.fr": "https://lesjours.fr/rss.xml"
2024-05-23 13:59:38 +02:00
};
var host = window.location.host;
var rssurl = map[window.location.host];
if (!rssurl)
{
alert("unknown newspaper");
}
else
{
fetch(rssurl)
.then(response => response.text())
.then(xmlstring => {
const parser = new DOMParser();
const xmldoc = parser.parseFromString(xmlstring, 'text/xml');
var today = new Date;
items = xmldoc.evaluate("/rss/channel/item", xmldoc);
while ((item = items.iterateNext()))
{
2024-08-28 14:57:38 +02:00
var datenode = item.getElementsByTagName("pubDate");
if (!datenode || !datenode.length)
{
datenode = item.getElementsByTagName("dc:date");
}
var itemdate = new Date(datenode[0].textContent);
2024-05-23 13:59:38 +02:00
var itemlink = item.getElementsByTagName("link")[0].textContent;
if (itemdate.toDateString() == today.toDateString())
{
console.log("will open " + itemlink);
window.open(itemlink, "_blank");
}
}
});
}
})();