Wobbly-Website/script.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-07-30 18:32:42 +02:00
function randomBackground(backgrounds) {
let background = selectRandom(backgrounds);
console.log("Choosen random background image:", background);
document.getElementById("background").style.backgroundImage = "url(https://i21k.de/emil/backgrounds/" + background + ")";
// let div_height = document.getElementById("background").offsetHeight;
// let half_div_height = (0 - div_height) / 2;
// document.getElementById("background").style.backgroundPosition = "0% " + half_div_height.toString() + "px";
2023-07-30 18:32:42 +02:00
}
function selectRandom(array) {
let choosen = array[Math.floor(Math.random() * array.length)];
return choosen;
}
function copyText(text) {
try {
navigator.clipboard.writeText(text);
console.log('Content copied to clipboard: "' + text + '"');
} catch (error) {
console.error('Failed to copy "' + text + '":', error);
}
}
function strBetweenStrings(startStr, endStr, str) {
pos = str.indexOf(startStr) + startStr.length;
return str.substring(pos, str.indexOf(endStr, pos));
}
function getStringOfPageContent(url, callbackFunction) {
$.get(url, function(data) {
callbackFunction(data);
});
};
function getFilesInFolder(pageContent) { // Needs auto file indexing
// console.log(pageContent);
let contentArray = pageContent.split("\n");
let files = [];
for (let line in contentArray) {
if (contentArray[line].includes("<li>")) {
files.push(strBetweenStrings('"', '"', contentArray[line]));
}
}
files.shift();
// console.log(files);
return files;
};
// getStringOfPageContent("backgrounds", getFilesInFolder)