From 7a5ca71571374b24a17e5cd1e757f2ce7017707a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Wed, 13 Jun 2018 09:16:22 -0500 Subject: [PATCH] Add trakt simplifier --- trakt.simplifier.user.js | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 trakt.simplifier.user.js diff --git a/trakt.simplifier.user.js b/trakt.simplifier.user.js new file mode 100644 index 0000000..526ed65 --- /dev/null +++ b/trakt.simplifier.user.js @@ -0,0 +1,66 @@ +// -*- tab-width: 4; js-indent-level: 4; -*- +// ==UserScript== +// @name Trakt Simplifier +// @namespace danielrayjones +// @version 0.0.1 +// @description Strip out eps/movies from trakt lists based on a query string +// @author Dan Jones +// @match https://trakt.tv/* +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + let searches = window.location.search.substr(1).split('&'); + let query = {}; + searches.forEach(function (search) { + let split = search.split('='); + query[split[0]] = split[1]; + }); + + if (!('since' in query)) return; + + let since = parseInt(query.since, 10); + + let watched_shows = JSON.parse(localStorage.watched_shows);; + let watched_movies = JSON.parse(localStorage.watched_movies); + + $('[itemtype="http://schema.org/TVEpisode"], [itemtype="http://schema.org/Movie"]').each(function () { + let type = $(this).attr('itemtype').replace(/^https?:\/\/schema.org\//, ''); + + switch(type) { + case "TVEpisode": + processEpisode(this); + break; + case "Movie": + processMovie(this); + break; + } + }); + + // @todo Trigger resize? + + function processEpisode(that) { + let $ep = $(that); + let series = $ep.data('show-id'); + let ep = $ep.data('episode-id'); + + let watched = watched_shows[series] ? watched_shows[series].e[ep] : null; + + if (!watched) return; + + if (watched[0] > since) $ep.remove(); + } + + function processMovie(that) { + let $mov = $(that); + let id = $mov.data('movie-id'); + + let watched = watched_movies[id]; + + if (!watched) return; + + if (watched[0] > since) $ep.remove(); + } +})();