| 1 |
(function() { |
| 2 |
document.addEventListener('DOMContentLoaded', function() { |
| 3 |
var section = document.getElementById('wpr-show-connection-key'); |
| 4 |
var toggleLink = document.getElementById('wpr-show-connection-key-link'); |
| 5 |
var keyField = document.getElementById('wpr-connection-key'); |
| 6 |
var viewButton = document.getElementById('wpr-view-connection-key'); |
| 7 |
var copyButton = document.getElementById('wpr-copy-connection-key'); |
| 8 |
if (!section || !keyField || !viewButton || !copyButton) { |
| 9 |
return; |
| 10 |
} |
| 11 |
|
| 12 |
if (toggleLink) { |
| 13 |
toggleLink.addEventListener('click', function(event) { |
| 14 |
event.preventDefault(); |
| 15 |
section.style.display = 'block'; |
| 16 |
toggleLink.style.display = 'none'; |
| 17 |
}); |
| 18 |
} |
| 19 |
|
| 20 |
viewButton.addEventListener('click', function() { |
| 21 |
if (keyField.type === 'password') { |
| 22 |
keyField.type = 'text'; |
| 23 |
viewButton.textContent = 'Hide Key'; |
| 24 |
} else { |
| 25 |
keyField.type = 'password'; |
| 26 |
viewButton.textContent = 'View Key'; |
| 27 |
} |
| 28 |
}); |
| 29 |
|
| 30 |
copyButton.addEventListener('click', function() { |
| 31 |
var previousType = keyField.type; |
| 32 |
keyField.type = 'text'; |
| 33 |
|
| 34 |
var updateCopyState = function() { |
| 35 |
copyButton.textContent = 'Copied!'; |
| 36 |
setTimeout(function() { |
| 37 |
copyButton.textContent = 'Copy Key'; |
| 38 |
}, 2000); |
| 39 |
}; |
| 40 |
|
| 41 |
var restoreField = function() { |
| 42 |
keyField.type = previousType; |
| 43 |
}; |
| 44 |
|
| 45 |
if (navigator.clipboard && navigator.clipboard.writeText) { |
| 46 |
navigator.clipboard.writeText(keyField.value).then(function() { |
| 47 |
updateCopyState(); |
| 48 |
}).finally(function() { |
| 49 |
restoreField(); |
| 50 |
}); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
keyField.select(); |
| 55 |
document.execCommand('copy'); |
| 56 |
updateCopyState(); |
| 57 |
restoreField(); |
| 58 |
}); |
| 59 |
}); |
| 60 |
})(); |
| 61 |
|