function addShopLinks(imageUrl) { document.querySelectorAll(".book-wrapper").forEach(wrapper => { if (wrapper.querySelector(".shop_link")) return; const coverLink = wrapper.querySelector(".sp__the-cover a"); if (!coverLink) return; const href = coverLink.getAttribute("href"); const isbn = href.split("/")[1]; if (!isbn) return; const shopLink = document.createElement("p"); shopLink.innerHTML = ` Shop Link `; wrapper.appendChild(shopLink); }); } function waitForImageUrl(callback) { if (window.SearchShopLinkData && window.SearchShopLinkData.imageUrl) { callback(window.SearchShopLinkData.imageUrl); } else { setTimeout(() => waitForImageUrl(callback), 50); } } waitForImageUrl(function(imageUrl) { // Run once in case elements already exist addShopLinks(imageUrl); // Watch for dynamically added book wrappers const observer = new MutationObserver(() => { addShopLinks(imageUrl); }); observer.observe(document.body, { childList: true, subtree: true }); });