const scriptTag = document.currentScript; const notificationApproveMode = scriptTag.getAttribute('data-notificationApproveMode') === 'true'; const notificationApproveNotificationPermissionRoute = scriptTag.getAttribute('data-notificationApproveNotificationPermissionRoute'); const notificationPolicyPageUrl = scriptTag.getAttribute('data-notificationPolicyPageUrl'); const styles=`` document.head.insertAdjacentHTML('beforeend', styles); console.log('notificationApproveMode',notificationApproveMode); if( typeof notificationApproveMode === "undefined" || notificationApproveMode === null || typeof notificationApproveNotificationPermissionRoute === "undefined" || notificationApproveNotificationPermissionRoute === null || typeof notificationPolicyPageUrl === "undefined" || notificationPolicyPageUrl === null ){ console.log('Notification permission variables are not defined.'); }else{ if(notificationApproveMode==false){ const NOTIFICATION_REMINDER_KEY = 'notificationPermissionReminderSet'; const REMINDER_DURATION_MS = 3 * 60 * 60 * 1000; // 24 saat milisaniye cinsinden const removeBanner = () => { const banner = document.querySelector('.sozlesme-onay-top'); if (banner) { banner.remove(); } }; const handleConfirmNotificationPermission = () => { fetch(notificationApproveNotificationPermissionRoute, { method: 'POST', headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'), 'Content-Type': 'application/json', 'Accept': 'application/json' }, }).then(response => { if (!response.ok) { return response.json().then(err => { throw err; }); } return response.json(); }).then(function(response) { if (response.success !== undefined && response.success === true) { removeBanner(); localStorage.removeItem(NOTIFICATION_REMINDER_KEY); Swal.fire({ title: 'Başarılı', text: 'Bildirim izni tercihleriniz kaydedildi.', confirmButtonText: 'Tamam', icon: 'success' }); } else { const errorMessage = response.message || 'Bildirim izni tercihleriniz kaydedilemedi.'; Swal.fire({ title: 'Hata', text: errorMessage, confirmButtonText: 'Tamam', icon: 'error' }); } }).catch(function(error) { console.error('Fetch error:', error); let errorMessageText = 'Bir sorun oluştu. Lütfen daha sonra tekrar deneyin.'; if (error && error.message) { errorMessageText = error.message; } else if (typeof error === 'string') { errorMessageText = error; } Swal.fire({ title: 'İşlem Başarısız', text: errorMessageText, confirmButtonText: 'Tamam', icon: 'error' }); }); }; const handleLaterNotificationPermission = () => { const currentTime = new Date().getTime(); localStorage.setItem(NOTIFICATION_REMINDER_KEY, currentTime.toString()); removeBanner(); }; const shouldShowBanner = () => { const reminderSetTime = localStorage.getItem(NOTIFICATION_REMINDER_KEY); if (!reminderSetTime) { return true; } const currentTime = new Date().getTime(); const timeElapsed = currentTime - parseInt(reminderSetTime, 10); if (timeElapsed >= REMINDER_DURATION_MS) { localStorage.removeItem(NOTIFICATION_REMINDER_KEY); console.log('Banner should be shown.'); return true; } return false; }; const initBanner = () => { const csrfTokenMeta = document.querySelector('meta[name="csrf-token"]'); if (!csrfTokenMeta || !csrfTokenMeta.getAttribute('content')) { console.error('CSRF token meta tag not found or empty. Banner cannot be initialized.'); return; } if (!shouldShowBanner()) { console.log('Banner should not be shown.'); return; } const bannerHTML = `

Size daha iyi hizmet sunabilmek ve yeniliklerden haberdar etmek için bildirimleri kullanıyoruz. Bildirim almak ister misiniz? Detaylı Bilgi ve izin sözleşmesi için tıklayınız.

`; document.body.insertAdjacentHTML('beforeend', bannerHTML); document.getElementById('notificationConfirmBtn').addEventListener('click', handleConfirmNotificationPermission); document.getElementById('notificationLaterBtn').addEventListener('click', handleLaterNotificationPermission); }; document.addEventListener('DOMContentLoaded', initBanner); } }