// ==UserScript== // @name Metacritic Improved // @namespace metacritic_improved // @description Save/Hide upcoming releases, various UI improvements. // @homepageURL https://github.com/daraeman/metacritic_improved // @author daraeman // @version 1.1 // @date 2017-08-10 // @include http://www.metacritic.com/browse/dvds/* // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js // @downloadURL none // ==/UserScript== var storage_keys = { local: { ignored: "metacritic_improved_release_ignore", saved: "metacritic_improved_release_save", }, }; // grab our saved data var data = { ignored: {}, saved: {}, show_hidden: 0, }; function parseJson( json, assign_to, initial ) { try { var parsed = JSON.parse( json ); try { if ( parsed === null ) parsed = initial; data[ assign_to ] = parsed; } catch ( e ) {} } catch ( e ) {} } parseJson( localStorage.getItem( storage_keys.local.ignored ), "ignored", {} ); parseJson( localStorage.getItem( storage_keys.local.saved ), "saved", {} ); parseJson( localStorage.getItem( storage_keys.local.show_hidden ), "show_hidden", 0 ); // iterate over the page function isSaved( link ) { if ( data.saved[ link ] ) return true; return false; } function isIgnored( link ) { if ( data.ignored[ link ] ) return true; return false; } function getLink( el ) { return el.find( ".title a" ).attr( "href" ); } function saveView( el ) { el.removeClass( "metacritic_improved_ignored" ).addClass( "metacritic_improved_saved" ); } function ignoreView( el ) { el.removeClass( "metacritic_improved_saved" ).addClass( "metacritic_improved_ignored" ); if ( ! data.show_hidden ) jQuery( ".metacritic_improved_ignored" ).slideUp(); } function resetView( el ) { el.removeClass( "metacritic_improved_saved" ).removeClass( "metacritic_improved_ignored" ); } function stringToDate( str ) { return new Date( str ); } function daysUntil( date ) { var now_millis = +new Date(); var then_millis = +date; return ( ( then_millis - now_millis ) / 1000 / 60 / 60 / 24 ); } function dateView( el ) { var date_el = el.find( ".date_wrapper" ).find( "span" ).first(); var date_string = date_el.text(); var parsed_date = stringToDate( date_string ); var days_until = daysUntil( parsed_date ); var rounded_date = Math.round( days_until ); var words = Math.abs( rounded_date ) +" days "; words += ( days_until > 0 ) ? "" : "ago"; if ( rounded_date === 0 ) words = "today"; else if ( rounded_date === 1 ) words = "tomorrow"; else if ( rounded_date === -1 ) words = "yesterday"; date_el.append( '
' ); } jQuery( ".list .summary_row" ).each(function(){ var el = jQuery( this ); var link = getLink( el ); dateView( el ); if ( isSaved( link ) ) saveView( el ); else if ( isIgnored( link ) ) ignoreView( el ); el.append( '