Amazon show absolute review numbers

Adds the number of reviews to each rating separately

当前为 2018-06-08 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Amazon show absolute review numbers
// @namespace    graphen
// @version      0.1.0
// @description  Adds the number of reviews to each rating separately
// @author       Graphen
// @include      /^https?:\/\/www\.amazon\.(cn|in|co\.jp|sg|fr|de|it|nl|es|co\.uk|ca|com(\.(mx|au|br))?)\/.*$/
// @icon         https://www.amazon.com/favicon.ico
// @grant        none
// @noframes
// ==/UserScript==
/* jshint esversion: 6 */

(function() {
    'use strict';

    var totalReviewCount = document.querySelector(".totalReviewCount").innerText;
    // Sanitize totalReviewCount in case site has changed and selector returns nonsense
    // Remove all non-digits
    totalReviewCount = totalReviewCount.replace(/\D/g, '');
    // Convert string to integer
    totalReviewCount = parseInt(totalReviewCount, 10);
    // Most reviewed product has ~100000 at the moment
    if (totalReviewCount < 250000) {
        const arrPercentages = Array.from(document.querySelectorAll("#histogramTable .a-text-right > *:first-child"));
        for (var e of arrPercentages) {
            let v = e.innerText;
            // Get rid of percentage sign and convert string to integer
            v = parseInt(v, 10);
            // Calculate absolute review count
            v = Math.round(v * totalReviewCount / 100);
            // Cancel if nonsense
            if (v > totalReviewCount || v < 0) {
                break;
            }
            // Append calculated value to visible node
            e.textContent += " (" + v + ")";
        }
    }

})();