Amazon - Show absolute review numbers

Adds the number of reviews to each rating separately

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Amazon - Show absolute review numbers
// @namespace    graphen
// @version      1.2.6
// @description  Adds the number of reviews to each rating separately
// @license      MIT
// @author       Graphen
// @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)\/.*$/
// @grant        none
// @noframes
// @icon         https://www.amazon.com/favicon.ico
// ==/UserScript==

/* jshint esversion: 6 */

// Testpages:
// 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
// https://www.amazon.de/dp/B078S8YZZ6/

(function(doc) {
    'use strict';

    var totalReviewCount = doc.querySelector('[data-hook="total-review-count"]').innerText;
    var arrPercentages = Array.from(doc.querySelectorAll("#histogramTable .a-text-right"));

    if (totalReviewCount && arrPercentages) {
        // Sanitize totalReviewCount
        // Remove all non-digits
        totalReviewCount = totalReviewCount.replace(/\D/g, '');
        // Convert string to integer
        totalReviewCount = parseInt(totalReviewCount, 10);
        // Check for nonsense (Most reviewed product has ~100000 at the moment)
        if (totalReviewCount < 250000) {
            for (var e of arrPercentages) {
                let percentValue = e.innerText;
                // Get rid of percentage sign and convert string to integer
                percentValue = parseInt(percentValue, 10);
                // Calculate absolute review count
                percentValue = Math.round(percentValue * totalReviewCount / 100);
                // Cancel if nonsense
                if (percentValue > totalReviewCount || percentValue < 0) {
                    break;
                }
                // Append calculated value to visible node
                var absNum = doc.createTextNode(" (" + percentValue + ")");
                e.appendChild(absNum);
            }
        }
    }

    // Insert own stylesheet
    let reviewStyle = doc.createElement("style");
    reviewStyle.innerHTML = "#histogramTable td:last-of-type { text-align: right !important; }";
    doc.head.appendChild(reviewStyle);


})(document);