AliExpress Rating Calculator

Takes product star ratings and puts a numerical values over them.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        AliExpress Rating Calculator
// @description  Takes product star ratings and puts a numerical values over them.
// @match        https://www.aliexpress.com/
// @match        https://www.aliexpress.com/*
// @match        https://*.aliexpress.com/*
// @grant       none
// @version     0.2
// @author      Anon
// @noframes
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=aliexpress.com
// @namespace https://greasyfork.org/users/1309046
// ==/UserScript==

(function() {
    'use strict';

    let scrollCount = 0;

    // Function to calculate and display the rating for each star list
    function calculateRatings() {
        // Select all elements with class containing "multi--starList--" or "t9_CA"
        const starListElements = document.querySelectorAll('[class*="multi--starList--"], [class*="t9_CA"]');

        starListElements.forEach(starList => {
            // Select all elements with class containing "multi--evalutionModal--" or "Ktfxu" within the current star list
            const modalElements = starList.querySelectorAll('[class*="multi--evalutionModal--"], [class*="Ktfxu"]');

            let totalWidth = 0;
            let starCount = 0;

            modalElements.forEach(modal => {
                // Select all the star elements with class containing "multi--progress--" or "_2E4Wz" within the current modal
                const starElements = modal.querySelectorAll('[class*="multi--progress--"], [class*="_2E4Wz"]');

                // Loop through each star element and sum up their widths
                starElements.forEach(star => {
                    const width = parseInt(star.style.width);
                    totalWidth += width;
                    starCount++;
                });
            });

            // Calculate the rating (assuming each full star is represented by 10px width)
            const rating = totalWidth / 10;

            // Create a div to display the rating
            const ratingDisplay = document.createElement('div');
            ratingDisplay.style.backgroundColor = 'black';
            ratingDisplay.style.color = 'white';
            ratingDisplay.style.padding = '3px';
            ratingDisplay.style.position = 'absolute';
            ratingDisplay.style.zIndex = '1';
            ratingDisplay.textContent = `${rating.toFixed(1)} stars`;

            // Append the rating display
            starList.appendChild(ratingDisplay);
        });
    }

    // Run the function after the page has loaded
    window.addEventListener('load', calculateRatings);

    // Function to handle scroll events
    function handleScroll() {
        scrollCount++;
        if (scrollCount >= 10) {
            scrollCount = 0;
            calculateRatings();
        }
    }

    // Add scroll event listener
    window.addEventListener('scroll', handleScroll);
})();