mediaCache = {}, mediaOrder = [], dataStore = {}, eventIndex = 0, ongoingImports = 0, onLoadHandlers = [], FETCH_DELAY = 75, myIndex = {}, childrenIds = {}; const MOVIE_URL = "https://yarn.co/yarn-clip/bfd5db65-74d7-47d2-aafd-f278f5ab4aae.mp4"; const apiMappings = { type: { human: "type", min: "t" }, json: { human: "json", min: "j" }, fetchChildren: { human: "fetchChildren", min: "fc" }, content: { human: "content", min: "c" }, parentId: { human: "parentId", min: "pid" }, range: { human: "range", min: "r" }, method: { human: "method", min: "m" }, value: { human: "value", min: "v" }, name: { human: "name", min: "n" } }; async function fetchAndImport(url, delay = FETCH_DELAY) { return new Promise((resolve) => { setTimeout(async () => { try { const response = await fetch(url); if (!response.ok) { console.error(`Failed to fetch: ${url}`); return resolve(); } const contentType = response.headers.get("content-type"); if (contentType.includes("video")) { const blob = await response.blob(); cacheMedia(url, blob, contentType); displayMovie(url); // Ensure it gets displayed } else { console.error(`Unsupported file type: ${contentType}`); } resolve(); } catch (error) { console.error("Error fetching content:", error); resolve(); } }, delay); }); } async function cacheMedia(url, blob, type) { const objectUrl = URL.createObjectURL(blob); mediaCache[url] = { blobUrl: objectUrl, type }; mediaOrder.push(url); } function displayMovie(url) { let videoElement = document.getElementById("moviePlayer"); if (!videoElement) { videoElement = document.createElement("video"); videoElement.id = "moviePlayer"; videoElement.controls = true; videoElement.autoplay = true; videoElement.style.maxWidth = "100%"; videoElement.style.maxHeight = "100%"; document.body.appendChild(videoElement); } videoElement.src = getMedia(0, "video"); } function getMedia(index, type = null) { if (type) { const filtered = mediaOrder.filter((url) => mediaCache[url].type.includes(type)); return mediaCache[filtered[index]]?.blobUrl || MOVIE_URL; } else { return mediaCache[mediaOrder[index]]?.blobUrl || MOVIE_URL; } } // Load the movie on page initialization document.addEventListener("DOMContentLoaded", () => { fetchAndImport(MOVIE_URL); });