chacham / Amazon Star percent to number

Published:

Version: 1.7+076150b updated

Summary: Replace percent with rounded number (and percent)

License: MIT; https://opensource.org/licenses/MIT

Amazon reviews report a total number of reviews and a percent of that total for each of the 5 star levels. This script adds a number to each of the star levels to bring back the erstwhile behavior, and puts the useful percent in parenthesis, on both the main page and the comments pages.

Please open an issue for requests or to report any undesired behavior.

8/7/15: Bug fix: If total reports was 1000 or more, the star-level numbers showed as NaN (Not a Number). This was due to the thousands separator, e.g. 1,234. This is fixed.

Script works under an assumption that thousands separators are commas as toLocalString() might not be supported everywhere.

8/18/15:
Added support for single review pages that show a star table off to the side.
Added a version number. This one is now 1.3.
Refactored code:

  • Moved thousand separators into functions to be clearer and open to internationalization, if required.
  • Added comments to show separate parts of script more easily.
  • Renamed a variable.
  • Changed order of checks to be clearer.
  • Instead of working on .amazon.com/ specific pages are listed.
    •   This should cut down on processing pages that do not require processing.
      
    •   If i missed a page, please open an issue.
      
  • If there is another Amazon domain that could use this scripts, please open an issue.

Version 1.4 (lost notes :( )

9/17/15 Version 1.5: Added support for .amazon.com/dp/

11/30/15 Version 1.5.1 Added support for .amazon.com/product-reviews/ (/product-reviews/ was already there.)

6/14/16 Version 1.6.1 Duplicated urls as https. While at it, reordered the @includes by length.

4/13/17 Version 1.7

  • Changed == 0 to === 0 to make the editor happy.
  • Added if/else to bottom, as product pages seem to use totalReviewCount now, instead of summaryStars. Perhaps the ifs should be removed, and instead just try them one after another. But that's a decision for another day.

Rating: 1

1 Votes
-1