25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
1.1 KiB

  1. <button id="copyButton" onclick="Run()">Generate</button>
  2. <script>
  3. function GetButton() {
  4. return document.getElementById("copyButton");
  5. }
  6. function UpdateButtonText(text) {
  7. GetButton().innerText = text;
  8. }
  9. function DisableButton() {
  10. GetButton().disabled = true;
  11. }
  12. function GeneratePassword() {
  13. UpdateButtonText("Generating");
  14. setTimeout(() => UpdateButtonText("Generating."), 1000);
  15. setTimeout(() => UpdateButtonText("Generating.."), 2000);
  16. setTimeout(() => UpdateButtonText("Generating..."), 3000);
  17. return new Promise(resolve => {
  18. setTimeout(resolve, 4000, 'm<=u6T8`hM"nxwuY');
  19. });
  20. }
  21. function CopyToClipboard(password) {
  22. return navigator.clipboard.writeText(password).then(() => {
  23. UpdateButtonText("Copied in clipboard!");
  24. DisableButton();
  25. });
  26. }
  27. function Run() {
  28. GeneratePassword().then(password => {
  29. CopyToClipboard(password).catch(error => {
  30. UpdateButtonText("Click to copy!");
  31. GetButton().onclick = () => CopyToClipboard(password);
  32. });
  33. });
  34. }
  35. </script>