From cd4d61c326ff114bc86800164ab5b15eb8acac03 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 19 Oct 2017 11:55:21 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AA=20Add=20key=20trigger=20to=20trakt?= =?UTF-8?q?=20scraper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trakt.scraper.user.js | 57 +++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/trakt.scraper.user.js b/trakt.scraper.user.js index 8177320..268ce7c 100644 --- a/trakt.scraper.user.js +++ b/trakt.scraper.user.js @@ -7,11 +7,19 @@ // @author Dan Jones // @match https://trakt.tv/* // @grant none +// @require https://raw.githubusercontent.com/tommcfarlin/konami-code/master/src/jquery.konami.min.js // ==/UserScript== (function() { 'use strict'; + $(window).konami({ + code: [71,69,84], + eventName: 'konami.get' + }); + + $(window).on('konami.get', getStuff); + String.prototype.lpad = function(padString, length) { let str = this; while (str.length < length) @@ -19,8 +27,8 @@ return str; }; - let watched_shows = JSON.parse(localStorage.watched_shows); - let watched_movies = JSON.parse(localStorage.watched_movies); + let watched_shows; + let watched_movies; function processEpisode(that) { let $ep = $(that); @@ -50,7 +58,15 @@ let watched = watched_shows[series] ? watched_shows[series].e[ep] : null; - let this_ep = { series_id: series, episode_id: ep, title, url, watches: watched ? watched[1] : 0, last_watched: watched ? watched[0] : null}; + let this_ep = { + series_id: series, + episode_id: ep, + title, + url, + watches: watched ? watched[1] : 0, + last_watched: watched ? watched[0] : null, + node: that + }; return this_ep; } @@ -63,27 +79,42 @@ let url = $mov.children('[itemprop="url"]').attr('content'); let watched = watched_movies[id]; - let this_mov = { id, title, url, watches: watched ? watched[1] : 0, last_watched: watched ? watched[0] : null}; + let this_mov = { + id, + title, + url, + watches: watched ? watched[1] : 0, + last_watched: watched ? watched[0] : null, + node: that + }; return this_mov; } - let items = $('[itemtype="http://schema.org/TVEpisode"], [itemtype="http://schema.org/Movie"]').map(function() { - let type = $(this).attr('itemtype').replace(/^https?:\/\/schema.org\//, ''); + function getStuff() { - let data = {}; - switch(type) { + watched_shows = JSON.parse(localStorage.watched_shows); + watched_movies = JSON.parse(localStorage.watched_movies); + + let items = $('[itemtype="http://schema.org/TVEpisode"], [itemtype="http://schema.org/Movie"]').map(function() { + let type = $(this).attr('itemtype').replace(/^https?:\/\/schema.org\//, ''); + + let data = {}; + switch(type) { case "TVEpisode": data = processEpisode(this); break; case "Movie": data = processMovie(this); break; - } - data.type = type; + } + data.type = type; - return data; - }); + return data; + }); + + console.log(items); + + } - console.log(items); })();