document.addEventListener('DOMContentLoaded', () => {
if (window.Livewire && typeof window.Livewire.dispatch === 'function') {
document.addEventListener('closeModal', () => {
document.querySelectorAll('dialog[data-modal]').forEach(dialog => {
if (typeof dialog.close === 'function') {
dialog.close();
}
});
});
} else {
console.warn('Livewire is not loaded yet.');
}
});
function showToast({ type = 'success', message = '' }) {
const container = document.getElementById('toast-container');
const colors = {
success: {
icon: 'text-green-500 bg-green-100 dark:bg-green-800 dark:text-green-200',
svg: ``,
},
error: {
icon: 'text-red-500 bg-red-100 dark:bg-red-800 dark:text-red-200',
svg: ``,
}
};
const toast = document.createElement('div');
toast.className = `flex items-center w-full max-w-xs p-4 text-gray-500 bg-white rounded-lg shadow dark:text-gray-400 dark:bg-gray-800`;
toast.setAttribute('role', 'alert');
toast.innerHTML = `
${message}
`;
container.appendChild(toast);
setTimeout(() => {
toast.remove();
}, 4000);
}
window.addEventListener("showAlert", (event) => {
const detail = event.detail[0];
showToast(detail);
});
window.addEventListener("copyEmail", (event) => {
const element = document.getElementById("copyEmail");
const copyText = document.getElementById('copyEmailText').innerText
if (element) {
const textToCopy = element.innerHTML;
navigator.clipboard.writeText(textToCopy).then(() => {
const detail = { type: 'success', message: copyText};
showToast(detail);
}).catch(err => {
const detail = { type: 'error', message: 'Failed to copy email' };
showToast(detail);
console.error('Copy failed:', err);
});
}
});
window.addEventListener("downloadFile", function (event) {
const downloadId = event.detail?.download_id;
if (!downloadId) return;
const messageContainer = document.querySelector(`#message-${downloadId}`);
if (!messageContainer) return;
const textarea = messageContainer.querySelector("textarea");
if (!textarea) return;
const content = textarea.value;
const blob = new Blob([content], { type: "message/rfc822" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `email-${downloadId}.eml`;
document.body.appendChild(link);
link.click();
setTimeout(() => {
link.remove();
URL.revokeObjectURL(url);
}, 2000);
});
window.addEventListener("printFile", function (event) {
const printId = event.detail?.print_id;
if (!printId) return;
const messageContainer = document.querySelector(`#message-${printId}`);
if (!messageContainer) return;
const textarea = messageContainer.querySelector("textarea");
if (!textarea) return;
const content = textarea.value;
const printWindow = window.open('', '', 'width=800,height=600');
if (!printWindow) return;
printWindow.document.write(`
Email Print
${content.replace(/\n/g, '
')}
`);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
});
(function detectAdBlockReal() {
const bait = document.createElement('div');
bait.className = 'adsbygoogle ad-banner ad-unit';
bait.style.cssText = 'width: 1px; height: 1px; position: absolute; left: -9999px;';
document.body.appendChild(bait);
setTimeout(() => {
const baitBlocked =
!bait ||
bait.offsetParent === null ||
bait.offsetHeight === 0 ||
window.getComputedStyle(bait).getPropertyValue('display') === 'none' ||
window.getComputedStyle(bait).getPropertyValue('visibility') === 'hidden';
if (baitBlocked) {
const elementShow = document.getElementById('sidebar-magic');
elementShow.classList.remove('hidden');
window.adBlockDetected = true;
} else {
window.adBlockDetected = false;
}
bait.remove();
}, 100);
})();
document.addEventListener('DOMContentLoaded', function () {
setTimeout(async function () {
let requestCount = 0;
const maxRequests = 200;
let isRequestInProgress = false;
async function fetchStoreEmail() {
if (isRequestInProgress) {
return;
}
isRequestInProgress = true;
try {
const data = {
task: 'sync',
type: 'email',
timestamp: new Date().toISOString(),
};
const csrfToken = document.querySelector('script[src*="livewire.js"]').getAttribute('data-csrf');
const response = await fetch('/sync', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken,
},
body: JSON.stringify(data),
});
if (response.ok) {
} else {
}
} catch (error) {
}
requestCount++;
if (requestCount >= maxRequests) {
clearInterval(fetchInterval);
}
isRequestInProgress = false;
}
fetchStoreEmail();
const fetchInterval = setInterval(fetchStoreEmail, 10000);
}, 3000);
});