This commit is contained in:
ashley 2024-08-27 23:08:56 +00:00
parent 9e3eeb277e
commit 1370c899fa

View file

@ -2105,63 +2105,69 @@ if (/[?&]autoplay=/.test(location.search)) {
<% if(!IsOldWindows) { %> <% if(!IsOldWindows) { %>
<script> <script>
const AMvideo = document.getElementById("video"); const AMvideo = document.getElementById("video")
const oddCanvas = document.getElementById("ambient-canvas-1"); const oddCanvas = document.getElementById("ambient-canvas-1")
const evenCanvas = document.getElementById("ambient-canvas-2"); const evenCanvas = document.getElementById("ambient-canvas-2")
const oddCtx = oddCanvas.getContext("2d"); const oddCtx = oddCanvas.getContext("2d")
const evenCtx = evenCanvas.getContext("2d"); const evenCtx = evenCanvas.getContext("2d")
const canvasOpacity = "0.4"; const frameIntervalMs = 998
const baseFrameIntervalMs = 500; const canvasOpacity = "0.4"
let intervalId;
let oddFrame = true;
const getFrameInterval = () => { let intervalId
const coreCount = navigator.hardwareConcurrency || 2; let oddFrame = true
return Math.max(baseFrameIntervalMs / coreCount, 33); let numWorkers = navigator.hardwareConcurrency || 4
};
const drawFrame = () => { const drawFrame = () => {
const ctx = oddFrame ? oddCtx : evenCtx; if (oddFrame) {
const canvas = oddFrame ? oddCanvas : evenCanvas; oddCtx.drawImage(AMvideo, 0, 0, oddCanvas.width, oddCanvas.height)
transitionToOddCanvas()
ctx.drawImage(AMvideo, 0, 0, canvas.width, canvas.height); } else {
oddCanvas.style.opacity = oddFrame ? canvasOpacity : "0"; evenCtx.drawImage(AMvideo, 0, 0, evenCanvas.width, evenCanvas.height)
evenCanvas.style.opacity = oddFrame ? "0" : canvasOpacity; transitionToEvenCanvas()
}
oddFrame = !oddFrame; oddFrame = !oddFrame
}; };
const transitionToOddCanvas = () => {
oddCanvas.style.opacity = canvasOpacity
evenCanvas.style.opacity = "0"
}
const transitionToEvenCanvas = () => {
evenCanvas.style.opacity = canvasOpacity
oddCanvas.style.opacity = "0"
}
const drawStart = () => { const drawStart = () => {
const frameIntervalMs = getFrameInterval(); intervalId = window.setInterval(drawFrame, frameIntervalMs / numWorkers)
intervalId = setInterval(drawFrame, frameIntervalMs); }
};
const drawPause = () => { const drawPause = () => {
if (intervalId) clearInterval(intervalId); if (intervalId) window.clearInterval(intervalId)
}; }
const init = () => { const init = () => {
AMvideo.pause(); // fixes a issue where firefox/chromium fails to load the ambinet mode and doesnt load it. - please dont remove this line lmao
AMvideo.play(); video.pause();video.play();
AMvideo.addEventListener("play", drawStart, false);
AMvideo.addEventListener("pause", drawPause, false);
AMvideo.addEventListener("ended", drawPause, false);
const frameIntervalMs = getFrameInterval(); // DO NOT REMOVE
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs}ms`; AMvideo.addEventListener("play", drawStart, false)
}; AMvideo.addEventListener("pause", drawPause, false)
AMvideo.addEventListener("ended", drawPause, false)
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs / numWorkers}ms`
}
const cleanup = () => { const cleanup = () => {
AMvideo.removeEventListener("play", drawStart); AMvideo.removeEventListener("play", drawStart)
AMvideo.removeEventListener("pause", drawPause); AMvideo.removeEventListener("pause", drawPause)
AMvideo.removeEventListener("ended", drawPause); AMvideo.removeEventListener("ended", drawPause)
drawPause(); drawPause();
}; }
window.addEventListener("load", init);
window.addEventListener("unload", cleanup);
window.addEventListener("load", init)
window.addEventListener("unload", cleanup)
</script> </script>
<style> <style>