2022-02-09 20:11:31 +01:00
|
|
|
// @author rubenwardy
|
|
|
|
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
|
|
|
|
|
2022-01-25 21:48:37 +01:00
|
|
|
document.querySelectorAll(".video-embed").forEach(ele => {
|
2022-01-25 22:52:46 +01:00
|
|
|
try {
|
|
|
|
const href = ele.getAttribute("href");
|
|
|
|
const url = new URL(href);
|
2022-01-25 21:48:37 +01:00
|
|
|
|
2022-01-25 22:52:46 +01:00
|
|
|
if (url.host == "www.youtube.com") {
|
|
|
|
ele.addEventListener("click", () => {
|
|
|
|
ele.parentNode.classList.add("d-block");
|
|
|
|
ele.classList.add("embed-responsive");
|
|
|
|
ele.classList.add("embed-responsive-16by9");
|
|
|
|
ele.innerHTML = `
|
|
|
|
<iframe title="YouTube video player" frameborder="0"
|
|
|
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
|
|
allowfullscreen>
|
|
|
|
</iframe>`;
|
2022-01-25 21:48:37 +01:00
|
|
|
|
2022-01-25 22:52:46 +01:00
|
|
|
const embedURL = new URL("https://www.youtube.com/");
|
|
|
|
embedURL.pathname = "/embed/" + url.searchParams.get("v");
|
|
|
|
embedURL.searchParams.set("autoplay", "1");
|
2022-01-25 21:48:37 +01:00
|
|
|
|
2022-01-25 22:52:46 +01:00
|
|
|
const iframe = ele.children[0];
|
|
|
|
iframe.setAttribute("src", embedURL);
|
|
|
|
});
|
|
|
|
|
|
|
|
ele.setAttribute("data-src", href);
|
|
|
|
ele.removeAttribute("href");
|
2022-01-25 23:13:48 +01:00
|
|
|
|
|
|
|
ele.querySelector(".label").innerText = "YouTube";
|
2022-01-25 22:52:46 +01:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(url);
|
|
|
|
return;
|
2022-01-25 21:48:37 +01:00
|
|
|
}
|
|
|
|
});
|