-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist_embed.js
34 lines (32 loc) · 1.29 KB
/
playlist_embed.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
window.addEventListener("message", function (event) {
const ilp = event.data["playlist-ilp"] || false;
if (ilp) {
var not_done = true;
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('name') === 'monetization') {
metas[i].content = ilp;
not_done = false;
console.log("set ilp to " + ilp + " via event.");
}
}
if (not_done) {
const monetizationTag = document.createElement('meta');
monetizationTag.name = 'monetization';
monetizationTag.content = ilp;
document.head.appendChild(monetizationTag);
console.log("added meta & set ilp to " + ilp + " via event.");
}
}
});
const url = document.currentScript.getAttribute('playlist');
const width = document.currentScript.getAttribute('width') || 300;
const height = document.currentScript.getAttribute('height') || 600;
const container_name = document.currentScript.getAttribute('container') || 'playlist';
const iframe = document.createElement('iframe');
iframe.src = url;
iframe.width = width;
iframe.height = height;
iframe.frameborder = "no";
iframe.allow = "autoplay";
document.currentScript.after(iframe);