document.addEventListener('DOMContentLoaded', function() {
var button = document.getElementById('share-product');
button.addEventListener('click', function() {
var dummy = document.createElement('input');
document.body.appendChild(dummy);
// پیدا کردن شناسه پست از عنصر span
var postIdElement = document.querySelector('.post-id');
var postId = postIdElement ? postIdElement.getAttribute('data-post-id') : null;
// ساخت لینک بر اساس دامنه و post ID
var baseUrl = 'https://parsianhome.com/'; // دامنه اصلی
var shortLink = baseUrl + '?p=' + postId; // لینک کوتاه
dummy.value = shortLink; // لینک کوتاه محصول
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
// نمایش پیام موفقیت
});
});
const questions = document.querySelectorAll('.question');
questions.forEach(question => {
question.addEventListener('click', () => {
const answer = question.nextElementSibling;
answer.classList.toggle('show-answer');
});
});
document.addEventListener('DOMContentLoaded', function() {
const button = document.querySelector('.see-more-fani .wd-btn-text');
// بررسی وجود دکمه و اضافه کردن رویداد کلیک
if (button) {
button.parentElement.addEventListener('click', function() {
if (button.innerText === 'مشاهده بیشتر') {
button.innerText = 'بستن';
} else {
button.innerText = 'مشاهده بیشتر';
}
});
}
});
// انتخاب تمام عناصر با کلاس meta-label
const labels = document.querySelectorAll('.meta-label');
// حذف کاراکتر ':' از متن هر عنصر
labels.forEach(label => {
label.textContent = label.textContent.replace(/:/g, '');
});
// تابعی برای حذف کلمه "تومان"
function removeToman() {
// انتخاب تمام عناصر با کلاس woocommerce-Price-amount
const priceElements = document.querySelectorAll('.price del');
// حلقه برای حذف کلمه "تومان"
priceElements.forEach(function(element) {
element.innerHTML = element.innerHTML.replace('تومان', '').trim();
});
}
// اجرای تابع در بارگذاری صفحه
window.addEventListener('load', function() {
removeToman(); // حذف "تومان" در بارگذاری اولیه
// انتخاب div با کلاس wd-attr-selected
const targetNode = document.querySelector('.wd-attr-selected');
// تنظیمات برای MutationObserver
const config = { childList: true, subtree: true, characterData: true };
// ایجاد یک MutationObserver
const observer = new MutationObserver(function(mutationsList) {
for (let mutation of mutationsList) {
// اگر محتوای div تغییر کند
if (mutation.type === 'childList' || mutation.type === 'characterData') {
removeToman(); // حذف "تومان" در صورت تغییر
}
}
});
// شروع نظارت بر تغییرات
if (targetNode) {
observer.observe(targetNode, config);
}
});