💪 Add key trigger to trakt scraper
This commit is contained in:
parent
f3eff53d39
commit
cd4d61c326
1 changed files with 44 additions and 13 deletions
|
|
@ -7,11 +7,19 @@
|
||||||
// @author Dan Jones
|
// @author Dan Jones
|
||||||
// @match https://trakt.tv/*
|
// @match https://trakt.tv/*
|
||||||
// @grant none
|
// @grant none
|
||||||
|
// @require https://raw.githubusercontent.com/tommcfarlin/konami-code/master/src/jquery.konami.min.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
$(window).konami({
|
||||||
|
code: [71,69,84],
|
||||||
|
eventName: 'konami.get'
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).on('konami.get', getStuff);
|
||||||
|
|
||||||
String.prototype.lpad = function(padString, length) {
|
String.prototype.lpad = function(padString, length) {
|
||||||
let str = this;
|
let str = this;
|
||||||
while (str.length < length)
|
while (str.length < length)
|
||||||
|
|
@ -19,8 +27,8 @@
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
let watched_shows = JSON.parse(localStorage.watched_shows);
|
let watched_shows;
|
||||||
let watched_movies = JSON.parse(localStorage.watched_movies);
|
let watched_movies;
|
||||||
|
|
||||||
function processEpisode(that) {
|
function processEpisode(that) {
|
||||||
let $ep = $(that);
|
let $ep = $(that);
|
||||||
|
|
@ -50,7 +58,15 @@
|
||||||
|
|
||||||
let watched = watched_shows[series] ? watched_shows[series].e[ep] : null;
|
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;
|
return this_ep;
|
||||||
}
|
}
|
||||||
|
|
@ -63,27 +79,42 @@
|
||||||
let url = $mov.children('[itemprop="url"]').attr('content');
|
let url = $mov.children('[itemprop="url"]').attr('content');
|
||||||
let watched = watched_movies[id];
|
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;
|
return this_mov;
|
||||||
}
|
}
|
||||||
|
|
||||||
let items = $('[itemtype="http://schema.org/TVEpisode"], [itemtype="http://schema.org/Movie"]').map(function() {
|
function getStuff() {
|
||||||
let type = $(this).attr('itemtype').replace(/^https?:\/\/schema.org\//, '');
|
|
||||||
|
|
||||||
let data = {};
|
watched_shows = JSON.parse(localStorage.watched_shows);
|
||||||
switch(type) {
|
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":
|
case "TVEpisode":
|
||||||
data = processEpisode(this);
|
data = processEpisode(this);
|
||||||
break;
|
break;
|
||||||
case "Movie":
|
case "Movie":
|
||||||
data = processMovie(this);
|
data = processMovie(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
data.type = type;
|
data.type = type;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(items);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
console.log(items);
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue