/* Add custom JS code below */ /** * ============================================================ * SEO OPTIMIZER — أريج الطيب * areejaltayyeb.com * الإصدار: 1.0 * الوصف: سكريبت شامل لتحسين ظهور الموقع في أول نتيجة جوجل * ============================================================ * * طريقة الإضافة: * ضع هذا الملف في موقعك ثم أضف السطر التالي قبل : * * ============================================================ */ (function () { "use strict"; /* ────────────────────────────────────────────── 1. إعدادات الموقع ────────────────────────────────────────────── */ const SITE = { name: "أريج الطيب", url: "https://areejaltayyeb.com", logo: "https://cdn.salla.sa/zZVWP/2IFjPjk1BSAkTsYUBD4iwOwSnvm26fSHbU9fVrqn.png", twitter: "@areej_altayyeb", locale: "ar_SA", phone: "+966544338360", defaultKeywords: [ "بخور طبيعي", "دهن عود أصلي", "مسك فاخر", "متجر بخور السعودية", "بخور أونلاين", "دهن عود", "فحم العود", "عود طبيعي", "أريج الطيب", "بخور فاخر", ], defaultDescription: "تسوّق أجود أنواع البخور الطبيعي ودهن العود الأصيل والمسك الفاخر من متجر أريج الطيب. منتجات مختارة بعناية بأسعار تنافسية مع توصيل سريع لجميع مناطق المملكة.", }; /* ────────────────────────────────────────────── 2. تحسين الـ Meta Tags ────────────────────────────────────────────── */ function optimizeMeta() { const head = document.head; // دالة مساعدة: إنشاء أو تحديث وسم meta function setMeta(attrs) { const selector = attrs.name ? `meta[name="${attrs.name}"]` : attrs.property ? `meta[property="${attrs.property}"]` : null; let el = selector ? document.querySelector(selector) : null; if (!el) { el = document.createElement("meta"); head.appendChild(el); } Object.entries(attrs).forEach(([k, v]) => el.setAttribute(k, v)); } // ── charset و viewport ── if (!document.querySelector('meta[charset]')) { const c = document.createElement("meta"); c.setAttribute("charset", "UTF-8"); head.insertBefore(c, head.firstChild); } setMeta({ name: "viewport", content: "width=device-width, initial-scale=1.0" }); // ── SEO الأساسي ── const pageTitle = document.title || `${SITE.name} | بخور ودهن عود فاخر`; const pageDesc = document.querySelector('meta[name="description"]')?.content || SITE.defaultDescription; setMeta({ name: "description", content: pageDesc }); setMeta({ name: "keywords", content: SITE.defaultKeywords.join(", ") }); setMeta({ name: "author", content: SITE.name }); setMeta({ name: "robots", content: "index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1" }); setMeta({ name: "googlebot", content: "index, follow" }); setMeta({ name: "language", content: "Arabic" }); setMeta({ name: "revisit-after", content: "7 days" }); setMeta({ name: "rating", content: "general" }); setMeta({ name: "geo.region", content: "SA" }); setMeta({ name: "geo.placename", content: "Saudi Arabia" }); // ── Open Graph (Facebook / WhatsApp / سناب) ── const ogImage = document.querySelector('meta[property="og:image"]')?.content || SITE.logo; setMeta({ property: "og:type", content: "website" }); setMeta({ property: "og:url", content: window.location.href }); setMeta({ property: "og:title", content: pageTitle }); setMeta({ property: "og:description", content: pageDesc }); setMeta({ property: "og:image", content: ogImage }); setMeta({ property: "og:image:width", content: "1200" }); setMeta({ property: "og:image:height", content: "630" }); setMeta({ property: "og:site_name", content: SITE.name }); setMeta({ property: "og:locale", content: SITE.locale }); // ── Twitter Card ── setMeta({ name: "twitter:card", content: "summary_large_image" }); setMeta({ name: "twitter:site", content: SITE.twitter }); setMeta({ name: "twitter:creator", content: SITE.twitter }); setMeta({ name: "twitter:title", content: pageTitle }); setMeta({ name: "twitter:description", content: pageDesc }); setMeta({ name: "twitter:image", content: ogImage }); // ── Canonical Link ── let canonical = document.querySelector('link[rel="canonical"]'); if (!canonical) { canonical = document.createElement("link"); canonical.rel = "canonical"; head.appendChild(canonical); } canonical.href = window.location.href.split("?")[0].split("#")[0]; // ── hreflang للعربية ── if (!document.querySelector('link[hreflang="ar"]')) { const hl = document.createElement("link"); hl.rel = "alternate"; hl.hreflang = "ar"; hl.href = SITE.url; head.appendChild(hl); } console.log("[SEO] ✅ Meta tags محسّنة"); } /* ────────────────────────────────────────────── 3. تحسين الصور (ALT + Lazy Loading) ────────────────────────────────────────────── */ function optimizeImages() { const images = document.querySelectorAll("img"); let fixed = 0; images.forEach((img) => { // أضف lazy loading if (!img.loading) { img.loading = "lazy"; } // أضف decoding async لتسريع التحميل if (!img.decoding) { img.decoding = "async"; } // أنشئ ALT تلقائي إذا كان مفقوداً if (!img.alt || img.alt.trim() === "") { const src = img.src || img.getAttribute("data-src") || ""; const filename = src.split("/").pop().split(".")[0]; // كلمات مفتاحية مرتبطة بالمنتجات const keywords = { oud: "دهن عود أصلي — أريج الطيب", bakhoor: "بخور طبيعي فاخر — أريج الطيب", musk: "مسك فاخر — أريج الطيب", incense: "بخور عربي أصيل — أريج الطيب", logo: "شعار متجر أريج الطيب", banner: "متجر أريج الطيب للبخور والعود", }; let alt = SITE.name + " — بخور طبيعي ودهن عود"; for (const [key, val] of Object.entries(keywords)) { if (src.toLowerCase().includes(key) || filename.toLowerCase().includes(key)) { alt = val; break; } } img.alt = alt; img.setAttribute("title", alt); fixed++; } // أضف width/height إن لم تكن موجودة لمنع CLS if (!img.width && !img.getAttribute("width")) { img.setAttribute("width", img.naturalWidth || "auto"); } if (!img.height && !img.getAttribute("height")) { img.setAttribute("height", img.naturalHeight || "auto"); } }); console.log(`[SEO] ✅ صور محسّنة: ${images.length} | ALT أُضيف: ${fixed}`); } /* ────────────────────────────────────────────── 4. تحسين الروابط الداخلية ────────────────────────────────────────────── */ function optimizeLinks() { const links = document.querySelectorAll("a"); links.forEach((link) => { const href = link.href || ""; // روابط خارجية: أضف noopener + nofollow if (href && !href.includes(SITE.url) && !href.startsWith("/") && !href.startsWith("#")) { link.rel = "noopener noreferrer nofollow"; if (!link.target) link.target = "_blank"; } // أضف title للروابط الفارغة if (!link.title && link.textContent.trim()) { link.title = link.textContent.trim().substring(0, 60); } }); console.log(`[SEO] ✅ روابط محسّنة: ${links.length}`); } /* ────────────────────────────────────────────── 5. تحسين هيكل العناوين H1-H6 ────────────────────────────────────────────── */ function optimizeHeadings() { const h1s = document.querySelectorAll("h1"); // تأكد من وجود H1 واحد فقط if (h1s.length === 0) { const firstHeading = document.querySelector("h2, h3, .title, [class*='title']"); if (firstHeading && firstHeading.tagName !== "H1") { console.warn("[SEO] ⚠️ لا يوجد H1 في الصفحة — يُنصح بإضافة واحد"); } } else if (h1s.length > 1) { console.warn( `[SEO] ⚠️ يوجد ${h1s.length} وسوم H1 — يجب أن يكون واحد فقط` ); } else { // تأكد من أن H1 يحتوي كلمة مفتاحية const h1Text = h1s[0].textContent.toLowerCase(); const hasKeyword = SITE.defaultKeywords.some((kw) => h1Text.includes(kw.toLowerCase()) ); if (!hasKeyword) { console.warn("[SEO] ⚠️ H1 لا يحتوي كلمة مفتاحية أساسية"); } } console.log(`[SEO] ✅ هيكل العناوين فُحص`); } /* ────────────────────────────────────────────── 6. تحسين سرعة التحميل (Performance) ────────────────────────────────────────────── */ function optimizePerformance() { // Preconnect للـ CDN المستخدم const preconnects = [ "https://cdn.salla.sa", "https://cdn.files.salla.network", "https://cdn.assets.salla.network", "https://fonts.googleapis.com", "https://www.googletagmanager.com", ]; preconnects.forEach((url) => { if (!document.querySelector(`link[href="${url}"]`)) { const link = document.createElement("link"); link.rel = "preconnect"; link.href = url; link.crossOrigin = "anonymous"; document.head.appendChild(link); } }); // DNS Prefetch للسرعة const dnsPrefetch = [ "//www.google-analytics.com", "//www.googletagmanager.com", ]; dnsPrefetch.forEach((url) => { const link = document.createElement("link"); link.rel = "dns-prefetch"; link.href = url; document.head.appendChild(link); }); // تأخير السكريبتات غير الضرورية const scripts = document.querySelectorAll( 'script[src]:not([async]):not([defer])' ); scripts.forEach((s) => { if (!s.src.includes("seo-optimizer")) { s.defer = true; } }); console.log("[SEO] ✅ تحسينات السرعة مُطبّقة"); } /* ────────────────────────────────────────────── 7. Core Web Vitals Monitor ────────────────────────────────────────────── */ function monitorCoreWebVitals() { const vitals = {}; // LCP — Largest Contentful Paint (هدف: < 2.5 ثانية) if ("PerformanceObserver" in window) { new PerformanceObserver((list) => { const entries = list.getEntries(); vitals.lcp = Math.round(entries[entries.length - 1].startTime); const status = vitals.lcp < 2500 ? "✅ ممتاز" : vitals.lcp < 4000 ? "⚠️ متوسط" : "❌ بطيء"; console.log(`[SEO] LCP: ${vitals.lcp}ms — ${status}`); }).observe({ type: "largest-contentful-paint", buffered: true }); // CLS — Cumulative Layout Shift (هدف: < 0.1) let clsScore = 0; new PerformanceObserver((list) => { list.getEntries().forEach((entry) => { if (!entry.hadRecentInput) clsScore += entry.value; }); vitals.cls = +clsScore.toFixed(3); const status = vitals.cls < 0.1 ? "✅ ممتاز" : vitals.cls < 0.25 ? "⚠️ متوسط" : "❌ سيء"; console.log(`[SEO] CLS: ${vitals.cls} — ${status}`); }).observe({ type: "layout-shift", buffered: true }); // FCP — First Contentful Paint new PerformanceObserver((list) => { list.getEntries().forEach((entry) => { if (entry.name === "first-contentful-paint") { vitals.fcp = Math.round(entry.startTime); console.log(`[SEO] FCP: ${vitals.fcp}ms`); } }); }).observe({ type: "paint", buffered: true }); // TTFB — Time to First Byte window.addEventListener("load", () => { const nav = performance.getEntriesByType("navigation")[0]; if (nav) { vitals.ttfb = Math.round(nav.responseStart - nav.requestStart); const status = vitals.ttfb < 800 ? "✅ ممتاز" : vitals.ttfb < 1800 ? "⚠️ متوسط" : "❌ بطيء"; console.log(`[SEO] TTFB: ${vitals.ttfb}ms — ${status}`); // التقرير النهائي setTimeout(() => { const score = [ vitals.lcp < 2500, vitals.cls < 0.1, vitals.ttfb < 800, ].filter(Boolean).length; console.log( `\n[SEO] ═══════════════════════════════\n` + `[SEO] تقرير Core Web Vitals\n` + `[SEO] ═══════════════════════════════\n` + `[SEO] LCP : ${vitals.lcp || "—"}ms\n` + `[SEO] CLS : ${vitals.cls || "—"}\n` + `[SEO] FCP : ${vitals.fcp || "—"}ms\n` + `[SEO] TTFB : ${vitals.ttfb || "—"}ms\n` + `[SEO] الدرجة: ${score}/3\n` + `[SEO] ═══════════════════════════════` ); }, 3000); } }); } } /* ────────────────────────────────────────────── 8. Structured Data — JSON-LD (Organization) ────────────────────────────────────────────── */ function injectStructuredData() { if (document.querySelector('script[type="application/ld+json"]')) return; const schema = { "@context": "https://schema.org", "@graph": [ { "@type": "Organization", "@id": SITE.url + "#organization", name: SITE.name, url: SITE.url, logo: { "@type": "ImageObject", url: SITE.logo, }, contactPoint: { "@type": "ContactPoint", telephone: SITE.phone, contactType: "customer service", availableLanguage: "Arabic", }, sameAs: ["https://twitter.com/areej_altayyeb"], }, { "@type": "WebSite", "@id": SITE.url + "#website", url: SITE.url, name: SITE.name, description: SITE.defaultDescription, inLanguage: "ar", potentialAction: { "@type": "SearchAction", target: { "@type": "EntryPoint", urlTemplate: SITE.url + "/search?q={search_term_string}", }, "query-input": "required name=search_term_string", }, }, ], }; const script = document.createElement("script"); script.type = "application/ld+json"; script.textContent = JSON.stringify(schema, null, 2); document.head.appendChild(script); console.log("[SEO] ✅ Structured Data أُضيف"); } /* ────────────────────────────────────────────── 9. تحسين Breadcrumb التلقائي ────────────────────────────────────────────── */ function generateBreadcrumb() { const path = window.location.pathname; if (path === "/" || path === "") return; const parts = path.split("/").filter(Boolean); const items = [ { "@type": "ListItem", position: 1, name: "الرئيسية", item: SITE.url }, ]; let accumulated = SITE.url; parts.forEach((part, i) => { accumulated += "/" + part; items.push({ "@type": "ListItem", position: i + 2, name: decodeURIComponent(part).replace(/-/g, " "), item: accumulated, }); }); const breadcrumbSchema = { "@context": "https://schema.org", "@type": "BreadcrumbList", itemListElement: items, }; const script = document.createElement("script"); script.type = "application/ld+json"; script.textContent = JSON.stringify(breadcrumbSchema); document.head.appendChild(script); } /* ────────────────────────────────────────────── 10. فتح Sitemap وإبلاغ Google ────────────────────────────────────────────── */ function checkSitemap() { fetch(SITE.url + "/sitemap.xml", { method: "HEAD" }) .then((res) => { if (res.ok) { console.log("[SEO] ✅ Sitemap موجود: " + SITE.url + "/sitemap.xml"); } else { console.warn("[SEO] ⚠️ Sitemap غير موجود — يُنصح بإنشائه"); } }) .catch(() => { console.info("[SEO] ℹ️ تعذّر فحص Sitemap (مشكلة CORS — طبيعي من المتصفح)"); }); } /* ────────────────────────────────────────────── 11. تقرير نهائي شامل ────────────────────────────────────────────── */ function finalReport() { const checks = { title: document.title.length > 10 && document.title.length < 70, description: (document.querySelector('meta[name="description"]')?.content?.length || 0) > 50, h1: document.querySelectorAll("h1").length === 1, canonical: !!document.querySelector('link[rel="canonical"]'), ogTags: !!document.querySelector('meta[property="og:title"]'), https: window.location.protocol === "https:", mobile: !!document.querySelector('meta[name="viewport"]'), }; const passed = Object.values(checks).filter(Boolean).length; const total = Object.keys(checks).length; console.log( `\n[SEO] ╔═══════════════════════════════╗\n` + `[SEO] ║ تقرير SEO — أريج الطيب ║\n` + `[SEO] ╠═══════════════════════════════╣\n` + `[SEO] ║ ${checks.title ? "✅" : "❌"} عنوان الصفحة ║\n` + `[SEO] ║ ${checks.description ? "✅" : "❌"} وصف الميتا ║\n` + `[SEO] ║ ${checks.h1 ? "✅" : "❌"} H1 صحيح ║\n` + `[SEO] ║ ${checks.canonical ? "✅" : "❌"} رابط Canonical ║\n` + `[SEO] ║ ${checks.ogTags ? "✅" : "❌"} Open Graph Tags ║\n` + `[SEO] ║ ${checks.https ? "✅" : "❌"} HTTPS مُفعّل ║\n` + `[SEO] ║ ${checks.mobile ? "✅" : "❌"} صديق للجوال ║\n` + `[SEO] ╠═══════════════════════════════╣\n` + `[SEO] ║ النتيجة: ${passed}/${total} (${Math.round(passed/total*100)}%) ║\n` + `[SEO] ╚═══════════════════════════════╝` ); } /* ────────────────────────────────────────────── تشغيل كل الوظائف ────────────────────────────────────────────── */ function init() { console.log("[SEO] 🚀 بدء تحسين السيو — أريج الطيب"); optimizeMeta(); optimizeImages(); optimizeLinks(); optimizeHeadings(); optimizePerformance(); injectStructuredData(); generateBreadcrumb(); monitorCoreWebVitals(); // تأجيل الفحوصات غير الحرجة setTimeout(() => { checkSitemap(); finalReport(); }, 1500); } // تشغيل بعد اكتمال DOM if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", init); } else { init(); } })();