This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
94 lines (63 loc) · 2.08 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var pods = new Array();
window.onload = function(){
document.getElementById('splash_text').innerHTML =
getRandomArrayItem(bjarteNavn) + ", " +
getRandomArrayItem(toreNavn) + " og " +
getRandomArrayItem(steinarNavn)
loadPods();
document.getElementById('random_play_button').addEventListener("click",function(){
playPod(getRandomArrayItem(pods));
})
}
function playPod(pod){
document.getElementById('podcast_audio').src = pod.enclosures[0].url;
document.getElementById('current_playing_pod').innerHTML = pod.title;
document.getElementById('current_playing_div').style.display = "block";
$('html, body').animate({scrollTop: 0}, 200);
}
function loadPods(){
let url= 'http://podkast.nrk.no/program/radioresepsjonen.rss';
$.ajax({
type: 'GET',
url: "https://morning-earth-19323.herokuapp.com/?feedURL=" + url,
dataType: 'json',
success: handlePodsData
});
}
function handlePodsData(data){
pods = data.items;
let podsTable = document.getElementById('podlist_table');
for(pod of pods){
podsTable.appendChild(createPodRow(pod));
}
setClassDisplay("post_pods_load", "block");
setClassDisplay("pre_pods_load", "none");
}
function createPodRow(pod){
let podRow = document.createElement("tr");
podRow.className = "podlist_row";
podRow.addEventListener("click",function(){
playPod(pod);
})
let podData = document.createElement("td");
podData.className = "podlist_item";
let podTitle = document.createElement("p");
podTitle.className = "podlist_title";
podTitle.innerHTML = pod.title;
podData.appendChild(podTitle);
let podDescription = document.createElement("p");
podDescription.className = "podlist_description";
podDescription.innerHTML = pod.description;
podData.appendChild(podDescription);
podRow.appendChild(podData);
return podRow;
}
function getRandomArrayItem(array){
return array[Math.floor(Math.random() * array.length)];
}
function setClassDisplay(className, display){
let elements = document.getElementsByClassName(className);
for(el of elements){
el.style.display = display;
}
}