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.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
}