const meowEndpoint = "https://nelle.observer/meow";
const timeOutEndpoint = "https://nelle.observer/meowTimeout";

// loads all the functions to be loaded on load, pretty simple, it loads shit on load.
function onLoad() {
  jsEnabled();
  getSGAState();
  redirect();
  checkBoxes();
  getPlaceholder();
  getMeowTimeout(timeOutEndpoint);
}

// if javascript is enabled, this script will load, enabling all site elements that use javascript, by default these are all hidden.
function jsEnabled() {
  // 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");
      }
    }
  }
}

// meow 
const meowButton = document.getElementById("meow-button");
const justMeowed = document.getElementById("justMeowed");

let timeout = 1;

// on send button click
async function meowClick() {
  meowButton.disabled=true;
  meowButton.innerHTML = "<span>sleeping for 30 minutes...</span>";
    sendMeow(meowEndpoint);
}