60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
document.querySelectorAll('[data-auto-toast="true"]').forEach((toastEl) => {
|
|
const toast = new bootstrap.Toast(toastEl, { delay: 4200 });
|
|
toast.show();
|
|
});
|
|
|
|
document.querySelectorAll('[data-char-count-target]').forEach((field) => {
|
|
const targetSelector = field.getAttribute('data-char-count-target');
|
|
const counter = targetSelector ? document.querySelector(targetSelector) : null;
|
|
if (!counter) {
|
|
return;
|
|
}
|
|
|
|
const updateCounter = () => {
|
|
const length = field.value.trim().length;
|
|
counter.textContent = `${length} characters`;
|
|
};
|
|
|
|
field.addEventListener('input', updateCounter);
|
|
updateCounter();
|
|
});
|
|
|
|
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
|
|
anchor.addEventListener('click', (event) => {
|
|
const targetId = anchor.getAttribute('href');
|
|
if (!targetId || targetId === '#') {
|
|
return;
|
|
}
|
|
|
|
const target = document.querySelector(targetId);
|
|
if (!target) {
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('[data-copy-password]').forEach((button) => {
|
|
button.addEventListener('click', async () => {
|
|
const password = button.getAttribute('data-copy-password') || '';
|
|
if (!password) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await navigator.clipboard.writeText(password);
|
|
const originalText = button.textContent;
|
|
button.textContent = 'Password copied';
|
|
window.setTimeout(() => {
|
|
button.textContent = originalText;
|
|
}, 1600);
|
|
} catch (error) {
|
|
console.error('Copy failed', error);
|
|
}
|
|
});
|
|
});
|
|
});
|