diff options
Diffstat (limited to 'www/index.js')
-rw-r--r-- | www/index.js | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/www/index.js b/www/index.js index e25ec3a..a4257c1 100644 --- a/www/index.js +++ b/www/index.js @@ -1,9 +1,54 @@ import * as wasm from "genpass"; -const LEN = 32; +const DEFAULT_LEN = 32; -document.getElementById("password").innerHTML = wasm.generate(LEN); +let passwordInput = document.getElementById("password"); +let generateButton = document.getElementById("generate"); +let copyButton = document.getElementById("copy"); +let sizeInput = document.getElementById("size"); +let upperCaseInput = document.getElementById("upperCase"); +let lowerCaseInput = document.getElementById("lowerCase"); +let numberInput = document.getElementById("number"); +let specialInput = document.getElementById("special"); -document.getElementById("generate").onclick = (function () { - document.getElementById("password").innerHTML = wasm.generate(LEN); -}); +function copyToClipboard() { + let text = passwordInput.innerText + navigator.clipboard.writeText(text).then(function () { + }, function (err) { + console.error('Async: Could not copy text: ', err); + }); + + copyButton.textContent = "copied" + + setTimeout(() => { + copyButton.innerText = "copy" + }, 3000); +} + +function generate() { + let size = sizeInput.value; + let lower = lowerCaseInput.checked; + let upper = upperCaseInput.checked; + let number = numberInput.checked; + let special = specialInput.checked; + passwordInput.innerHTML = wasm.generate(size, lower, upper, number, special); +} + +// Setting up defaults +sizeInput.value = DEFAULT_LEN; +upperCaseInput.checked = true; +lowerCaseInput.checked = true; +numberInput.checked = true; +specialInput.checked = true; +//this will trigger passwordInput to be filled +generate(); + +//Adding events hooks + +sizeInput.onchange = generate; +upperCaseInput.onchange = generate; +lowerCaseInput.onchange = generate; +numberInput.onchange = generate; +specialInput.onchange = generate; +generateButton.onclick = generate; +copyButton.onclick = copyToClipboard;
\ No newline at end of file |