-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathcopyToken.js
More file actions
35 lines (27 loc) · 909 Bytes
/
copyToken.js
File metadata and controls
35 lines (27 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const initCopyToken = () => {
document.addEventListener('click', function (e) {
const button = e.target.closest('#copy-token-btn');
if (!button) return;
e.preventDefault();
// Prevent spam clicking
if (button.disabled) return;
const tokenInput = document.getElementById('api-token-val');
if (!tokenInput) return;
const originalHTML = button.innerHTML;
// Disable immediately
button.disabled = true;
navigator.clipboard.writeText(tokenInput.value).then(() => {
// Replace button contents with check icon
button.innerHTML = '<i class="fa fa-circle-check" aria-hidden="true"></i>';
// Restore after 2s
setTimeout(() => {
button.innerHTML = originalHTML;
button.disabled = false;
}, 2000);
}).catch(() => {
button.disabled = false;
alert('Failed to copy token');
});
});
};
initCopyToken();