Skip to content

Instantly share code, notes, and snippets.

@keune
Last active October 3, 2016 05:20
Show Gist options
  • Save keune/9e6e4bd65d900cc34f16d12d66dfd278 to your computer and use it in GitHub Desktop.
Save keune/9e6e4bd65d900cc34f16d12d66dfd278 to your computer and use it in GitHub Desktop.
IMDB Season Rating
// ==UserScript==
// @name IMDB Season Rating
// @namespace http://ahmetkun.com/
// @version 0.1
// @description calculate the rating of a tv show's seasons by episode ratings.
// @author Ahmet Kun
// @match http://www.imdb.com/title/*/eprate*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var seasons = {};
var output = '';
document.querySelectorAll('#tn15content table:first-of-type tr').forEach(function(el, i) {
if(!i) return;
var tds = el.querySelectorAll('td'),
epNum = tds[0].textContent,
season = epNum.split('.')[0],
rating = parseFloat(tds[2].textContent);
if(!seasons[season]) seasons[season] = [];
seasons[season].push(rating);
});
for(var season in seasons) {
var len = seasons[season].length,
sum = seasons[season].reduce(function(a,b) {return a + b}, 0);
output += '<tr>' +
'<td>Season ' + season + '</td>' +
'<td align="right">' + parseFloat(sum/len).toFixed(2) + '</td>' +
'<td align="right">' + len + '</td>' +
'</tr>';
}
var insertEl = document.createElement('table');
insertEl.innerHTML = '<tr><th>Season</th><th>Average Rating</th><th>Num. of episodes rated</th></tr>' + output;
document.querySelectorAll('#tn15content')[0].insertBefore(insertEl, document.querySelectorAll('#tn15content h3:first-of-type')[0]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment