Skip to content

Commit f69a100

Browse files
committed
fix: yt-with-consent needed minor change
Embeds were broken without that as YT changed something on their end apparently.
1 parent 0c8caf6 commit f69a100

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

assets/js/yt-with-consent.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
$(function() {
2-
// YouTube embeds with consent
3-
var embeds = document.getElementsByClassName("yt-with-consent");
4-
for (var i = 0; i < embeds.length; i++) {
5-
var embed = embeds[i];
6-
var vid = embed.dataset.vid;
7-
if (!vid) continue;
1+
$(function () {
2+
// YouTube embeds with consent
3+
var embeds = document.getElementsByClassName("yt-with-consent");
4+
for (var i = 0; i < embeds.length; i++) {
5+
var embed = embeds[i];
6+
var vid = embed.dataset.vid;
7+
if (!vid) continue;
88

9-
var preview = embed.dataset.preview || "/assets/img/yt-with-consent/" + vid + ".jpg";
10-
embed.style.backgroundImage = "url(" + preview + ")";
11-
embed.style.backgroundSize = "contain";
12-
embed.style.backgroundRepeat = "no-repeat";
13-
embed.style.backgroundPosition = "center";
14-
embed.style.backgroundColor = "black";
9+
var preview = embed.dataset.preview || "/assets/img/yt-with-consent/" + vid + ".jpg";
10+
embed.style.backgroundImage = "url(" + preview + ")";
11+
embed.style.backgroundSize = "contain";
12+
embed.style.backgroundRepeat = "no-repeat";
13+
embed.style.backgroundPosition = "center";
14+
embed.style.backgroundColor = "black";
1515

16-
var button = document.createElement("div");
17-
button.classList.add("play-button");
18-
button.onclick = function () {
19-
var iframe = document.createElement("iframe"),
20-
url = "https://www.youtube-nocookie.com/embed/" + this.parentNode.dataset.vid + "?autoplay=1&rel=0";
21-
iframe.setAttribute("src", url);
22-
iframe.setAttribute("frameborder", "0");
23-
iframe.setAttribute("allowfullscreen", "1");
24-
this.parentNode.parentNode.replaceChild(iframe, this.parentNode);
25-
};
26-
embed.appendChild(button);
16+
var button = document.createElement("div");
17+
button.classList.add("play-button");
18+
button.onclick = function () {
19+
var iframe = document.createElement("iframe"),
20+
url =
21+
"https://www.youtube-nocookie.com/embed/" +
22+
this.parentNode.dataset.vid +
23+
"?autoplay=1&rel=0";
24+
iframe.setAttribute("src", url);
25+
iframe.setAttribute("frameborder", "0");
26+
iframe.setAttribute("allowfullscreen", "1");
27+
iframe.setAttribute("allow", "autoplay; encrypted-media");
28+
iframe.setAttribute("referrerpolicy", "strict-origin-when-cross-origin");
29+
this.parentNode.parentNode.replaceChild(iframe, this.parentNode);
30+
};
31+
embed.appendChild(button);
2732

28-
var disclaimer = document.createElement("div");
29-
disclaimer.classList.add("yt-disclaimer");
30-
disclaimer.innerHTML = "This video will be embedded from Youtube. The <a href='https://policies.google.com/privacy?hl=en' rel='noreferrer noopener' target='_blank'>Privacy Policies of Google</a> apply.";
31-
embed.appendChild(disclaimer);
32-
}
33+
var disclaimer = document.createElement("div");
34+
disclaimer.classList.add("yt-disclaimer");
35+
disclaimer.innerHTML =
36+
"This video will be embedded from Youtube. The <a href='https://policies.google.com/privacy?hl=en' rel='noreferrer noopener' target='_blank'>Privacy Policies of Google</a> apply.";
37+
embed.appendChild(disclaimer);
38+
}
3339
});

0 commit comments

Comments
 (0)