Amazon Instant Next Episode Button

Provides links to the previous and next episodes just below the video area to easily load the next episode's page when watching a TV show on Amazon Instant View. A Greasemonkey script by Stephen Herr.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Amazon Instant Next Episode Button
// @namespace   greasyfork.org
// @description Provides links to the previous and next episodes just below the video area to easily load the next episode's page when watching a TV show on Amazon Instant View. A Greasemonkey script by Stephen Herr.
// @include     *www.amazon.com/*
// @version     1.4
// @grant       none
// ==/UserScript==

var episodeList = false;
var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
    if (divs[i].className.indexOf('episode-list') > -1) {
        episodeList = divs[i];
        break;
    }
}

// if we're watching a show
if (episodeList) {
    // find the next episode element
    var nextEpisode = false;
    var prevEpisode = false;
    var prevPrevEpisode = false;
    var episodes = episodeList.getElementsByTagName('li');
    for (var i = 0; i < episodes.length; i++) {
        var episode = episodes[i];
        if (prevEpisode && prevEpisode.className.indexOf('selected-episode') > -1) {
            // prevEpisode is actually current, so set the two variables we care about
            nextEpisode = episode;
            prevEpisode = prevPrevEpisode;
            break;
        } 
        prevPrevEpisode = prevEpisode;
        prevEpisode = episode;
    }
    
    var parent = episodeList.parentNode;
    var containerDiv = document.createElement('div');
    containerDiv.setAttribute('class', 'aiv-container-limited');
    if (prevEpisode) {
        var prevA = prevEpisode.getElementsByTagName('a')[0];
        var prevHref = prevA.getAttribute('href');
        var prevTitle = prevEpisode.getElementsByClassName('episode-title')[0].innerHTML.trim();
        var prevH2 = document.createElement('h2');
        prevH2.setAttribute('style', 'float:left');
        var prevLink = document.createElement('a');
        prevLink.setAttribute('href', prevHref);
        var prevText = document.createTextNode('<< ' + prevTitle);
        prevLink.appendChild(prevText);
        prevH2.appendChild(prevLink);
        containerDiv.appendChild(prevH2);
    }
    if (nextEpisode) {
        var nextA = nextEpisode.getElementsByTagName('a')[0];
        var nextHref = nextA.getAttribute('href');
        var nextTitle = nextA.getElementsByClassName('episode-title')[0].innerHTML.trim();
        var nextH2 = document.createElement('h2');
        nextH2.setAttribute('style', 'float:right');
        var nextLink = document.createElement('a');
        nextLink.setAttribute('href', nextHref);
        var nextText = document.createTextNode(nextTitle + ' >>');
        nextLink.appendChild(nextText);
        nextH2.appendChild(nextLink);
        containerDiv.appendChild(nextH2);
    }
    var wrapperDiv = document.createElement('div');
    wrapperDiv.setAttribute('class', 'aiv-wrapper');
    wrapperDiv.appendChild(containerDiv);
    parent.parentNode.insertBefore(wrapperDiv, parent);
}