document.addEventListener('DOMContentLoaded', () => { setTimeout(() =>{ // Get all contact-slot elements (using attribute selector for multiple IDs) const contactSlots = document.querySelectorAll('[id="contact-slot"]'); // Check if we have at least 2 contact slots if (contactSlots.length >= 2) { const telegramSlot = contactSlots[1]; // Get the second contact slot // Modify it for Telegram const telegramLink = telegramSlot.querySelector('.s-contacts-item'); const telegramIcon = telegramSlot.querySelector('.s-contacts-icon'); const telegramText = telegramSlot.querySelector('.unicode'); if (telegramLink && telegramIcon && telegramText) { telegramLink.href = 'https://t.me/MANSOURSTOR'; telegramLink.target = '_blank'; telegramIcon.innerHTML = ` telegram `; telegramText.textContent = '@MANSOURSTOR'; } } },500); }); //speed // Optimized JavaScript for better performance document.addEventListener('DOMContentLoaded', function() { // Improved loader functionality const loader = document.querySelector(".loader-init"); if (loader) { // Hide loader when page is ready window.addEventListener("load", () => { loader.classList.add("loader-init--hidden"); loader.addEventListener("transitionend", () => { if (document.body.contains(loader)) { document.body.removeChild(loader); } }); }); } // Lazy loading for images const lazyImages = document.querySelectorAll('img[loading="lazy"]'); if ('IntersectionObserver' in window) { const imageObserver = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { const lazyImage = entry.target; if (lazyImage.dataset.src) { lazyImage.src = lazyImage.dataset.src; lazyImage.removeAttribute('data-src'); imageObserver.unobserve(lazyImage); } } }); }); lazyImages.forEach(function(lazyImage) { imageObserver.observe(lazyImage); }); } else { // Fallback for browsers without intersection observer let lazyLoadThrottleTimeout; function lazyLoad() { if (lazyLoadThrottleTimeout) { clearTimeout(lazyLoadThrottleTimeout); } lazyLoadThrottleTimeout = setTimeout(function() { const scrollTop = window.scrollY; lazyImages.forEach(function(lazyImage) { if (lazyImage.offsetTop < (window.innerHeight + scrollTop)) { if (lazyImage.dataset.src) { lazyImage.src = lazyImage.dataset.src; lazyImage.removeAttribute('data-src'); } } }); if (lazyImages.length == 0) { document.removeEventListener("scroll", lazyLoad); window.removeEventListener("resize", lazyLoad); window.removeEventListener("orientationChange", lazyLoad); } }, 20); } document.addEventListener("scroll", lazyLoad); window.addEventListener("resize", lazyLoad); window.addEventListener("orientationChange", lazyLoad); } // Optimize cookie management function optimizeCookies() { const ignoreKeys = ["__said", "__ssid", "_fbp", "_scid", "cf_", "XSRF-TOKEN", "_gac", "_ga", "_twitter_sess", "personalization_id", "_hjid", "intercom-session-"]; // Clean cookies only if they exceed size limit if (new TextEncoder().encode(document.cookie).length < 8000) { return; } document.cookie.split("; ").forEach(function(cookie) { const key = cookie.split("=")[0].trim(); if (!ignoreKeys.includes(key)) { document.cookie = key + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; } }); } // Run cookie optimization less frequently setInterval(optimizeCookies, 30000); // Defer non-critical third-party scripts function loadDeferredScripts() { const deferredScripts = [ // Add your third-party scripts here { src: 'https://cdn.sift.com/s.js', async: true }, { src: 'https://www.googletagmanager.com/gtm.js?id=GTM-TGFC6FV', async: true } ]; deferredScripts.forEach(script => { const scriptEl = document.createElement('script'); scriptEl.src = script.src; if (script.async) scriptEl.async = true; document.body.appendChild(scriptEl); }); } // Load deferred scripts after critical content if ('requestIdleCallback' in window) { requestIdleCallback(loadDeferredScripts); } else { setTimeout(loadDeferredScripts, 2000); } // Optimize event handlers function optimizeEvents() { // Use event delegation for common events document.addEventListener('click', function(e) { // Handle click events using delegation if (e.target.closest('.header-btn')) { // Handle header button clicks const btn = e.target.closest('.header-btn'); if (btn.getAttribute('onclick') && btn.getAttribute('onclick').includes('login::open')) { e.preventDefault(); if (window.salla && window.salla.event) { window.salla.event.dispatch('login::open'); } } } }); } // Initialize optimized events optimizeEvents(); }); // Optimize resource hints function addResourceHints() { const hints = [ { rel: 'preconnect', href: 'https://cdn.assets.salla.network' }, { rel: 'preconnect', href: 'https://cdn.salla.network' }, { rel: 'preconnect', href: 'https://cdn.salla.sa' } ]; hints.forEach(hint => { const linkEl = document.createElement('link'); linkEl.rel = hint.rel; linkEl.href = hint.href; document.head.appendChild(linkEl); }); } // Add resource hints early if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', addResourceHints); } else { addResourceHints(); } // Prioritize above-the-fold content loading function prioritizeCriticalContent() { // Find slider images and prioritize the first one const sliderImages = document.querySelectorAll('.photos-slider img'); if (sliderImages.length > 0) { sliderImages[0].loading = 'eager'; sliderImages[0].fetchpriority = 'high'; // Set others to lazy load for (let i = 1; i < sliderImages.length; i++) { sliderImages[i].loading = 'lazy'; } } } // Run prioritization as early as possible if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', prioritizeCriticalContent); } else { prioritizeCriticalContent(); }