Putlocker Script

Putlocker tv show controller

  1. // ==UserScript==
  2. // @name Putlocker Script
  3. // @namespace https://redmoses.me/
  4. // @version 0.2.1
  5. // @description Putlocker tv show controller
  6. // @author Red Moses
  7. // @include http://putlocker.is/*episode*
  8. // @include http://putlocker.is/*tvshow*
  9. // @grant none
  10. // @require http://code.jquery.com/jquery-latest.js
  11. // ==/UserScript==
  12. /* jshint -W097 */
  13. 'use strict';
  14.  
  15. // button style
  16. $('head').append("<style>.myButton{-moz-box-shadow:0 14px 14px -7px #3e7327;-webkit-box-shadow:0 14px 14px -7px #3e7327;box-shadow:0 14px 14px -7px #3e7327;background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#77b55a),color-stop(1,#72b352));background:-moz-linear-gradient(top,#77b55a 5%,#72b352 100%);background:-webkit-linear-gradient(top,#77b55a 5%,#72b352 100%);background:-o-linear-gradient(top,#77b55a 5%,#72b352 100%);background:-ms-linear-gradient(top,#77b55a 5%,#72b352 100%);background:linear-gradient(to bottom,#77b55a 5%,#72b352 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#77b55a', endColorstr='#72b352', GradientType=0);background-color:#77b55a;-moz-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;border:1px solid #4b8f29;display:inline-block;cursor:pointer;color:#fff;font-family:Arial;font-size:25px;font-weight:700;padding:6px 12px;text-decoration:none;text-shadow:0 1px 23px #5b8a3c}.myButton:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#72b352),color-stop(1,#77b55a));background:-moz-linear-gradient(top,#72b352 5%,#77b55a 100%);background:-webkit-linear-gradient(top,#72b352 5%,#77b55a 100%);background:-o-linear-gradient(top,#72b352 5%,#77b55a 100%);background:-ms-linear-gradient(top,#72b352 5%,#77b55a 100%);background:linear-gradient(to bottom,#72b352 5%,#77b55a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#72b352', endColorstr='#77b55a', GradientType=0);background-color:#72b352}.myButton:active{position:relative;top:1px}</style>");
  17.  
  18. function getTitle(url){
  19. var re = /watch-.*-tvshow/, m;
  20. if ((m = re.exec(url)) !== null) {
  21. if (m.index === re.lastIndex) {
  22. re.lastIndex++;
  23. }
  24. }
  25. return (m[0].replace("watch-","")).replace("-tvshow","");
  26. }
  27.  
  28. function updateShow(show){
  29. var result = $.grep(shows, function(s){ return s.title == show.title; });
  30. if (result.length > 0){
  31. for (var i in shows) {
  32. if (shows[i].title == show.title) {
  33. shows[i].url = show.url;
  34. break;
  35. }
  36. }
  37. } else {
  38. shows.push(show);
  39. }
  40. localStorage.TV_SHOWS = JSON.stringify(shows);
  41. }
  42.  
  43. function getEpisode(url, direction){
  44. var re = /episode-[0-9]+/, m;
  45.  
  46. if ((m = re.exec(url)) !== null) {
  47. if (m.index === re.lastIndex) {
  48. re.lastIndex++;
  49. }
  50. }
  51. var episode_num = Number(m[0].replace("episode-","")), new_episode;
  52. if(direction == 'prev') {
  53. new_episode = episode_num - 1;
  54. } else {
  55. new_episode = episode_num + 1;
  56. }
  57. var new_url = url.replace("episode-" + episode_num, "episode-" + new_episode);
  58. updateShow({title: getTitle(url), url: new_url});
  59. return new_url;
  60. }
  61.  
  62. function getLastWatched(url){
  63. var title = getTitle(url);
  64. var result = $.grep(shows, function(show){ return show.title == title; });
  65. if (result.length > 0) {
  66. return result[0].url;
  67. } else {
  68. alert("No data saved for " + title);
  69. return null;
  70. }
  71. }
  72.  
  73. // get saved shows
  74. var shows = [];
  75. if(localStorage.TV_SHOWS) {
  76. shows = JSON.parse(localStorage.TV_SHOWS);
  77. } else {
  78. localStorage.TV_SHOWS = JSON.stringify(shows);
  79. }
  80.  
  81. var episode_page = window.location.href.indexOf("episode") > -1;
  82. if (episode_page){
  83. updateShow({title: getTitle(window.location.href), url: window.location.href});
  84. $('body').append('<input type="button" value="Next episode" id="next" class="myButton">');
  85. $('#next').css("position", "fixed").css("top", 0).css("right", 0);
  86. $('#next').click(function(){
  87. window.location.href = getEpisode(window.location.href, 'next');
  88. });
  89. $('body').append('<input type="button" value="Previous episode" id="prev" class="myButton">');
  90. $('#prev').css("position", "fixed").css("top", 0).css("left", 0);
  91. $('#prev').click(function(){
  92. window.location.href = getEpisode(window.location.href, 'prev');
  93. });
  94. } else {
  95. $('body').append('<div style="text-align:center;"><input type="button" value="Last watched" id="last_episode" class="myButton"></div>');
  96. $('#last_episode').css("position", "fixed").css("top", 0);
  97. if(typeof(Storage) == "undefined")
  98. $('#last_episode').attr('disabled','disabled');
  99. $('#last_episode').click(function(){
  100. var last_watched = getLastWatched(window.location.href);
  101. if (last_watched)
  102. window.location.href = last_watched;
  103. });
  104. }