55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
|
function randomBackground(backgrounds) {
|
||
|
let background = selectRandom(backgrounds);
|
||
|
console.log("Choosen random background image:", background);
|
||
|
|
||
|
document.getElementById("background").style.backgroundImage = "url(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";
|
||
|
}
|
||
|
|
||
|
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)
|