-
Notifications
You must be signed in to change notification settings - Fork 1
/
remaining.episodes.followshows.user.js
61 lines (58 loc) · 1.57 KB
/
remaining.episodes.followshows.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==UserScript==
// @name FollowShows Remaining
// @namespace followshows
// @description Show a number of remaining episodes to watch
// @icon http://followshows.com/favicon.ico
// @author vBm <[email protected]>
// @oujs:author vBm
// @license The MIT License (MIT)
// @supportURL https://github.com/vBm/snippets/issues
// @include http://followshows.com/user/*
// @version 4.3
// @date 17/03/2015
// @grant none
// ==/UserScript==
$('#stats').append(
$('<div>').append(
$('<span>').attr({
class: 'addic7ed'
}),
$('<div>').attr({
class: 'title'
}).css(
'cursor', 'pointer'
).click(
function() {
prompt('Total count:', textPrep());
}
).text('EPISODES TO WATCH')
)
);
function textPrep() {
var numbers = $('#stats').text().match(/\d+/g),
shows = numbers[0],
watched = numbers[3],
remain = numbers[4];
return 'FollowShows stats: ' + shows + ' shows || ' + watched + ' episodes watched || ' + remain + ' episodes to watch';
}
if (!$('a.btn-follow-user').attr('user')) {
$.ajax({
url: '//' + document.location.hostname + '/home/watchlist',
cache: false,
}).done(function(data) {
var totalEpisodesSum, totalEpisodes = [];
if ($(data).find('.stats').size() !== 0 ) {
$(data).find('.stats').each(function() {
totalEpisodes.push(parseInt($(this).text().match(/\d+/)[0], 10));
});
totalEpisodesSum = totalEpisodes.reduce(function(a, b) {
return a + b;
});
$('.addic7ed').text(totalEpisodesSum);
} else {
$('.addic7ed').text('N/A');
}
});
} else {
$('.addic7ed').text('N/A');
}