hugo-owu-se/assets/js/randomize.js

33 lines
953 B
JavaScript
Raw Normal View History

2024-03-12 09:12:11 +00:00
function randomImageBroker(ElemName, imgArray) {
const imgELM = document.getElementById(ElemName);
2024-03-14 07:11:47 +00:00
const randomIndex = mathRandom(imgArray);
2024-03-12 09:12:11 +00:00
imgELM.src = imgArray[randomIndex];
}
function randomTextBroker(ElemName, textArray) {
const textElm = document.getElementById(ElemName);
2024-03-14 07:11:47 +00:00
const randomIndex = mathRandom(textArray);
2024-03-12 09:12:11 +00:00
textElm.innerHTML = textArray[randomIndex]
}
2024-03-14 07:11:47 +00:00
function mathRandom(srcArray) {
2024-03-12 09:12:11 +00:00
return Math.floor(Math.random()*srcArray.length);
}
base_path = "/images/weebos_avif/";
//file_extension = ".avif"
// Create a new array to store the modified strings
imgArray = imgArray.map(img_path => base_path + img_path);
//console.log(imgArray)
// Set image display
var img = document.getElementById("random-img");
img.style.display = "block";
// text randomized
//document.getElementById("p1").innerHTML = "New tererxt!";
document.onload = randomImageBroker('random-img', imgArray);
randomTextBroker('random-text', text_array)