💪 Add key trigger to trakt scraper

This commit is contained in:
Dan Jones 2017-10-19 11:55:21 -05:00
commit cd4d61c326

View file

@ -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,11 +79,23 @@
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;
}
function getStuff() {
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\//, '');
@ -86,4 +114,7 @@
});
console.log(items);
}
})();