Add trakt simplifier
This commit is contained in:
parent
74968a1b44
commit
7a5ca71571
1 changed files with 66 additions and 0 deletions
66
trakt.simplifier.user.js
Normal file
66
trakt.simplifier.user.js
Normal file
|
|
@ -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();
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue