@@ -54,30 +54,16 @@ generatePasswordButton.addEventListener('click', () => {
54
54
passwordTextarea . value = password ;
55
55
} ) ;
56
56
57
- // Get the copy button element
58
- const copyButton = document . getElementById ( 'copy-button' ) ;
59
-
60
- // Add an event listener to the copy button
61
- copyButton . addEventListener ( 'click' , function ( ) {
62
- // Get the password element
63
- const passwordElement = document . getElementById ( 'password' ) ;
64
57
65
- // Create a temporary input element
66
- const input = document . createElement ( 'input' ) ;
67
- input . value = passwordElement . innerText ;
68
- document . body . appendChild ( input ) ;
58
+ const copyButton = document . getElementById ( 'copy-button' ) ;
59
+ const confirmationMessage = document . getElementById ( 'confirmation-message' ) ;
69
60
70
- // Select and copy the password to the clipboard
71
- input . select ( ) ;
61
+ copyButton . addEventListener ( 'click' , ( ) => {
62
+ passwordTextarea . select ( ) ;
72
63
document . execCommand ( 'copy' ) ;
73
-
74
- // Remove the temporary input element
75
- document . body . removeChild ( input ) ;
76
-
77
- // Show a confirmation message
78
- const confirmationMessage = document . getElementById ( 'confirmation-message' ) ;
79
64
confirmationMessage . style . display = 'block' ;
80
- setTimeout ( function ( ) {
65
+ setTimeout ( ( ) => {
81
66
confirmationMessage . style . display = 'none' ;
82
- } , 3000 ) ;
67
+ } , 2000 ) ;
83
68
} ) ;
69
+
0 commit comments