// ==UserScript== // @name IMDb Tomatoes // @description Add Rotten Tomatoes ratings to IMDb movie pages // @author chocolateboy // @copyright chocolateboy // @namespace https://github.com/chocolateboy/userscripts // @version 0.1.1 // @license GPL: http://www.gnu.org/copyleft/gpl.html // @include http://*.imdb.tld/title/tt* // @include http://*.imdb.tld/*/title/tt* // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js // @grant GM_addStyle // @grant GM_deleteValue // @grant GM_getValue // @grant GM_listValues // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== /* * OK: * * http://www.imdb.com/title/tt0309698/ - 4 items * http://www.imdb.com/title/tt0086312/ - 3 items * http://www.imdb.com/title/tt0037638/ - 2 items * * Fixed: * * http://www.imdb.com/title/tt0162346/ - 4 items * http://www.imdb.com/title/tt0159097/ - 4 items * * Not aliased (yet): * * http://www.imdb.com/awards-central/title/tt2402927/ */ const COMMAND_NAME = GM_info.script.name + ': clear data' const COMPACT_LAYOUT = '.plot_summary_wrapper .minPlotHeightWithPoster' const CURRENT_YEAR = new Date().getFullYear() const NOW = Date.now() const ONE_HOUR = 1000 * 60 * 60 const ONE_DAY = ONE_HOUR * 24 const STATUS_TO_STYLE = { 'N/A': 'tbd', Fresh: 'favorable', Rotten: 'unfavorable' } // purge expired entries function purgeCached (date) { for (let key of GM_listValues()) { let entry = JSON.parse(GM_getValue(key)) if (date === -1 || date > entry.expires) { GM_deleteValue(key) } } } // prepend an item to the review bar or append a link to the star box function render ($target, { url, status, score }) { let style = STATUS_TO_STYLE[status] if ($target.hasClass('titleReviewBar')) { // reduce the amount of space taken up by the Metacritic item // and make it consistent with our style (i.e. site name rather // than domain name) $target.find('a[href="http://www.metacritic.com"]').text('Metacritic') // 4 review items is too many for the "compact" layout (e.g. // a poster but no trailer). it's designed for a maximum of 3. // to work around this, we hoist the review bar out of the // movie-info block (plot_summary_wrapper) and float it left // beneath the poster e.g.: // // before: // // [ [ ] [ ] ] // [ [ ] [ ] ] // [ [ Poster ] [ Info ] ] // [ [ ] [ ] ] // [ [ ] [ [MC] [IMDb] [&c.] ] ] // // after: // // [ [ ] [ ] ] // [ [ ] [ ] ] // [ [ Poster ] [ Info ] ] // [ [ ] [ ] ] // [ [ ] [ ] ] // [ ] // [ [RT] [MC] [IMDb] [&c.] ] if ($(COMPACT_LAYOUT).length && $target.find('.titleReviewBarItem').length > 2) { let $clear = $('