Browse Source

reindent

master
HxxxxxS 2 years ago
parent
commit
7b6ac5fb36
  1. 48
      script.js

48
script.js

@ -166,12 +166,12 @@ window.addEventListener("resize", updateCanvasSize)
function getSourceFiles() { function getSourceFiles() {
debugLog("Getting source files") debugLog("Getting source files")
return fetch("/api/videos") return fetch("/api/videos")
.then(response => response.json()) .then(response => response.json())
.then(videoFiles => { .then(videoFiles => {
debugLog("Success") debugLog("Success")
cachedVideos = videoFiles; cachedVideos = videoFiles;
}) })
.catch(error => console.error("Error fetching videos:", error)); .catch(error => console.error("Error fetching videos:", error));
} }
function selectRandomVideo(videoElement) { function selectRandomVideo(videoElement) {
@ -179,14 +179,14 @@ function selectRandomVideo(videoElement) {
const currentSrc = videoElement.src; const currentSrc = videoElement.src;
const filteredVideos = cachedVideos.filter(video => video.src !== currentSrc); const filteredVideos = cachedVideos.filter(video => video.src !== currentSrc);
if (filteredVideos.length > 0) { if (filteredVideos.length > 0) {
const randomIndex = Math.floor(Math.random() * filteredVideos.length); const randomIndex = Math.floor(Math.random() * filteredVideos.length);
const randomVideo = filteredVideos[randomIndex]; const randomVideo = filteredVideos[randomIndex];
videoElement.src = randomVideo.src; videoElement.src = randomVideo.src;
} else { } else {
debugLog("No other videos available."); debugLog("No other videos available.");
getSourceFiles().then(()=>{ getSourceFiles().then(()=>{
selectRandomVideo(videoElement) selectRandomVideo(videoElement)
}) })
} }
} else { } else {
debugLog("Cache empty, doing new request") debugLog("Cache empty, doing new request")
@ -197,17 +197,17 @@ function selectRandomVideo(videoElement) {
} }
document.addEventListener('keydown', function(event) { document.addEventListener('keydown', function(event) {
console.log('keyDown',event) console.log('keyDown',event)
// Check if the pressed key is the one you want to bind // Check if the pressed key is the one you want to bind
if (event.key === 'Enter') { if (event.key === 'Enter') {
showText = !showText showText = !showText
} }
if (event.key === 'ArrowDown') { if (event.key === 'ArrowDown') {
loadVideos(-1) loadVideos(-1)
} }
if (event.key === 'ArrowUp') { if (event.key === 'ArrowUp') {
loadVideos(1) loadVideos(1)
} }
}) })
getSourceFiles().then(()=>{ getSourceFiles().then(()=>{

Loading…
Cancel
Save