Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fabiensebban/ee5bf12024fb37b0365fad474e70637e to your computer and use it in GitHub Desktop.
Save fabiensebban/ee5bf12024fb37b0365fad474e70637e to your computer and use it in GitHub Desktop.
Copie add to cart button style to share wishlist button
// Wishlist Power share button style
document.addEventListener('DOMContentLoaded', () => {
const callback = () => {
let wishlistPowerShareButtonButton = document.querySelector(".ooo-wl-share-button");
let wishlistPowerAddToCartButton = document.querySelector('ooo-wl-button-add-to-cart')?.querySelector('button');
if (wishlistPowerShareButtonButton && wishlistPowerAddToCartButton) {
wishlistPowerShareButtonButton.classList.remove('ooo-wl-share-button');
wishlistPowerShareButtonButton.classList.add('button', 'button-primary', 'ooo-wl-button');
// Get computed styles from the source button
const computedStyles = wishlistPowerAddToCartButton.style;
// Copy CSS variables
for (const style of computedStyles) {
if (style.startsWith('--')) {
wishlistPowerShareButtonButton.style.setProperty(
style,
computedStyles.getPropertyValue(style)
);
}
}
wishlistPowerShareButtonButton.style.overflow = 'unset';
}
}
const observer = new MutationObserver(callback);
observer.observe(document.documentElement, { attributes: true, childList: true });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment