Amazon - Show absolute review numbers

Adds the number of reviews to each rating separately

  1. // ==UserScript==
  2. // @name Amazon - Show absolute review numbers
  3. // @namespace graphen
  4. // @version 1.2.5
  5. // @description Adds the number of reviews to each rating separately
  6. // @license MIT
  7. // @author Graphen
  8. // @include /^https?:\/\/(www|smile)\.amazon\.(cn|in|co\.jp|sg|se|ae|fr|de|pl|it|nl|es|co\.uk|ca|com(\.(mx|au|br|tr|be))?)\/.*(dp|gp\/(product|video)|exec\/obidos\/ASIN|o\/ASIN|product-reviews)\/.*$/
  9. // @grant none
  10. // @noframes
  11. // @icon https://www.amazon.com/favicon.ico
  12. // ==/UserScript==
  13.  
  14. /* jshint esversion: 6 */
  15.  
  16. // Testpages:
  17. // https://www.amazon.de/s?k=roccat+kone+pure+2017&__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&qid=1556553434&ref=sr_pg_1
  18. // https://www.amazon.de/dp/B078S8YZZ6/
  19.  
  20. (function(doc) {
  21. 'use strict';
  22.  
  23. var totalReviewCount = doc.querySelector('[data-hook="total-review-count"]').innerText;
  24. var arrPercentages = Array.from(doc.querySelectorAll("#histogramTable .a-text-right > .a-size-base"));
  25.  
  26. if (totalReviewCount && arrPercentages) {
  27. // Sanitize totalReviewCount
  28. // Remove all non-digits
  29. totalReviewCount = totalReviewCount.replace(/\D/g, '');
  30. // Convert string to integer
  31. totalReviewCount = parseInt(totalReviewCount, 10);
  32. // Check for nonsense (Most reviewed product has ~100000 at the moment)
  33. if (totalReviewCount < 250000) {
  34. for (var e of arrPercentages) {
  35. let percentValue = e.innerText;
  36. // Get rid of percentage sign and convert string to integer
  37. percentValue = parseInt(percentValue, 10);
  38. // Calculate absolute review count
  39. percentValue = Math.round(percentValue * totalReviewCount / 100);
  40. // Cancel if nonsense
  41. if (percentValue > totalReviewCount || percentValue < 0) {
  42. break;
  43. }
  44. // Append calculated value to visible node
  45. var absNum = doc.createTextNode(" (" + percentValue + ")");
  46. e.appendChild(absNum);
  47. }
  48. }
  49. }
  50.  
  51. // Insert own stylesheet
  52. let reviewStyle = doc.createElement("style");
  53. reviewStyle.innerHTML = "#histogramTable td:last-of-type { text-align: right !important; }";
  54. doc.head.appendChild(reviewStyle);
  55.  
  56.  
  57. })(document);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址