62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
// Dark mode toggle
|
|
const toggleBtn = document.getElementById('darkModeBtn');
|
|
if (toggleBtn) {
|
|
toggleBtn.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
document.body.classList.toggle('dark-mode');
|
|
});
|
|
}
|
|
|
|
// Copy email button
|
|
const copyBtn = document.getElementById('copyBtn');
|
|
if (copyBtn) {
|
|
copyBtn.addEventListener('click', () => {
|
|
const text = document.getElementById('aiEmail')?.innerText;
|
|
if (text) {
|
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
// Modern way (requires HTTPS or localhost)
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
showToast();
|
|
}).catch(err => {
|
|
alert("Failed to copy: " + err);
|
|
});
|
|
} else {
|
|
// Fallback for HTTP
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = text;
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
document.execCommand('copy');
|
|
document.body.removeChild(textarea);
|
|
showToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Save email button
|
|
const saveBtn = document.getElementById('saveBtn');
|
|
if (saveBtn) {
|
|
saveBtn.addEventListener('click', () => {
|
|
const text = document.getElementById('aiEmail')?.innerText;
|
|
if (text) {
|
|
const blob = new Blob([text], { type: 'text/plain' });
|
|
const link = document.createElement('a');
|
|
link.href = URL.createObjectURL(blob);
|
|
link.download = 'email.txt';
|
|
link.click();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Toast helper
|
|
function showToast() {
|
|
const toast = document.getElementById('toast');
|
|
if (toast) {
|
|
toast.classList.add('show');
|
|
setTimeout(() => toast.classList.remove('show'), 2000);
|
|
}
|
|
}
|
|
});
|