/**
 * @projectname UseMnemonic.js
 * @version 0.1
 * @author Lars Kölker
 * @copyright 2020
 * 
 * Check out {@link https://lars.koelker.dev/} for more cool stuff.
 */
var UseMnemonic={run:(e="button, label, a, .UseMnemonic",t="_")=>{const n=document.querySelectorAll(e),o=[];for(let e=0;e<n.length;e++){const r=n[e],c=r.textContent.indexOf(t),i=r.textContent.charAt(c+1);if(-1===c)continue;if(o.includes(i.toLowerCase())){console.warn("The char '"+i+"' is already being used. Skipping.");continue}const a=new RegExp(t.replace("&","&amp;")+i,"i");r.innerHTML=r.innerHTML.replace(a,"<span data-mnemonic>"+i+"</span>"),document.addEventListener("keypress",e=>{if(e.key.toLowerCase()===i.toLowerCase()&&e.target===document.body){if("LABEL"===r.tagName){if(r.hasAttribute("for"))return void document.getElementById(r.getAttribute("for")).focus();if(null!==r.querySelector("input"))return e.preventDefault(),void r.querySelector("input").focus()}r.click()}}),o.push(i.toLowerCase())}const r=document.querySelectorAll("[data-mnemonic]");document.addEventListener("keyup",e=>{"Alt"===e.key&&e.target===document.body&&r.forEach(e=>{""===e.style.textDecoration?e.style.textDecoration="underline":e.style.textDecoration=null})}),document.addEventListener("click",()=>{r.forEach(e=>{e.style.textDecoration=null})})}};