-
Notifications
You must be signed in to change notification settings - Fork 1
/
RDP.js
204 lines (184 loc) · 6.52 KB
/
RDP.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Template Name: Radio DePaul Custom JavaScript
* Author : Matthew Mola
* Date: 3/7/2021
* Version 1.2
*/
//Define Variables
var title, artist, album, artwork, rdptext, rdp = "";
var urlCoverArt, urlCoverArt96, urlCoverArt128, urlCoverArt192, urlCoverArt256, urlCoverArt384;
rdptext = "Radio DePaul";
//Set the reloading
document.onload = getStreamingData();
window.onload = function() {
document.getElementById('player_desk_title').style.display = 'none';
};
window.onload = function () {
getStreamingData();
// Interval to get streaming data in miliseconds
setInterval(function () {
getStreamingData();
}, 5000);
}
function togglePlay() {
var audio = document.getElementsByTagName("audio")[0];
if (audio) {
if (audio.paused) {
audio.play();
document.getElementById("player_desk_button").className = "fas fa-pause-circle fa-3x";
document.getElementById("player_mob_button").className = "fas fa-pause-circle fa-3x";
} else {
audio.pause();
document.getElementById("player_desk_button").className = "fas fa-play-circle fa-3x";
document.getElementById("player_mob_button").className = "fas fa-play-circle fa-3x";
}
}
}
function getStreamingData()
{
//Get the rest of the data
fetch("https://radiodepaul.com/json/radiodepaul.json").then((response) => { return response.json() }).then((data) =>
{
//Work with JSON data here
rdp = JSON.parse(JSON.stringify(data));
artist = rdp.artist;
title = rdp.song;
artwork = rdp.artwork;
album = rdptext;
//title = "The Poor Fisherman (LP Version-1972)";
//artist = "Yusef Lateef";
//Main Title and The Attack on the Jakku Village
//John Williams
//My Brain Is Hanging Upside Down (Bonzo Goes To Bitburg)
//Ramones
//title = "In This Temple As In The Hearts Of Man For Whom He Saved The Earth";
//title = "Damita Menezes";
//artist = "Damita Menezes Damita";
//Set Current Song and Artwork
title = title.replace(/ \([\s\S]*?\)/g, '');
document.getElementById("player_desk_title").innerHTML = title;
document.getElementById("player_desk_artist").innerHTML = artist;
document.getElementById("player_mob_title").innerHTML = title;
document.getElementById("player_mob_artist").innerHTML = artist;
document.getElementById("player_desk_artwork").src = artwork;
document.getElementById("player_mob_artwork").src = artwork;
document.getElementsByClassName("player_desk")[0].style.display = "block";
//Cover Art Resizing for Media Session
urlCoverArt = (artwork != urlCoverArt) ? artwork.replace('170x170bb', '512x512bb') : urlCoverArt;
urlCoverArt96 = (artwork != urlCoverArt) ? urlCoverArt.replace('512x512bb', '96x96bb') : urlCoverArt;
urlCoverArt128 = (artwork != urlCoverArt) ? urlCoverArt.replace('512x512bb', '128x128bb') : urlCoverArt;
urlCoverArt192 = (artwork != urlCoverArt) ? urlCoverArt.replace('512x512bb', '192x192bb') : urlCoverArt;
urlCoverArt256 = (artwork != urlCoverArt) ? urlCoverArt.replace('512x512bb', '256x256bb') : urlCoverArt;
urlCoverArt384 = (artwork != urlCoverArt) ? urlCoverArt.replace('512x512bb', '384x384bb') : urlCoverArt;
//Set Cover Art to Cover if cover.jpg is detected
if(artwork.includes("cover.jpg"))
{
urlCoverArt = artwork;
}
//Final Media Session
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: title,
artist: artist,
album: album,
artwork: [{
src: urlCoverArt96,
sizes: '96x96',
type: 'image/png'
},
{
src: urlCoverArt128,
sizes: '128x128',
type: 'image/png'
},
{
src: urlCoverArt192,
sizes: '192x192',
type: 'image/png'
},
{
src: urlCoverArt256,
sizes: '256x256',
type: 'image/png'
},
{
src: urlCoverArt384,
sizes: '384x384',
type: 'image/png'
},
{
src: urlCoverArt,
sizes: '512x512',
type: 'image/png'
}
]
});
}
})
}
jQuery(document).ready(function($)
{
//Set Button text to dropdown item text when clicked
$(".dropdown-menu a").click(function () {
var selText = $(this).text();
$(".dropdown-toggle").html(selText);
});
//Set Button class active when clicked
$(".btn").click(function ()
{
$(".btn").removeClass("active");
$(this).addClass("active");
});
//Set Dropdown class active when clicked
$(".dropdown-item").click(function ()
{
$(".dropdown-item").removeClass("active");
$(this).addClass("active");
});
//Load More Script for News
//Hides All Posts by default
$("#all-posts div.post-row").hide();
//Shows the first two by default
$("#all-posts div.post-row").slice(0, 5).show().addClass("d-flex");
//Button adds two more posts
$(".all-load-more").click(function(){
var showing = $("#all-posts .post-row:visible").length;
$("#all-posts .post-row").slice(showing - 1, showing + 5).show().addClass("d-flex");
});
//Hides Entertainment Posts by default
$("#entertainment-posts div.post-row").hide();
//Shows the first two by default
$("#entertainment-posts div.post-row").slice(0, 5).show().addClass("d-flex");
//Button adds two more posts
$(".entertainment-load-more").click(function(){
var showing = $("#entertainment-posts .post-row:visible").length;
$("#entertainment-posts .post-row").slice(showing - 1, showing + 5).show().addClass("d-flex");
});
//Hides News Posts by default
$("#news-posts div.post-row").hide();
//Shows the first two by default
$("#news-posts div.post-row").slice(0, 5).show().addClass("d-flex");
//Button adds two more posts
$(".news-load-more").click(function(){
var showing = $("#news-posts .post-row:visible").length;
$("#news-posts .post-row").slice(showing - 1, showing + 5).show().addClass("d-flex");
});
//Hides Podcasts Posts by default
$("#podcasts-posts div.post-row").hide();
//Shows the first two by default
$("#podcasts-posts div.post-row").slice(0, 5).show().addClass("d-flex");
//Button adds two more posts
$(".podcasts-load-more").click(function(){
var showing = $("#podcasts-posts .post-row:visible").length;
$("#podcasts-posts .post-row").slice(showing - 1, showing + 5).show().addClass("d-flex");
});
//Hides Newsletter Posts by default
$("#newsletter-posts div.post-row").hide();
//Shows the first two by default
$("#newsletter-posts div.post-row").slice(0, 5).show().addClass("d-flex");
//Button adds two more posts
$(".newsletter-load-more").click(function(){
var showing = $("#newsletter-posts .post-row:visible").length;
$("#newsletter-posts .post-row").slice(showing - 1, showing + 5).show().addClass("d-flex");
});
});