const menuControl = document.getElementById("xw-gn-menustate");
const menuParent = menuControl.parentElement;
const body = document.querySelector("body");

document.addEventListener("click", function(event)
{
   if (menuParent)
   {
      const clicked = event.target;

      menuParent.querySelectorAll("a").forEach(function(link)
      {
         if (link === clicked)
         {
            menuControl.checked = false;
            body.style.overflow = "";
         }
      });
   }
});

menuControl.addEventListener("change", function(event)
{
   if (menuControl.checked)
   {
      body.style.overflow = "hidden";
   }
   else
   {
      body.style.overflow = "";
   }
});
