Last active
August 17, 2023 14:29
-
-
Save trickpattyFH20/8d02b18aaf63b7d405456c13602b3f16 to your computer and use it in GitHub Desktop.
show total amazon review count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.from(document.querySelectorAll('[data-a-popover]')).forEach((el) => { | |
const itemJson = JSON.parse(el.dataset.aPopover); | |
const { url } = itemJson; | |
if (url && url.includes('review')) { | |
fetch(url) | |
.then((response) => response.text()) | |
.then((html) => { | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(html, 'text/html'); | |
const reviewPopupClone = doc.cloneNode(true); | |
const ratingCount = reviewPopupClone.querySelector('.totalRatingCount').innerHTML; | |
const ratingContainer = document.createElement('div'); | |
ratingContainer.style.fontSize = '20px'; | |
ratingContainer.style.fontWeight = 'bold'; | |
ratingContainer.className = 'rating-container'; | |
ratingContainer.innerHTML = ratingCount; | |
el.parentNode.appendChild(ratingContainer); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment