52 lines
No EOL
2 KiB
JavaScript
52 lines
No EOL
2 KiB
JavaScript
"use strict";
|
|
|
|
function removeAcastBranding(description,removeBR) { // Retire la mention "hébergé par Acast"
|
|
let desc = description.replace(/(<br><hr>\n<p>).+(<\/p>)/g,"");
|
|
if (removeBR) { desc = desc.replace(/<br>/g,"") }
|
|
return desc
|
|
}
|
|
|
|
async function fetchRSSfeed() {
|
|
const RSS_URL = 'https://feeds.acast.com/public/shows/le-plus-beau-des-voyages';
|
|
const response = await fetch("https://api.rss2json.com/v1/api.json?rss_url=" + RSS_URL);
|
|
return await response.json();
|
|
}
|
|
|
|
function formatEpisodeIntoHTML(episode) {
|
|
|
|
const article = document.createElement("article");
|
|
article.className = "podcast";
|
|
|
|
const podcastTitle = document.createElement("h3");
|
|
podcastTitle.innerHTML = episode.title;
|
|
|
|
const podcastAudio = document.createElement("audio");
|
|
podcastAudio.setAttribute("controls",true);
|
|
podcastAudio.setAttribute("src",episode.enclosure.link);
|
|
podcastAudio.setAttribute("type",episode.enclosure.type);
|
|
podcastAudio.setAttribute("length",episode.enclosure.length)
|
|
podcastAudio.setAttribute("duration",episode.enclosure.duration)
|
|
|
|
const podcastDescription = document.createElement("div");
|
|
podcastDescription.className = "podcast-desc"
|
|
podcastDescription.innerHTML = removeAcastBranding(episode.description,true);
|
|
|
|
article.append(podcastTitle,podcastAudio,podcastDescription);
|
|
|
|
return article
|
|
}
|
|
|
|
window.addEventListener("DOMContentLoaded", function () {
|
|
console.log(
|
|
"Hewo, c'est renarde 🦊, la créatrice de ce site. Si tu veux trouver le code source du site c'est par ici -> "
|
|
+ 'https://forgejo.la-taniere-solidaire.gay/'
|
|
);
|
|
|
|
fetchRSSfeed().then( rssData => {
|
|
document.getElementById("FeedDesc").innerHTML = removeAcastBranding(rssData.feed.description,false);
|
|
for (const episode of rssData.items) {
|
|
const formatedEp = formatEpisodeIntoHTML(episode)
|
|
this.document.getElementById("Podcasts").append(formatedEp)
|
|
}
|
|
})
|
|
}) |