FollowShows Remaining

Show a number of remaining episodes to watch

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