Amazon-Ranking-Laplace

Re-calculating Amazon ranks based on Laplace's rule of succession

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Amazon-Ranking-Laplace
// @namespace    http://github.com/ArmanJR
// @version      0.1
// @description  Re-calculating Amazon ranks based on Laplace's rule of succession
// @author       Arman
// @match        https://www.amazon.com/*/dp/*
// @icon         https://upload.wikimedia.org/wikipedia/commons/d/de/Amazon_icon.png
// @license      MIT
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    document.onreadystatechange = function () {
        if (document.readyState === 'complete') {
            var xpath = '//*[@id="acrPopover"]/span[1]/a/i[1]/span';
            var ratingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
            var rating = parseFloat(ratingElement.innerHTML.split("o")[0]);
            var xpath2 = '//*[@id="acrCustomerReviewText"]';
            var numElement = document.evaluate(xpath2, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
            var num = parseFloat(numElement.innerHTML.replace(',', '').split("r")[0]);var first = rating + (5 - rating) / (num + 1);
            var second = first + (1 - first) / (num + 2);
            document.querySelector('#averageCustomerReviews').innerHTML += ' &nbsp;<span style="color:red;">' + second.toString().substr(0, 4) + ' ';
        }
    }
})();