Skip to content

Instantly share code, notes, and snippets.

@trickpattyFH20
Last active August 17, 2023 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trickpattyFH20/8d02b18aaf63b7d405456c13602b3f16 to your computer and use it in GitHub Desktop.
Save trickpattyFH20/8d02b18aaf63b7d405456c13602b3f16 to your computer and use it in GitHub Desktop.
show total amazon review count
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