// ==UserScript== // @name IMDb Standard Deviation // @namespace http://userscripts.org/users/7063 // @include https://www.imdb.com/title/tt*/ratings // @include https://www.imdb.com/title/tt*/ratings-* // @include https://www.imdb.com/title/tt*/ratings?* // @version 2018.12.2.6.36 // @grant none // @description Adds standard deviation to IMDb ratings breakdown pages. // @downloadURL none // ==/UserScript== /*eslint-env browser*/ "use strict"; (function () { const main = document.querySelector("#main"); if (!main) { return; } const votes = [...main.querySelector("table").rows] .map(k => +k.cells[2].textContent); votes.shift(); let product = 0; let votecount = 0; votes.forEach((v, i) => { product += v * (10 - i); votecount += v; }); // votes.forEach((v, i) => product += (votecount += v) * (10 - i)); const redFun = (p, c, i) => p + Math.pow(10 - i - product / votecount, 2) * c; const out = main.querySelector(".title-ratings-sub-page .allText[align=\"center\"]"); out.textContent = `${out.textContent.trim()}. \xA0Standard Deviation = ${ Math.sqrt(votes.reduce(redFun, 0) / (votecount - 1)).toFixed(2)}`; }());