https://www.neweracap.eu/cdn/shop/t/253/assets/trustpilot-rating.js?v=183142653358216639481785932116
1customElements.get("trustpilot-rating")||customElements.define("trustpilot-rating",class extends HTMLElement{constructor(){super(),this.id=this.getAttribute("data-tp-id"),this.buid=this.getAttribute("data-buid"),this.queryId=this.getAttribute("data-query-id"),this.avgRating=this.querySelector(".tp-avg-rating"),this.content=this.querySelector(".trustpilot-rating__content"),this.scrollToReviews=this.getAttribute("data-scroll-to-reviews")==="true",this.scrollToReviewsSelector=".section-trustpilot-product-reviews-carousel",this.sessionObjectName="trustpilot-product-rating",this.sessionProductKey=`product-${this.id}`}connectedCallback(){const observer=new IntersectionObserver(entries=>{entries.forEach(entry=>{if(entry.isIntersecting){const rating=this.checkSessionStorage();if(rating==="no reviews"){observer.disconnect();return}if(rating){this.renderRating(rating),observer.disconnect();return}this.getRating(),observer.disconnect()}})});observer.observe(this),this.scrollToReviews&&this.addEventListener("click",this.scrollToReviewsElement)}calculateRoundedRating(reviews){if(!reviews||reviews.total===0)return 0;const avg=((reviews.oneStar||0)*1+(reviews.twoStars||0)*2+(reviews.threeStars||0)*3+(reviews.fourStars||0)*4+(reviews.fiveStars||0)*5)/reviews.total;return Math.round(avg*10)/10}getRating(){const url=`https://api.trustpilot.com/v1/product-reviews/business-units/${this.buid}?sku=${this.queryId}`;fetch(url,{method:"GET",headers:{apikey:window.tpk,"Content-Type":"application/json"}}).then(response=>{if(response.ok)return response.json();throw new Error("TrustPilot rating Network response was not ok.")}).then(data=>{const calculatedRating=this.calculateRoundedRating(data.numberOfReviews),finalRating=Number(calculatedRating)===Number(data.starsAverage)?data.starsAverage:calculatedRating;this.renderRating(finalRating),this.saveInSessionStorage(finalRating)}).catch(error=>{console.error("There has been a problem with TrustPilot rating fetch operation:",error)})}renderRating(starsAverage){this.avgRating&&this.content&&starsAverage&&starsAverage>0&&(this.avgRating.innerHTML=starsAverage,this.content.classList.remove("hidden"))}saveInSessionStorage(starsAverage){const storage=sessionStorage.getItem(this.sessionObjectName),storageData=storage?JSON.parse(storage):{};starsAverage===0?storageData[this.sessionProductKey]="no reviews":storageData[this.sessionProductKey]=starsAverage,sessionStorage.setItem(this.sessionObjectName,JSON.stringify(storageData))}checkSessionStorage(){const storage=sessionStorage.getItem(this.sessionObjectName);if(!storage)return!1;const storageData=storage?JSON.parse(storage):{};return storageData[this.sessionProductKey]?storageData[this.sessionProductKey]:!1}scrollToReviewsElement(){const reviewsElement=document.querySelector(this.scrollToReviewsSelector);reviewsElement&&reviewsElement.scrollIntoView({behavior:"smooth"})}}); 2//# sourceMappingURL=/cdn/shop/t/253/assets/trustpilot-rating.js.map?v=183142653358216639481785932116
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.