/* Add custom Js styles below */
(function () {
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) {
var htmlContent = targetElement.innerHTML;
var regex = /\|جدول\|([\s\S]*?)\|الجدول\|/g;
if (!htmlContent.match(regex)) 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(function (col) {
tableHTML += "| " + col.trim() + " | ";
});
tableHTML += "
";
isFirstRow = false;
} else {
tableHTML += "";
cols.forEach(function (col) {
tableHTML += "| " + col.trim() + " | ";
});
tableHTML += "
";
}
});
tableHTML += "
";
return tableHTML;
});
targetElement.innerHTML = newHtml;
}
function renderFAQ() {
var selectors = [
".product-details__description",
".product__description",
"#description",
".description-content",
"article",
".pro-details",
];
selectors.forEach(function (selector) {
document.querySelectorAll(selector).forEach(processFAQ);
});
}
function processFAQ(targetElement) {
var htmlContent = targetElement.innerHTML;
var faqRegex = /\|اسئلة\|([\s\S]*?)\|نهاية\|/g;
if (!htmlContent.match(faqRegex)) return;
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 = '', currentA = '';
lines.forEach(function (line) {
line = line.trim();
if (!line) return;
if (line.startsWith('س')) {
if (currentQ) faqHTML += '
';
currentQ = line.replace(/س\s*:\s*/, '');
faqHTML += '' + currentQ + '
';
} else if (line.startsWith('ج')) {
currentA = line.replace(/ج\s*:\s*/, '');
faqHTML += '
' + currentA + '
';
}
});
faqHTML += '';
return faqHTML;
});
targetElement.innerHTML = newHtml;
}
function init() {
renderMultiColTables();
renderFAQ();
}
window.addEventListener('load', init);
setTimeout(init, 1500);
setTimeout(init, 3000);
})();