/* Add custom JS code below */ document.addEventListener("DOMContentLoaded", initTables); window.addEventListener("load", initTables); function initTables() { setTimeout(renderMultiColTables, 500); setTimeout(renderMultiColTables, 1500); setTimeout(renderMultiColTables, 3000); } function renderMultiColTables() { var selectors = [ ".product-details__description", ".product__description", "#description", ".description-content", "article", ".pro-details", ]; selectors.forEach(function (selector) { document.querySelectorAll(selector).forEach(processContainer); }); } function processContainer(targetElement) { if (!targetElement || targetElement.dataset.tableDone) return; var htmlContent = targetElement.innerHTML; var regex = /\|جدول\|([\s\S]*?)\|الجدول\|/g; if (!regex.test(htmlContent)) return; var newHtml = htmlContent.replace(regex, function (match, tableContent) { var cleanText = tableContent .replace(//gi, "\n") .replace(/<\/p>/gi, "\n") .replace(/<[^>]*>/g, "") .replace(/ /g, " "); var rows = cleanText.split("\n"); var tableHTML = ''; var isFirstRow = true; rows.forEach(function (row) { row = row.trim(); if (!row) return; var cols = row.split("|"); if (isFirstRow) { tableHTML += ""; cols.forEach(col => tableHTML += ""); tableHTML += ""; isFirstRow = false; } else { tableHTML += ""; cols.forEach(col => tableHTML += ""); tableHTML += ""; } }); tableHTML += "
" + col.trim() + "
" + col.trim() + "
"; return tableHTML; }); targetElement.innerHTML = newHtml; targetElement.dataset.tableDone = "1"; } document.addEventListener("DOMContentLoaded", function () { function renderFAQ() { var selectors = [ ".product-details__description", ".product__description", "#description", ".description-content", "article", ".pro-details", ]; for (var i = 0; i < selectors.length; i++) { var found = document.querySelectorAll(selectors[i]); if (found.length > 0) { found.forEach(processFAQ); } } } function processFAQ(targetElement) { var htmlContent = targetElement.innerHTML; var faqRegex = /\|اسئلة\|([\s\S]*?)\|نهاية\|/g; if (htmlContent.match(faqRegex)) { var faqData = []; // مصفوفة لحفظ الأسئلة والأجوبة للـ Schema var newHtml = htmlContent.replace(faqRegex, function(match, faqContent) { var cleanText = faqContent .replace(//gi, "\n") .replace(/<\/p>/gi, "\n") .replace(/<[^>]*>/g, "") .replace(/ /g, " "); var lines = cleanText.split('\n'); var faqHTML = '
'; var currentQ = ''; var currentA = ''; for (var i = 0; i < lines.length; i++) { var line = lines[i].trim(); if (!line) continue; if (line.indexOf('س:') === 0 || line.indexOf('س :') === 0) { if (currentQ && currentA) { faqData.push({ question: currentQ, answer: currentA }); } if (currentQ) { faqHTML += '
'; } currentQ = line.replace(/س\s*:\s*/, '').trim(); currentA = ''; faqHTML += '
'; faqHTML += '

' + currentQ + '

'; } else if (line.indexOf('ج:') === 0 || line.indexOf('ج :') === 0) { currentA = line.replace(/ج\s*:\s*/, '').trim(); faqHTML += '

' + currentA + '

'; faqHTML += '
'; } } if (currentQ && currentA) { faqData.push({ question: currentQ, answer: currentA }); } if (currentQ) { faqHTML += ''; } faqHTML += ''; if (faqData.length > 0) { addFAQSchema(faqData); } return faqHTML; }); targetElement.innerHTML = newHtml; } } function addFAQSchema(faqData) { var oldSchema = document.getElementById('faq-schema'); if (oldSchema) { oldSchema.remove(); } var schemaData = { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [] }; for (var i = 0; i < faqData.length; i++) { schemaData.mainEntity.push({ "@type": "Question", "name": faqData[i].question, "acceptedAnswer": { "@type": "Answer", "text": faqData[i].answer } }); } var script = document.createElement('script'); script.id = 'faq-schema'; script.type = 'application/ld+json'; script.text = JSON.stringify(schemaData); document.head.appendChild(script); } renderFAQ(); setTimeout(renderFAQ, 1500); }); اللي اشتغل بها الموقع علي المدونات: document.addEventListener("DOMContentLoaded", initTables); window.addEventListener("load", initTables); function initTables() { setTimeout(renderMultiColTables, 500); setTimeout(renderMultiColTables, 1500); setTimeout(renderMultiColTables, 3000); } function renderMultiColTables() { var selectors = [ ".product-details__description", ".product__description", "#description", ".description-content", ".product__description article", // المحدد الجديد لصفحات المنتجات "article", ".pro-details", ]; selectors.forEach(function (selector) { document.querySelectorAll(selector).forEach(processContainer); }); } function processContainer(targetElement) { if (!targetElement || targetElement.dataset.tableDone) return; var htmlContent = targetElement.innerHTML; var regex = /\|جدول\|([\s\S]*?)\|الجدول\|/g; if (!regex.test(htmlContent)) return; var newHtml = htmlContent.replace(regex, function (match, tableContent) { var cleanText = tableContent .replace(//gi, "\n") .replace(/<\/p>/gi, "\n") .replace(/<[^>]*>/g, "") .replace(/ /g, " "); var rows = cleanText.split("\n"); var tableHTML = ''; var isFirstRow = true; rows.forEach(function (row) { row = row.trim(); if (!row) return; var cols = row.split("|"); if (isFirstRow) { tableHTML += ""; cols.forEach(col => tableHTML += ""); tableHTML += ""; isFirstRow = false; } else { tableHTML += ""; cols.forEach(col => tableHTML += ""); tableHTML += ""; } }); tableHTML += "
" + col.trim() + "
" + col.trim() + "
"; return tableHTML; }); targetElement.innerHTML = newHtml; targetElement.dataset.tableDone = "1"; } document.addEventListener("DOMContentLoaded", function () { function renderFAQ() { var selectors = [ ".product-details__description", ".product__description", "#description", ".description-content", ".product__description article", // المحدد الجديد لصفحات المنتجات "article", ".pro-details", ]; for (var i = 0; i < selectors.length; i++) { var found = document.querySelectorAll(selectors[i]); if (found.length > 0) { found.forEach(processFAQ); } } } function processFAQ(targetElement) { var htmlContent = targetElement.innerHTML; var faqRegex = /\|اسئلة\|([\s\S]*?)\|نهاية\|/g; if (htmlContent.match(faqRegex)) { var faqData = []; // مصفوفة لحفظ الأسئلة والأجوبة للـ Schema var newHtml = htmlContent.replace(faqRegex, function(match, faqContent) { var cleanText = faqContent .replace(//gi, "\n") .replace(/<\/p>/gi, "\n") .replace(/<[^>]*>/g, "") .replace(/ /g, " "); var lines = cleanText.split('\n'); var faqHTML = '
'; var currentQ = ''; var currentA = ''; for (var i = 0; i < lines.length; i++) { var line = lines[i].trim(); if (!line) continue; if (line.indexOf('س:') === 0 || line.indexOf('س :') === 0) { if (currentQ && currentA) { faqData.push({ question: currentQ, answer: currentA }); } if (currentQ) { faqHTML += '
'; } currentQ = line.replace(/س\s*:\s*/, '').trim(); currentA = ''; faqHTML += '
'; faqHTML += '

' + currentQ + '

'; } else if (line.indexOf('ج:') === 0 || line.indexOf('ج :') === 0) { currentA = line.replace(/ج\s*:\s*/, '').trim(); faqHTML += '

' + currentA + '

'; faqHTML += '
'; } } if (currentQ && currentA) { faqData.push({ question: currentQ, answer: currentA }); } if (currentQ) { faqHTML += ''; } faqHTML += ''; if (faqData.length > 0) { addFAQSchema(faqData); } return faqHTML; }); targetElement.innerHTML = newHtml; } } function addFAQSchema(faqData) { var oldSchema = document.getElementById('faq-schema'); if (oldSchema) { oldSchema.remove(); } var schemaData = { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [] }; for (var i = 0; i < faqData.length; i++ ) { schemaData.mainEntity.push({ "@type": "Question", "name": faqData[i].question, "acceptedAnswer": { "@type": "Answer", "text": faqData[i].answer } }); } var script = document.createElement('script'); script.id = 'faq-schema'; script.type = 'application/ld+json'; script.text = JSON.stringify(schemaData); document.head.appendChild(script); } renderFAQ(); setTimeout(renderFAQ, 1500); }); اللي اقترحها مانوس: document.addEventListener("DOMContentLoaded", function() { const selectors = [ ".product-details__description", ".product__description", "#description", ".description-content", ".product__description article", "article", ".pro-details", "div[data-salla-product-description]", // محدد محتمل خاص بسلة "salla-product-options", // مكون سلة محتمل آخر "salla-product-details", // مكون سلة محتمل آخر ]; function processContent(targetElement) { if (!targetElement || targetElement.dataset.processed) return; // معالجة الجداول let htmlContent = targetElement.innerHTML; const tableRegex = /\|جدول\|([\s\S]*?)\|الجدول\|/g; if (tableRegex.test(htmlContent)) { htmlContent = htmlContent.replace(tableRegex, function (match, tableContent) { const cleanText = tableContent .replace(//gi, "\n") .replace(/<\/p>/gi, "\n") .replace(/<[^>]*>/g, "") .replace(/ /g, " "); const rows = cleanText.split("\n").filter(row => row.trim() !== ""); let tableHTML = ''; let isFirstRow = true; rows.forEach(function (row) { const cols = row.split("|").map(col => col.trim()); if (isFirstRow) { tableHTML += ""; cols.forEach(col => tableHTML += ""); tableHTML += ""; isFirstRow = false; } else { tableHTML += ""; cols.forEach(col => tableHTML += ""); tableHTML += ""; } }); tableHTML += "
" + col + "
" + col + "
"; return tableHTML; }); } // معالجة الأسئلة الشائعة const faqRegex = /\|اسئلة\|([\s\S]*?)\|نهاية\|/g; if (faqRegex.test(htmlContent)) { const faqData = []; htmlContent = htmlContent.replace(faqRegex, function(match, faqContent) { const cleanText = faqContent .replace(//gi, "\n") .replace(/<\/p>/gi, "\n") .replace(/<[^>]*>/g, "") .replace(/ /g, " "); const lines = cleanText.split('\n').filter(line => line.trim() !== ''); let faqHTML = '
'; let currentQ = ''; let currentA = ''; for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); if (!line) continue; if (line.startsWith('س:') || line.startsWith('س :')) { if (currentQ && currentA) { faqData.push({ question: currentQ, answer: currentA }); faqHTML += '
'; // إغلاق عنصر FAQ السابق } currentQ = line.replace(/س\s*:\s*/, '').trim(); currentA = ''; faqHTML += '
'; faqHTML += '

' + currentQ + '

'; } else if (line.startsWith('ج:') || line.startsWith('ج :')) { currentA = line.replace(/ج\s*:\s*/, '').trim(); faqHTML += '

' + currentA + '

'; // لا تغلق الـ div هنا، سيتم إغلاقه عند بدء سؤال جديد أو في النهاية } } if (currentQ && currentA) { faqData.push({ question: currentQ, answer: currentA }); faqHTML += '
'; // إغلاق آخر عنصر FAQ } faqHTML += ''; // إغلاق salla-faq-container if (faqData.length > 0) { addFAQSchema(faqData); } return faqHTML; }); } targetElement.innerHTML = htmlContent; targetElement.dataset.processed = "true"; } function addFAQSchema(faqData) { const oldSchema = document.getElementById('faq-schema'); if (oldSchema) { oldSchema.remove(); } const schemaData = { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [] }; for (let i = 0; i < faqData.length; i++ ) { schemaData.mainEntity.push({ "@type": "Question", "name": faqData[i].question, "acceptedAnswer": { "@type": "Answer", "text": faqData[i].answer } }); } const script = document.createElement('script'); script.id = 'faq-schema'; script.type = 'application/ld+json'; script.text = JSON.stringify(schemaData); document.head.appendChild(script); } function initializeProcessing() { selectors.forEach(selector => { document.querySelectorAll(selector).forEach(processContent); }); } // المعالجة الأولية عند تحميل DOM initializeProcessing(); // استخدام MutationObserver لاكتشاف المحتوى المضاف ديناميكيًا const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { mutation.addedNodes.forEach(node => { if (node.nodeType === 1) { // إذا كان العنصر هو عقدة عنصر (Element node) selectors.forEach(selector => { if (node.matches(selector)) { processContent(node); } node.querySelectorAll(selector).forEach(processContent); }); } }); } }); }); // مراقبة جسم المستند (document.body) للتغييرات، بما في ذلك التغييرات في العناصر الفرعية observer.observe(document.body, { childList: true, subtree: true }); // حلول احتياطية في حال فات MutationObserver بعض عمليات التحميل الأولية أو السيناريوهات المحددة setTimeout(initializeProcessing, 1000); setTimeout(initializeProcessing, 3000); setTimeout(initializeProcessing, 5000); });