mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 03:18:56 +01:00
awa
This commit is contained in:
parent
9e3eeb277e
commit
1370c899fa
1 changed files with 48 additions and 42 deletions
|
@ -2105,63 +2105,69 @@ if (/[?&]autoplay=/.test(location.search)) {
|
|||
<% if(!IsOldWindows) { %>
|
||||
|
||||
<script>
|
||||
const AMvideo = document.getElementById("video");
|
||||
const oddCanvas = document.getElementById("ambient-canvas-1");
|
||||
const evenCanvas = document.getElementById("ambient-canvas-2");
|
||||
const oddCtx = oddCanvas.getContext("2d");
|
||||
const evenCtx = evenCanvas.getContext("2d");
|
||||
const AMvideo = document.getElementById("video")
|
||||
const oddCanvas = document.getElementById("ambient-canvas-1")
|
||||
const evenCanvas = document.getElementById("ambient-canvas-2")
|
||||
const oddCtx = oddCanvas.getContext("2d")
|
||||
const evenCtx = evenCanvas.getContext("2d")
|
||||
|
||||
const canvasOpacity = "0.4";
|
||||
const baseFrameIntervalMs = 500;
|
||||
let intervalId;
|
||||
let oddFrame = true;
|
||||
const frameIntervalMs = 998
|
||||
const canvasOpacity = "0.4"
|
||||
|
||||
const getFrameInterval = () => {
|
||||
const coreCount = navigator.hardwareConcurrency || 2;
|
||||
return Math.max(baseFrameIntervalMs / coreCount, 33);
|
||||
};
|
||||
let intervalId
|
||||
let oddFrame = true
|
||||
let numWorkers = navigator.hardwareConcurrency || 4
|
||||
|
||||
const drawFrame = () => {
|
||||
const ctx = oddFrame ? oddCtx : evenCtx;
|
||||
const canvas = oddFrame ? oddCanvas : evenCanvas;
|
||||
|
||||
ctx.drawImage(AMvideo, 0, 0, canvas.width, canvas.height);
|
||||
oddCanvas.style.opacity = oddFrame ? canvasOpacity : "0";
|
||||
evenCanvas.style.opacity = oddFrame ? "0" : canvasOpacity;
|
||||
|
||||
oddFrame = !oddFrame;
|
||||
if (oddFrame) {
|
||||
oddCtx.drawImage(AMvideo, 0, 0, oddCanvas.width, oddCanvas.height)
|
||||
transitionToOddCanvas()
|
||||
} else {
|
||||
evenCtx.drawImage(AMvideo, 0, 0, evenCanvas.width, evenCanvas.height)
|
||||
transitionToEvenCanvas()
|
||||
}
|
||||
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 frameIntervalMs = getFrameInterval();
|
||||
intervalId = setInterval(drawFrame, frameIntervalMs);
|
||||
};
|
||||
intervalId = window.setInterval(drawFrame, frameIntervalMs / numWorkers)
|
||||
}
|
||||
|
||||
const drawPause = () => {
|
||||
if (intervalId) clearInterval(intervalId);
|
||||
};
|
||||
if (intervalId) window.clearInterval(intervalId)
|
||||
}
|
||||
|
||||
const init = () => {
|
||||
AMvideo.pause();
|
||||
AMvideo.play();
|
||||
AMvideo.addEventListener("play", drawStart, false);
|
||||
AMvideo.addEventListener("pause", drawPause, false);
|
||||
AMvideo.addEventListener("ended", drawPause, false);
|
||||
// fixes a issue where firefox/chromium fails to load the ambinet mode and doesnt load it. - please dont remove this line lmao
|
||||
video.pause();video.play();
|
||||
|
||||
const frameIntervalMs = getFrameInterval();
|
||||
oddCanvas.style.transition = evenCanvas.style.transition = `opacity ${frameIntervalMs}ms`;
|
||||
};
|
||||
// DO NOT REMOVE
|
||||
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 = () => {
|
||||
AMvideo.removeEventListener("play", drawStart);
|
||||
AMvideo.removeEventListener("pause", drawPause);
|
||||
AMvideo.removeEventListener("ended", drawPause);
|
||||
AMvideo.removeEventListener("play", drawStart)
|
||||
AMvideo.removeEventListener("pause", drawPause)
|
||||
AMvideo.removeEventListener("ended", drawPause)
|
||||
drawPause();
|
||||
};
|
||||
|
||||
window.addEventListener("load", init);
|
||||
window.addEventListener("unload", cleanup);
|
||||
}
|
||||
|
||||
window.addEventListener("load", init)
|
||||
window.addEventListener("unload", cleanup)
|
||||
|
||||
</script>
|
||||
<style>
|
||||
|
|
Loading…
Reference in a new issue