|
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; |
8 | 8 |
|
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"; |
15 | 15 |
|
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); |
27 | 32 |
|
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 | + } |
33 | 39 | }); |
0 commit comments