class PasswordGenerator extends HTMLElement { constructor() { super(); this.innerHTML = `
32
Zahlen
Großbuchstaben
Kleinbuchstaben
Sonderzeichen
`; const outValue = this.querySelector("#pwgen-out"); const pwlen = this.querySelector("#pwgen-len"); const pwlenSpan = this.querySelector("#pwgen-len-num"); const includeNum = this.querySelector("#pwgen-inc-num"); const includeBigChar = this.querySelector("#pwgen-inc-big-char"); const includeSmallChar = this.querySelector("#pwgen-inc-small-char"); const includeSpecialChat = this.querySelector("#pwgen-inc-special-char"); const button = this.querySelector("button"); pwlen.oninput = () => { pwlenSpan.innerText = pwlen.value; button.click(); } includeNum.onchange = () => { button.click(); } includeBigChar.onchange = () => { button.click(); } includeSmallChar.onchange = () => { button.click(); } includeSpecialChat.onchange = () => { button.click(); } button.onclick = () => { let possibleChar = ""; let password = ""; if(includeNum.checked) { possibleChar += "1234567890"; } if(includeBigChar.checked) { possibleChar += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } if(includeSmallChar.checked) { possibleChar += "abcdefghijklmnopqrstuvwxyz"; } if(includeSpecialChat.checked) { possibleChar += ",;.:-_#'+*?=)(/&%$§\"!°{[]}<>|~" } for(let i = 0; i < pwlen.value; i++) { password += possibleChar[Math.floor(Math.random() * possibleChar.length)]; } outValue.value = password; } button.click(); } } customElements.define("jl-pwgen", PasswordGenerator)