youtube autoplay works

This commit is contained in:
2025-08-04 22:35:47 -04:00
parent 73a65095df
commit bf597be39e
+55 -28
View File
@@ -551,7 +551,6 @@
</div> </div>
</div> </div>
todo: todo:
<br />add youtube autoplay support
<br />rename stuff | better function names | imageUrl -> mediaUrl | etc. <br />rename stuff | better function names | imageUrl -> mediaUrl | etc.
</body> </body>
@@ -606,7 +605,8 @@
shadowRgba: "rgba(255,255,255,.90)", shadowRgba: "rgba(255,255,255,.90)",
zIndex: "", zIndex: "",
invertX: false, invertX: false,
invertY: false invertY: false,
autoplay: false
}; };
let wallpaper = ""; let wallpaper = "";
@@ -641,6 +641,7 @@
settings; settings;
sections; sections;
clockIntervalId; clockIntervalId;
youtubeId;
constructor( constructor(
id, id,
@@ -651,7 +652,8 @@
width, width,
imageUrl, imageUrl,
settings, settings,
sections sections,
youtubeId
) { ) {
/* check if id is already used /* check if id is already used
if (containerDataMap.has(name.replace(" ", "-").toLowerCase())) { if (containerDataMap.has(name.replace(" ", "-").toLowerCase())) {
@@ -680,11 +682,34 @@
this.width = width; this.width = width;
this.settings = settings; this.settings = settings;
this.imageUrl = imageUrl; this.imageUrl = imageUrl;
this.youtubeId = youtubeId;
} }
else { else {
numberTotalContainers++; numberTotalContainers++;
if (name == "") this.name = "image " + numberOfImageContainers;
else this.name = name; if (imageUrl.includes("youtu.be")) {
this.youtubeId = imageUrl.slice(imageUrl.indexOf(".be/")+4, imageUrl.length);
}
else if (imageUrl.includes("youtube.com")) {
// normal youtube.com link
this.youtubeId = imageUrl.slice(imageUrl.indexOf("v=")+2, imageUrl.length);
if (this.youtubeId.includes("&")) {
this.youtubeId = this.youtubeId.slice(0, this.youtubeId.indexOf("&"));
}
}
if (name == "") {
if (this.videoId != undefined) {
this.name = "video " + numberOfImageContainers;
}
else {
this.name = "image " + numberOfImageContainers;
}
}
else {
this.name = name;
}
this.id = findLowestAvailableId(); this.id = findLowestAvailableId();
this.imageUrl = imageUrl; this.imageUrl = imageUrl;
@@ -696,7 +721,7 @@
this.settings.zIndex = numberOfImageContainers + numberOfTextContainers; this.settings.zIndex = numberOfImageContainers + numberOfTextContainers;
} }
if (imageUrl.includes("youtube.com") || imageUrl.includes("youtu.be")) { if (this.youtubeId != undefined) {
this.initializeYoutubeContainer(); this.initializeYoutubeContainer();
} }
else { else {
@@ -762,25 +787,10 @@
} }
initializeYoutubeContainer() { initializeYoutubeContainer() {
let link = this.imageUrl; let embedLink = "https://www.youtube.com/embed/" + this.youtubeId;
if (this.settings.autoplay) {
let videoId; embedLink += "?autoplay=1";
if (link.includes("youtu.be")) {
videoId = link.slice(link.indexOf(".be/")+4, link.length);
} }
else {
// normal youtube.com link
videoId = link.slice(link.indexOf("v=")+2, link.length);
if (videoId.includes("&")) {
videoId = videoId.slice(0, videoId.indexOf("&"));
}
}
let embedLink = "https://www.youtube.com/embed/" + videoId;
// if (this.settings.autoplay) {
// embedLink += "autoplay=1";
// }
document.body.insertAdjacentHTML( document.body.insertAdjacentHTML(
"beforeend", "beforeend",
@@ -1349,7 +1359,11 @@
`; `;
let youtubeEmbedOptions = ` let youtubeEmbedOptions = `
<p class="menuHeader">youtube autoplay</p>
<div class="containerOptionListing">
<label for=${this.id + "-settings-youtube-autoplay"}>autoplay on load?</label>
<input id=${this.id + "-settings-youtube-autoplay"} type="checkbox" onclick="toggleYoutubeAutoplay(this)" />
</div>
`; `;
document.getElementById("containers").insertAdjacentHTML( document.getElementById("containers").insertAdjacentHTML(
@@ -1429,6 +1443,8 @@
<label for=${this.id + "-settings-mirror-y"}>mirror vertically</label> <label for=${this.id + "-settings-mirror-y"}>mirror vertically</label>
<input id=${this.id + "-settings-mirror-y"} type="checkbox" /> <input id=${this.id + "-settings-mirror-y"} type="checkbox" />
</div> </div>
${this.youtubeId ? youtubeEmbedOptions : ``}
</div> </div>
<div class="manageButtons"> <div class="manageButtons">
@@ -1959,7 +1975,8 @@
containerMapValues[i].width, containerMapValues[i].width,
containerMapValues[i].imageUrl, containerMapValues[i].imageUrl,
containerMapValues[i].settings, containerMapValues[i].settings,
containerMapValues[i].sections containerMapValues[i].sections,
containerMapValues[i].youtubeId
)); ));
} }
@@ -2241,6 +2258,7 @@
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined,
undefined undefined
); );
@@ -2269,7 +2287,8 @@
undefined, undefined,
imageUrl, imageUrl,
undefined, undefined,
undefined undefined,
undefined,
); );
container.createImageContainerMenuListing(); container.createImageContainerMenuListing();
@@ -2454,7 +2473,8 @@
container.width, container.width,
container.imageUrl, container.imageUrl,
newSettings, newSettings,
container.sections container.sections,
container.youtubeId
); );
zIndexMap.set(numberTotalContainers + 1, clone.id); zIndexMap.set(numberTotalContainers + 1, clone.id);
@@ -3179,6 +3199,13 @@
} }
} }
function toggleYoutubeAutoplay(checkbox) {
let containerId = checkbox.id.split("-settings")[0];
let container = containerDataMap.get(containerId);
container.settings.autoplay = checkbox.checked;
}
/************************************ /************************************
* RESET / IMPORT & EXPORT HANDLERS * * RESET / IMPORT & EXPORT HANDLERS *
************************************/ ************************************/