Navigate_streamallthis.is

A little script to navigate trough series at the streaming host <a href="http://streamallthis.is">streamallthis.is</a>

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name       Navigate_streamallthis.is
// @namespace  http://use.i.E.your.homepage/
// @version    0.1.4
// @description  A little script to navigate trough series at the streaming host <a href="http://streamallthis.is">streamallthis.is</a>
// @match      http://streamallthis.is/watch/*/s*
// @require    http://code.jquery.com/jquery-1.11.2.min.js
// @copyright  2012+, greenhalos
// ==/UserScript==

$(document).ready(function(){
    var url = window.location.pathname;
    var filename = url.substring(url.lastIndexOf('/')+1);
    filename = filename.replace(".html","");
    filename = filename.replace("s","");
    var series = filename.substr(0,filename.indexOf('e'));
    var episode = filename.substr(filename.indexOf('e') + 1); 
    if(document.title == '404 Not Found'){
        changeSerie();
    } else {
        
        var p = document.createElement("P");
        p.align = "center";
        
        
        var prev=document.createElement("input");
        prev.type="button";
        prev.value="<<= PREV";
        prev.onclick = function(){changeEpisode(false)};
        p.appendChild(prev);
        
        var next=document.createElement("input");
        next.type="button";
        
        next.value="NEXT =>>";
        next.id = "next";
        p.appendChild(next);
        
        $(".fa").append(p);
        $('#next').hide();
        
        $.ajax({
            url: genLink(series, parseInt(episode)+1)
        }).done(function(){
         	$("#next").show();
            $("#next").click(function(){changeEpisode(true)});
        }).fail(function(){
            console.log('checking next serie?')
            $.ajax({
                url: genLink(addMissingZero(parseInt(series)+1), 1 )
            }).done(function() {
            	$("#next").show();
            	$("#next").click(function(){changeSerie()});
            });
        });
    }
    
    function changeSerie(){
        var next = episode > 1;
        if (next){
            series++;
            episode = 1;
            window.location.assign(genLink(addMissingZero(series),episode));
        } else {
            series --;
            //TODO
        }
    }
    
    function genLink(genSer, genEpi){
        genEpi = addMissingZero(genEpi);
    	return url.substring(0,url.lastIndexOf('/') + 1) + 's' + genSer + 'e' + genEpi + '.html';
    }
    
    
    function changeEpisode(next) {
		next ? episode++ : episode--;
        window.location.assign(genLink(series,episode));
        
    }
    
    function addMissingZero(number) {
        return (parseInt(number) < 10  ? "0" + number : number);
    }
});