diff options
author | 0neGal <mail@0negal.com> | 2023-08-21 03:06:41 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2023-08-21 03:06:41 +0200 |
commit | 6d108f5e94ecac6b724e128bae3af3d9f3c446e8 (patch) | |
tree | d3d9f21e3822cb4259ee34b30cd5ee356ef43c53 /docs/main.js | |
parent | f9c64963ac1e2dc3d5b5db7ab6ecfb5b6385bfa9 (diff) | |
download | Viper-6d108f5e94ecac6b724e128bae3af3d9f3c446e8.tar.gz Viper-6d108f5e94ecac6b724e128bae3af3d9f3c446e8.zip |
added a basic but proper website for Viper
More changes may come down the line, but this is more or less complete,
I think?? You never know..
Diffstat (limited to 'docs/main.js')
-rw-r--r-- | docs/main.js | 115 |
1 files changed, 75 insertions, 40 deletions
diff --git a/docs/main.js b/docs/main.js index a0223da..3f1e6ec 100644 --- a/docs/main.js +++ b/docs/main.js @@ -1,44 +1,79 @@ -let repo = "viper"; -let author = "0neGal"; -let api = "https://api.github.com/repos"; - -async function init() { - let release = await (await fetch(`${api}/${author}/${repo}/releases/latest`)).json(); - let assets = release.assets; - - let get = (asset) => { - for (let i in assets) { - if (assets[i].name.match(asset)) { - return assets[i].browser_download_url; - } - } +// change platform icon in "Download!" button if on Linux +if (navigator.userAgent.match("Linux")) { + document.querySelector("button img").src = "images/linux.png"; +} + +// functionality of "Download!" button +document.querySelector("button").addEventListener("click", () => { + // if on Linux, navigate to .AppImage file + if (navigator.userAgent.match("Linux")) { + return location.replace("?appimage"); } - let url; - let search = location.search.replace(/^\?/, ""); - switch(search) { - case "win-setup": - url = get(/Viper-Setup-.*\.exe$/); - break; - case "win-portable": - url = get(/Viper-.*\.exe$/); - break; - case "appimage": - url = get(/Viper-.*\.AppImage$/); - break; - case "linux": - url = get(/viper-.*.tar\.gz$/); - break; - case "rpm": - url = get(/viper-.*\.x86_64\.rpm$/); - break; - case "deb": - url = get(/viper_.*_amd64\.deb$/); - break; - default: - url = release.html_url; - break; + // if not on Linux, navigate to .exe setup file + location.replace("?win-setup"); +}) + +// how many wallpapers are in images/backgrounds/ +let backgrounds = 7; + +// initializes the elements for the backgrounds +function init_backgrounds() { + // run through `backgrounds` + for (let i = 2; i < backgrounds + 1; i++) { + // create background element + let background = document.createElement("div"); + + // add relevant classes + background.classList.add("image"); + + // set `background-image` CSS property + background.style.backgroundImage = + `url("images/backgrounds/${i}.jpg")`; + + // add image to DOM + document.querySelector(".background .images").appendChild( + background + ) } +}; init_backgrounds() + +// changes the current image to a random image, if the image picked is +// the same as the one currently being shown, then we re-run this +// function, aka duplicates do not happen! +function change_background() { + // get the ID for the new image + let new_image = Math.floor(Math.random() * (backgrounds - 2) + 1); + // get list of image elements + let images = document.querySelector(".background .images").children; + + // if the new images is the current images, cancel and re-run + if (images[new_image] == + document.querySelector(".background .images .active")) { + + return change_background(); + } + + // run through the images + for (let i = 0; i < images.length; i++) { + // if we're at the new active image, make it active + if (i == new_image) { + images[i].classList.add("active"); + continue; + } + + // remove any possible `.active` class from this image + images[i].classList.remove("active"); + } +} + +// makes the initial (Viper) background/image animate on page load +document.addEventListener("DOMContentLoaded", () => { + let image = document.querySelector(".image.active-noanim"); + + image.classList.add("active"); + image.classList.remove("active-noanim"); +}) - location.replace(url); -}; init() +// change wallpaper every 5 seconds +setInterval(change_background, 5000); |