presse/daily.js

38 lines
1.0 KiB
JavaScript

javascript: (function()
{
var map = {
"www.mediapart.fr": "https://www.mediapart.fr/articles/feed",
"www.lemonde.fr": "https://www.lemonde.fr/rss/une.xml",
"www.nytimes.com": "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
};
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()))
{
var itemdate = new Date(item.getElementsByTagName("pubDate")[0].textContent);
var itemlink = item.getElementsByTagName("link")[0].textContent;
if (itemdate.toDateString() == today.toDateString())
{
console.log("will open " + itemlink);
window.open(itemlink, "_blank");
}
}
});
}
})();