Adds standard deviation to IMDb ratings breakdown pages.
当前为
// ==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.8.11.39
// @grant none
// @description Adds standard deviation to IMDb ratings breakdown pages.
// ==/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.replace(/[\s,]+/g, ""));
votes.shift();//
let product = 0;
let votecount = 0;
votes.forEach((v, i) => {
product += v * (10 - i);
votecount += +v;
});
const sumOfSquares = votes.reduce((p, c, i) => p +
Math.pow(10 - i - product / votecount, 2) * c, 0);
main.querySelector(".title-ratings-sub-page .allText[align=\"center\"]").textContent +=
`\xA0 Standard Deviation = ${Math.sqrt(sumOfSquares / (votecount - 1)).toFixed(2)}`;
}());