nelle-observer/frontend/public/scripts/main.js

124 lines
3.6 KiB
JavaScript
Raw Normal View History

const meowEndpoint = "https://nelle.observer/api/meow";
const beepEndpoint = "https://nelle.observer/api/beep";
2024-10-28 16:49:32 -06:00
const kaomojiEndpoint = "https://nelle.observer/api/kaomoji";
var random_boolean = Math.random() < 0.5;
2024-09-15 18:11:38 -06:00
2024-09-08 14:14:28 -06:00
// loads all the functions to be loaded on load, pretty simple, it loads shit on load.
function onLoad() {
jsEnabled();
getSGAState();
redirect();
checkBoxes();
getPlaceholder();
getMeowTimeout(meowEndpoint);
getBeepTimeout(beepEndpoint);
2024-10-28 16:49:32 -06:00
getKaomojiTimeout(beepEndpoint);
2024-09-08 14:14:28 -06:00
}
// if javascript is enabled, this script will load, enabling all site elements that use javascript, by default these are all hidden.
function jsEnabled() {
2024-09-08 14:14:28 -06:00
// Get JS required element ids
const lastFmWidget = document.getElementById("lastfm-widget");
const ntfyWidgetContainer = document.getElementById("ntfyWidgetContainer");
const sgaButton = document.getElementById("sgaButton");
const incrementButton = document.getElementById("incrementButton");
// enable js required element ids
lastFmWidget.style.display = "initial";
ntfyWidgetContainer.style.display = "initial";
sgaButton.style.display = "initial";
incrementButton.style.display = "initial";
}
// LastFM stuff
const user = "limepotato";
const url = `https://lastfm-last-played.biancarosa.com.br/${user}/latest-song`;
const song = document.querySelector("#song");
fetch(url)
.then((response) => response.json())
.then((json) => {
song.innerHTML = `${json.track.name} - ${json.track.artist["#text"]}`;
});
// Chrome Redirect
function redirect() {
const chromium = /Chrome|Chromium|OPR|Opera|Edge|UC|QQ/.test(
navigator.userAgent
);
if (navigator.brave) {
window.location.replace("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
}
if (!navigator.brave) {
if (!localStorage.getItem("disclaimerAccepted")) {
if (chromium && screen.width >= 699) {
window.location.replace("/bsod");
}
if (chromium && screen.width <= 699) {
window.location.replace("/mobile-warn");
}
}
}
}
2024-09-15 18:11:38 -06:00
// meow
const meowButton = document.getElementById("meow-button");
const beepButton = document.getElementById("beep-button");
2024-10-28 16:49:32 -06:00
const kaomojiButton = document.getElementById("kaomoji-button");
2024-09-15 18:11:38 -06:00
2024-10-28 16:49:32 -06:00
// on send meow button click
2024-09-15 18:11:38 -06:00
async function meowClick() {
meowButton.disabled=true;
meowButton.innerHTML = "<span>sleeping...</span>";
2024-09-15 18:11:38 -06:00
sendMeow(meowEndpoint);
}
2024-10-28 16:49:32 -06:00
// on send beep button click
async function beepClick() {
beepButton.disabled=true;
beepButton.innerHTML = "<span>sleeping...</span>";
sendMeow(beepEndpoint);
2024-09-17 21:29:15 -06:00
}
2024-10-28 16:49:32 -06:00
// on send kaomoji button click
async function kaomojiClick() {
kaomojiButton.disabled=true;
kaomojiButton.innerHTML = "<span>sleeping...</span>";
sendMeow(kaomojiEndpoint);
}
2024-09-17 21:29:15 -06:00
// Show/Hide Info Boxes
const posterInfoButton = document.getElementById("poster-info-button");
const posterInfo = document.getElementById("poster-info");
let isPosterInfoHidden = true
const ntfyInfoButton = document.getElementById("ntfy-info-button");
const ntfyInfo = document.getElementById("ntfy-info");
let isNtfyInfoHidden = true
function showPosterInfo() {
if (isPosterInfoHidden) {
posterInfo.style.display = "initial";
posterInfoButton.innerHTML = "[hide more info]"
isPosterInfoHidden = false;
}
else {
posterInfo.style.display = "none";
posterInfoButton.innerHTML = "[show more info]"
isPosterInfoHidden = true;
}
}
function showNtfyInfo() {
if (isNtfyInfoHidden) {
ntfyInfo.style.display = "initial";
ntfyInfoButton.innerHTML = "[hide more info]"
isNtfyInfoHidden = false;
}
else {
ntfyInfo.style.display = "none";
ntfyInfoButton.innerHTML = "[show more info]"
isNtfyInfoHidden = true;
}
2024-10-28 16:49:32 -06:00
}