/**
* Product Page Enhancement Script
*
* This script:
* 1. Moves content from a specified heading to underneath the gallery (vanilla JS)
* 2. Manages product browsing history (jQuery)
*/
// ===== PART 1: Content Mover (Vanilla JS) =====
(() => {
// Function to move content from a heading to below the gallery
const moveContentBelowGallery = (headingSelector, gallerySelector) => {
// Find the target heading
const heading = document.querySelector(headingSelector);
if (!heading) return; // Exit if heading not found
// Find the gallery element
const gallery = document.querySelector(gallerySelector);
if (!gallery) return; // Exit if gallery not found
// Create a container for the content to be moved
const movedContentContainer = document.createElement('div');
movedContentContainer.className = 'moved-content-container';
// Collect the heading and all its following siblings
const contentToMove = [heading];
let currentElement = heading.nextElementSibling;
while (currentElement) {
contentToMove.push(currentElement);
currentElement = currentElement.nextElementSibling;
}
// Add all content to the new container
contentToMove.forEach(element => {
// Clone the element to avoid reference issues
const clonedElement = element.cloneNode(true);
movedContentContainer.appendChild(clonedElement);
// Remove the original element
element.parentNode.removeChild(element);
});
// Insert the new container after the gallery
gallery.insertAdjacentElement('afterend', movedContentContainer);
return movedContentContainer;
};
// Add a custom contains selector for case-insensitive text matching
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
}
// Override the querySelector method to support :contains()
const originalQuerySelector = Document.prototype.querySelector;
Document.prototype.querySelector = function(selector) {
if (selector.includes(':contains(')) {
// Extract the text content from the selector
const match = selector.match(/:contains\("([^"]+)"\)/);
if (match) {
const textToFind = match[1];
const baseSelector = selector.replace(/:contains\("([^"]+)"\)/, '');
// Find all elements that match the base selector
const elements = document.querySelectorAll(baseSelector);
// Return the first one that contains the text
for (const element of elements) {
if (element.textContent.includes(textToFind)) {
return element;
}
}
return null;
}
}
// Fall back to the original method for standard selectors
return originalQuerySelector.call(this, selector);
};
// Make the function globally available if needed
window.moveContentBelowGallery = moveContentBelowGallery;
// Execute the function when DOM is fully loaded
document.addEventListener('DOMContentLoaded', () => {
// Call with specific selectors for this page
moveContentBelowGallery('h2:contains("See the BOSS 4-in-1 Ultra Floor System in Action:")', '.gallery');
});
})();
// ===== PART 2: Product History Management (jQuery) =====
$(function() {
// Check and clear redirect flag if it exists
if (sessionStorage['has-redirect']) {
sessionStorage.removeItem('has-redirect');
}
// Product History jQuery plugin
$.fn.productHistory = function(historyItem) {
if (historyItem != null)
add(historyItem);
var history = getHistory(historyItem);
if (history.length > 0) {
$(this).append(`Recently Viewed Products`);
const historyContainer = $('');
history.forEach(item => {
var template = `