Skip to content

Instantly share code, notes, and snippets.

@vladanyes
Created February 15, 2023 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladanyes/b73eb752047b275d069da4d785130bda to your computer and use it in GitHub Desktop.
Save vladanyes/b73eb752047b275d069da4d785130bda to your computer and use it in GitHub Desktop.
external-radio-file
(function(){
'use strict';
var player = {"id":"6f3c055","name":"Default","type":"classic","size":"large","stream":{"station ":"s307b15171","output":null,"streaming_url":"https:\/\/streaming.radio.co\/s307b15171"},"theme":{"width":400,"background_colour":"#efefef","text_colour":"#de000a","accent_colour":"#9f9f9f","rounded_corners":true,"track_information":true},"settings":{"autoplay":true,"artwork":true,"spotify":false,"popout":false},"embed_url":"https:\/\/embed.radio.co\/player\/6f3c055.html","social":{"twitter":true,"facebook_share":true,"embed":true,"template":"Chilled.io"}};
var i = document.createElement('iframe');
var style = "border: none;overflow:hidden;";
var width = player.theme.width;
i.src = player.embed_url;
i.width = '100%';
i.allow = 'autoplay';
if (player.size !== 'small') {
style += 'max-width:' + width + 'px;margin:0 auto;';
}
i.setAttribute('scrolling', 'no');
i.setAttribute('style', style);
var s = document.getElementsByTagName('script');
s = s[s.length-1];
if(s.parentNode.nodeName === 'HEAD'){
window.onload = function() { document.body.appendChild(i); };
}else{
s.parentNode.insertBefore(i, s);
}
window.addEventListener('message', function(e) {
var eventName = e.data[0];
var data = e.data[1];
if(eventName === player.id+'.setHeight') {
i.style.height = data+'px';
}
}, false);
i.addEventListener('load', function(){
var targetUrl = player.embed_url.split('/').splice(0,3).join('/'); // strips everything after hostname
setTimeout(function() {
i.contentWindow.postMessage(JSON.stringify(['parent', location]), targetUrl);
}, 1000); // Prevent the iframe not being ready for messages.
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment