Putlocker电视剧上/下集按钮

在Putlocker电视剧播放页面添加上/下集按钮。

  1. // ==UserScript==
  2. // @name Putlocker Navigation Buttons
  3. // @name:zh-CN Putlocker电视剧上/下集按钮
  4. // @namespace http://rotar.tk/
  5. // @version 0.1.4
  6. // @description Add navigation buttons (previous,next) under putlocker tvshow videos.
  7. // @description:zh-CN 在Putlocker电视剧播放页面添加上/下集按钮。
  8. // @author Rotar
  9. // @match http://putlockers.ch/watch*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var curl = window.location.href;
  16. var vals = /watch-([a-z0-9\-]*)-tvshow(-season-([0-9]{1,2})-episode-([0-9]{1,2}))?-online/.exec(curl);
  17. var se = 0, ep = 0;
  18. var iurl = curl.replace(/-season-([0-9]{1,2})-episode-([0-9]{1,2})/,"");
  19. var retries = 3;
  20.  
  21. var list = {
  22. seasons: [],
  23. season: function(){
  24. return this.seasons.length-1;
  25. },
  26. episode: function(season){
  27. return this.seasons[season];
  28. },
  29. next: function(season,episode){
  30. if((episode+1)>this.episode(season)){
  31. if((season+1)>this.season()){
  32. return null;
  33. }else{
  34. return [season+1,1];
  35. }
  36. }else{
  37. return [season,episode+1];
  38. }
  39. },
  40. previous: function(season,episode){
  41. if((episode-1)<1){
  42. if((season-1)<1){
  43. return null;
  44. }else{
  45. return [season-1,this.episode(season-1)];
  46. }
  47. }else{
  48. return [season,episode-1];
  49. }
  50. }
  51. };
  52.  
  53. if(typeof(vals[2])!="undefined"){//on an episode page
  54. se = parseInt(vals[3]);
  55. ep = parseInt(vals[4]);
  56.  
  57. var contentbox = document.getElementsByClassName("content-box")[0];
  58. var msgdiv = document.getElementsByClassName("message")[0];
  59.  
  60. var navi = document.createElement("div");
  61. navi.id = "navi_box";
  62. navi.style.height = "40px";
  63. navi.style.position = "relative";
  64. navi.style.textAlign = "center";
  65. navi.style.fontFamily = "Arial";
  66. navi.style.fontSize = "22px";
  67. navi.style.marginTop = "-5px";
  68. navi.style.display = "None";
  69.  
  70. var prev = document.createElement("a");
  71. prev.id = "prev_btn";
  72. prev.style.position = "absolute";
  73. prev.style.left = "5px";
  74. prev.style.padding = "5px";
  75. prev.style.color = "#EEEEEE";
  76. prev.innerHTML = "PREVIOUS";
  77. prev.className = "movgr";
  78. prev.style.display = "None";
  79. navi.appendChild(prev);
  80.  
  81. var next = document.createElement("a");
  82. next.id = "next_btn";
  83. next.style.position = "absolute";
  84. next.style.right = "5px";
  85. next.style.padding = "5px";
  86. next.style.color = "#EEEEEE";
  87. next.innerHTML = "NEXT";
  88. next.className = "movgr";
  89. next.style.display = "None";
  90. navi.appendChild(next);
  91.  
  92. contentbox.insertBefore(navi,msgdiv);
  93. getIndex(iurl);
  94. }
  95.  
  96. function validate(elem){
  97. var result;
  98. if(elem.innerHTML.toLowerCase().substr(0,4)=="prev"){
  99. result = list.previous(se,ep);
  100. }else{
  101. result = list.next(se,ep);
  102. }
  103. if(result){
  104. var nurl = window.location.href.replace("-season-"+se+"-episode-"+ep,"-season-"+result[0]+"-episode-"+result[1]);
  105. elem.href = nurl;
  106. if(result[0]<se){
  107. elem.innerHTML = "PREVIOUS SEASON";
  108. }else if(result[0]>se){
  109. elem.innerHTML = "NEXT SEASON";
  110. }
  111. elem.style.display = "block";
  112. navi.style.display = "block";
  113. }
  114. }
  115.  
  116. function getIndex(lurl){
  117. var responseb;
  118. var xhr = new XMLHttpRequest();
  119. xhr.onloadend = function() {
  120. if (xhr.status == 200 || xhr.status == 304) {
  121. responseb = xhr.responseText;
  122. var dp = new DOMParser();
  123. var rdom = dp.parseFromString(responseb,'text/html');
  124. console.log("Index Successfully Fetched");
  125.  
  126. var icontentbox = rdom.getElementsByClassName("content-box")[0];
  127. var tbs = icontentbox.getElementsByTagName("table");
  128. for(var i=0; i<(tbs.length-5); i++){//put number of episodes for each season into list.seasons
  129. list.seasons[i+1]=tbs[2+i].childNodes[0].childNodes.length;
  130. }
  131. validate(prev);
  132. validate(next);
  133. }else{
  134. console.log("[Request Error] Index fetching failed.");
  135. retries--;
  136. if(retries>=0){
  137. console.log("[Request Error] Retrying in 3 seconds");
  138. setTimeOut(function(){
  139. console.log("Fetching Index...");
  140. getIndex(lurl);
  141. },3000);
  142. }
  143. }
  144. };
  145.  
  146. xhr.open('GET', lurl, true);
  147. xhr.send(null);
  148. }
  149. })();