ProjectFreeTv Episode Guide

Enhance ProjectFreeTV links with episode information.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         ProjectFreeTv Episode Guide
// @namespace    pftepisodeguide
// @version      0.2
// @description  Enhance ProjectFreeTV links with episode information.
// @author       splttingatms
// @include      http://projectfreetv.im/free/*
// @include      https://projectfreetv.im/free/*
// @include      http://*.projectfreetv.im/free/*
// @include      https://*.projectfreetv.im/free/*
// @include      http://projectfreetv.im/episode/*
// @include      https://projectfreetv.im/episode/*
// @include      http://*.projectfreetv.im/episode/*
// @include      https://*.projectfreetv.im/episode/*
// @grant        none
// @require      http://code.jquery.com/jquery-3.0.0.min.js
// ==/UserScript==

(function() {
	'use strict';

	function isEpisodePage() {
		return window.location.href.indexOf("episode") !== -1;
	}

	function parseFullEpisodeTitle(title) {
		var parsedEpisode = title.match(/(.+) Season (\d+) Episode (\d+)/);
		return {
			series: parsedEpisode[1],
			season: parsedEpisode[2],
			episode: parsedEpisode[3]
		};
	}
	
	if (isEpisodePage()) {
		var fullEpisodeTitle = $(".title")[0].innerText;
		var episode = parseFullEpisodeTitle(fullEpisodeTitle);

		$.getJSON(`https://www.omdbapi.com/?t=${encodeURIComponent(episode.series)}&Season=${episode.season}&Episode=${episode.episode}&callback=?`, function(result) {
			$(".box b")[3].nextSibling.data = result.Plot;
		});
	} else {
		$("table tr").each(function () {
			var episodeTableRow = $(this);
			var episodeLink = $("a:first-child", episodeTableRow);
			var episode = parseFullEpisodeTitle(episodeLink.text());

			$.getJSON(`https://www.omdbapi.com/?t=${encodeURIComponent(episode.series)}&Season=${episode.season}&Episode=${episode.episode}&callback=?`, function(result) {
				episodeLink.text(`S${episode.season}E${episode.episode} ${result.Title}`);

				var plot = $("</p>")
				.text(result.Plot)
				.css({margin: 0, textAlign: 'left'});

				$("th", episodeTableRow).append(plot);
			});
		});
	}
})();