Add copy link button. Enhance buttons by reverting their text when a new copy event occurs.
This commit is contained in:
		| @ -5,7 +5,7 @@ $doctype 5 | |||||||
|     <title>purr |     <title>purr | ||||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|     <script src="https://unpkg.com/htmx.org@1.7.0" integrity="sha384-EzBXYPt0/T6gxNp0nuPtLkmRpmDBbjg6WmCUZRLXBBwYYmwAUxzlSGej0ARHX0Bo" crossorigin="anonymous"> |     <script src="https://unpkg.com/htmx.org@1.7.0" integrity="sha384-EzBXYPt0/T6gxNp0nuPtLkmRpmDBbjg6WmCUZRLXBBwYYmwAUxzlSGej0ARHX0Bo" crossorigin="anonymous"> | ||||||
|     <script src="/copySecret.js" integrity="sha384-jB3mpB1WyAo8ToD7oWm/LjXBnEImM/8GB7tjExykwuNErwdPHa9mihHlVJRtV+bt"> |     <script src="/copyButtons.js" integrity="sha384-eNQZr7QWPQmi/EWi4lVVFOavm+Eibmh7iDvDptgE0j5fI3xycLssbDBZbKphi8pk"> | ||||||
|     <link rel="stylesheet" href="/style.css"> |     <link rel="stylesheet" href="/style.css"> | ||||||
|  |  | ||||||
|   <body> |   <body> | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								views/public/copyButtons.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								views/public/copyButtons.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | function copySecret(secret) { | ||||||
|  |   var tempText = document.createElement('input'); | ||||||
|  |   tempText.style = 'position: absolute; left: -1000px; top: -1000px'; | ||||||
|  |   tempText.value = secret; | ||||||
|  |   document.body.appendChild(tempText); | ||||||
|  |   tempText.select(); | ||||||
|  |   document.execCommand('copy'); | ||||||
|  |   document.body.removeChild(tempText); | ||||||
|  |   document.getElementById('secretButton').innerHTML = "- secret copied -"; | ||||||
|  |   document.getElementById('linkButton').innerHTML = "copy link"; | ||||||
|  | }  | ||||||
|  |  | ||||||
|  | function copyLink(link) { | ||||||
|  |   var tempText = document.createElement('input'); | ||||||
|  |   tempText.style = 'position: absolute; left: -1000px; top: -1000px'; | ||||||
|  |   tempText.value = window.location.origin + '/pw/' + link; | ||||||
|  |   document.body.appendChild(tempText); | ||||||
|  |   tempText.select(); | ||||||
|  |   document.execCommand('copy'); | ||||||
|  |   document.body.removeChild(tempText); | ||||||
|  |   document.getElementById('linkButton').innerHTML = "- link copied -"; | ||||||
|  |   document.getElementById('secretButton').innerHTML = "copy secret"; | ||||||
|  | }  | ||||||
| @ -1,10 +0,0 @@ | |||||||
| function copySecret(secret) { |  | ||||||
|   var tempText = document.createElement('input'); |  | ||||||
|   tempText.style = 'position: absolute; left: -1000px; top: -1000px'; |  | ||||||
|   tempText.value = secret; |  | ||||||
|   document.body.appendChild(tempText); |  | ||||||
|   tempText.select(); |  | ||||||
|   document.execCommand('copy'); |  | ||||||
|   document.body.removeChild(tempText); |  | ||||||
|   document.getElementById('copyButton').innerHTML = "- secret copied -"; |  | ||||||
| }  |  | ||||||
| @ -2,7 +2,8 @@ | |||||||
|   $maybe pw <- password |   $maybe pw <- password | ||||||
|     <p .resLink>secret found at <a href="/pw/#{link}">/pw/#{link}</a>: |     <p .resLink>secret found at <a href="/pw/#{link}">/pw/#{link}</a>: | ||||||
|     <h3 .pwResult>#{pw} |     <h3 .pwResult>#{pw} | ||||||
|     <button #copyButton .mainButton onclick="copySecret('#{pw}')">copy secret</button> |     <button #secretButton .mainButton onclick="copySecret('#{pw}')">copy secret</button> | ||||||
|  |     <button #linkButton .mainButton onclick="copyLink('#{link}')">copy link</button> | ||||||
|   $nothing |   $nothing | ||||||
|     <p .resLink>no secret found at  |     <p .resLink>no secret found at  | ||||||
|       <br /><a href="/pw/#{link}">/pw/#{link}</a> |       <br /><a href="/pw/#{link}">/pw/#{link}</a> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user