Dealscoaster




🎯 Join Our WhatsApp Community for Exclusive Deals!


Prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed at the time of purchase will apply.



if (sortSelect) {
const grid = document.querySelector(‘.amazon-products-grid’);
if (grid) {
const original = Array.from(grid.children);

sortSelect.addEventListener(‘change’, function() {
let cards = Array.from(grid.children);
if (this.value === ‘asc’ || this.value === ‘desc’) {
cards.sort((a, b) => {
// Extract price as float
const pa = parseFloat((a.querySelector(‘.price’)?.textContent || ”).replace(/[^0-9.]/g, ”)) || 0;
const pb = parseFloat((b.querySelector(‘.price’)?.textContent || ”).replace(/[^0-9.]/g, ”)) || 0;
return this.value === ‘asc’ ? pa – pb : pb – pa;
});
} else {
cards = original;
}
// Remove all and re-append in new order
cards.forEach(card => grid.appendChild(card));
});
}
}

// AGGRESSIVE PACKAGE IMAGE REMOVAL FOR MOBILE + WHITE BOX ELIMINATION
function removePackageImages() {
if (window.innerWidth <= 768) { // Mobile only const amazonProducts = document.querySelectorAll('.amazon-product'); let removedCount = 0; let removedContainers = 0; amazonProducts.forEach(product => {
const images = product.querySelectorAll(‘img’);

images.forEach(img => {
// Skip main product images
if (img.classList.contains(‘main-product-image’) ||
img.classList.contains(‘product-image’)) {
return;
}

// Remove if it matches package image patterns
const shouldRemove =
// Size-based removal (small images are likely badges/packages)
(img.width > 0 && img.width <= 150) || (img.height > 0 && img.height <= 150) || // Empty or broken images !img.src || img.src === '' || img.alt === '' || !img.hasAttribute('alt') || // URL-based removal img.src.includes('amazon') || img.src.includes('prime') || img.src.includes('badge') || img.src.includes('package') || img.src.includes('box') || img.src.includes('shipping') || img.src.includes('delivery') || img.src.includes('cloudfront') || img.src.includes('sprite') || // Alt text based removal (img.alt && ( img.alt.toLowerCase().includes('prime') || img.alt.toLowerCase().includes('badge') || img.alt.toLowerCase().includes('package') || img.alt.toLowerCase().includes('box') || img.alt.toLowerCase().includes('amazon') || img.alt.toLowerCase().includes('shipping') || img.alt.toLowerCase().includes('delivery') )); if (shouldRemove) { // Remove the image's parent container if it only contains this image const parent = img.parentElement; if (parent && parent !== product) { const siblings = Array.from(parent.children).filter(child =>
child !== img &&
child.textContent.trim() !== ” &&
!child.classList.contains(‘hidden’)
);

if (siblings.length === 0) {
// Parent only contains this image, remove the whole container
parent.remove();
removedContainers++;
} else {
// Just remove the image
img.remove();
}
} else {
img.remove();
}
removedCount++;
}
});

// Remove empty containers that might create white boxes
const emptyContainers = product.querySelectorAll(‘div:empty, span:empty, p:empty, figure:empty’);
emptyContainers.forEach(container => {
if (!container.classList.contains(‘main-product-image’) &&
!container.classList.contains(‘product-image’)) {
container.remove();
removedContainers++;
}
});

// Remove containers with only whitespace
const whitespaceContainers = product.querySelectorAll(‘div, span, p, figure’);
whitespaceContainers.forEach(container => {
if (!container.classList.contains(‘main-product-image’) &&
!container.classList.contains(‘product-image’) &&
!container.querySelector(‘.main-product-image’) &&
!container.querySelector(‘.product-image’) &&
container.textContent.trim() === ” &&
container.children.length === 0) {
container.remove();
removedContainers++;
}
});
});

if (removedCount > 0 || removedContainers > 0) {
console.log(`DealsCoaster: Removed ${removedCount} package images and ${removedContainers} empty containers on mobile`);
}
}
}

// Run package image removal multiple times to catch dynamic content
removePackageImages(); // Immediate
setTimeout(removePackageImages, 500); // After 500ms
setTimeout(removePackageImages, 1000); // After 1s
setTimeout(removePackageImages, 2000); // After 2s

// Monitor for new images added dynamically
const observer = new MutationObserver(function(mutations) {
let newImagesAdded = false;
mutations.forEach(function(mutation) {
if (mutation.type === ‘childList’) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1 && (node.tagName === ‘IMG’ || node.querySelector(‘img’))) {
newImagesAdded = true;
}
});
}
});

if (newImagesAdded) {
setTimeout(removePackageImages, 100);
}
});

// Start observing for dynamic content
observer.observe(document.body, {
childList: true,
subtree: true
});
});

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *