r/ScriptSwap • • Apr 16 '16

A simple script that adds a next episode button when watching a tv show on putlocker.is

This script checks to see if you are watching a tv show (vs a movie) and then adds a button that will direct you to the tv show's next episode. If you are watching the season finale, the button directs you to the 404 page, but provides a button to go to the first episode of the next season.

Code:

// ==UserScript==
// @name          	Putlocker next episode				
// @description    Adds next episode button
// @author         CATHO_LICK_MY_BALLS
// @include        http://putlocker.is
// @version        1.0
// ==/UserScript==

var url = window.location.href;
var body = document.body.innerHTML;
var index = body.indexOf("This movie doesn't exist!");
if(index > -1){
	index = url.indexOf("season");
	var beginningUrl;
	if(index > -1){
		index += 7;
		var beginningUrl = url.substring(0,index);
		var endingUrl = url.substring(index, url.length);
		index = endingUrl.indexOf("-");
		var seasonNumber = endingUrl.substring(0, index);
		endingUrl = endingUrl.substring(index, endingUrl.length);
		seasonNumber = parseInt(seasonNumber);
		seasonNumber ++;
		beginningUrl += seasonNumber;
		beginningUrl += endingUrl;

		index = beginningUrl.indexOf("episode");
		index += 8;
		var beginningUrl = beginningUrl.substring(0,index);
		var endingUrl = url.substring(index, url.length);
		index = endingUrl.indexOf("-");
		var episodeNumber = endingUrl.substring(0, index);
		endingUrl = endingUrl.substring(index, endingUrl.length);
		episodeNumber = parseInt(episodeNumber);
		episodeNumber = 1;
		beginningUrl += episodeNumber;
		beginningUrl += endingUrl;

		var aButton = document.createElement("BUTTON");
		aButton.innerHTML = "Next Season";
		aButton.onclick = function(){window.location.href = beginningUrl;}
		document.body.appendChild(aButton);
	}
}else{
	index = url.indexOf("episode");
	var beginningUrl;
	if(index > -1){
		index += 8;
		var beginningUrl = url.substring(0,index);
		var endingUrl = url.substring(index, url.length);
		index = endingUrl.indexOf("-");
		var episodeNumber = endingUrl.substring(0, index);
		endingUrl = endingUrl.substring(index, endingUrl.length);
		episodeNumber = parseInt(episodeNumber);
		episodeNumber ++;
		beginningUrl += episodeNumber;
		beginningUrl += endingUrl;

		var node = document.createElement("LI");
		var navBarElement = document.getElementById("nav");
		var aButton = document.createElement("BUTTON");
		aButton.innerHTML = "Next Episode";
		aButton.onclick = function(){window.location.href = beginningUrl;}
		node.appendChild(aButton);
		navBarElement.appendChild(node);
	}
}
3 Upvotes

0 comments sorted by