Skip to content

Instantly share code, notes, and snippets.

@nezort11
Last active April 29, 2024 22:15
Show Gist options
  • Save nezort11/0ce170932dd8c79cc48697e66991f5e1 to your computer and use it in GitHub Desktop.
Save nezort11/0ce170932dd8c79cc48697e66991f5e1 to your computer and use it in GitHub Desktop.
Render rating value and review count near every product in results on Lamoda
var REVIEW_RATING_REGEX = /"ratingValue": "([^"]+)",\s*"reviewCount": "([^"]+)"/;
var main = async () => {
const productCards = document.querySelectorAll(".x-product-card__card");
Array.from(productCards).forEach(async (productCard) => {
// console.log('productCard.id', productCard.id);
const productUrl = `https://www.lamoda.ru/p/${productCard.id}`;
// console.log('productUrl', productUrl);
const productPageResponse = await fetch(productUrl);
// console.log('productPageResponse.status', productPageResponse.status);
const productPageData = await productPageResponse.text();
// console.log('productPageData.length', productPageData.length);
const reviewRatingMatch = productPageData.match(REVIEW_RATING_REGEX);
const ratingValue = reviewRatingMatch[1];
const reviewCount = reviewRatingMatch[2];
// console.log('ratingValue', ratingValue);
// console.log('reviewCount', reviewCount);
const productCardDescription = productCard.querySelector(".x-product-card-description__microdata-wrap:nth-of-type(2)");
const ratingReviewElement = document.createElement("div");
ratingReviewElement.classList.add('x-product-card-description__rating-review');
const reviewCountElement = document.createElement("span");
reviewCountElement.classList.add('x-product-card-description__review-count');
reviewCountElement.innerHTML = `${reviewCount} / `;
const ratingValueElement = document.createElement("span");
ratingValueElement.classList.add('x-product-card-description__rating-value');
ratingValueElement.innerHTML = `${ratingValue}`;
ratingReviewElement.append(reviewCountElement);
ratingReviewElement.append(ratingValueElement);
productCardDescription.insertBefore(ratingReviewElement, productCardDescription.firstChild);
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment