AliExpress Rating Calculator

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

  1. // ==UserScript==
  2. // @name AliExpress Rating Calculator
  3. // @description Takes product star ratings and puts a numerical values over them.
  4. // @match https://www.aliexpress.com/
  5. // @match https://www.aliexpress.com/*
  6. // @match https://*.aliexpress.com/*
  7. // @grant none
  8. // @version 0.2
  9. // @author Anon
  10. // @noframes
  11. // @license MIT
  12. // @icon https://www.google.com/s2/favicons?sz=64&domain=aliexpress.com
  13. // @namespace https://greasyfork.org/users/1309046
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. let scrollCount = 0;
  20.  
  21. // Function to calculate and display the rating for each star list
  22. function calculateRatings() {
  23. // Select all elements with class containing "multi--starList--" or "t9_CA"
  24. const starListElements = document.querySelectorAll('[class*="multi--starList--"], [class*="t9_CA"]');
  25.  
  26. starListElements.forEach(starList => {
  27. // Select all elements with class containing "multi--evalutionModal--" or "Ktfxu" within the current star list
  28. const modalElements = starList.querySelectorAll('[class*="multi--evalutionModal--"], [class*="Ktfxu"]');
  29.  
  30. let totalWidth = 0;
  31. let starCount = 0;
  32.  
  33. modalElements.forEach(modal => {
  34. // Select all the star elements with class containing "multi--progress--" or "_2E4Wz" within the current modal
  35. const starElements = modal.querySelectorAll('[class*="multi--progress--"], [class*="_2E4Wz"]');
  36.  
  37. // Loop through each star element and sum up their widths
  38. starElements.forEach(star => {
  39. const width = parseInt(star.style.width);
  40. totalWidth += width;
  41. starCount++;
  42. });
  43. });
  44.  
  45. // Calculate the rating (assuming each full star is represented by 10px width)
  46. const rating = totalWidth / 10;
  47.  
  48. // Create a div to display the rating
  49. const ratingDisplay = document.createElement('div');
  50. ratingDisplay.style.backgroundColor = 'black';
  51. ratingDisplay.style.color = 'white';
  52. ratingDisplay.style.padding = '3px';
  53. ratingDisplay.style.position = 'absolute';
  54. ratingDisplay.style.zIndex = '1';
  55. ratingDisplay.textContent = `${rating.toFixed(1)} stars`;
  56.  
  57. // Append the rating display
  58. starList.appendChild(ratingDisplay);
  59. });
  60. }
  61.  
  62. // Run the function after the page has loaded
  63. window.addEventListener('load', calculateRatings);
  64.  
  65. // Function to handle scroll events
  66. function handleScroll() {
  67. scrollCount++;
  68. if (scrollCount >= 10) {
  69. scrollCount = 0;
  70. calculateRatings();
  71. }
  72. }
  73.  
  74. // Add scroll event listener
  75. window.addEventListener('scroll', handleScroll);
  76. })();