Perilin / Add Various Torrent Search Links to Trakt.tv Calendar

// ==UserScript==
// @name         Add Various Torrent Search Links to Trakt.tv Calendar
// @version      0.5.1
// @description  Adds  Various (ie, ExtraTorrent.ag, TorrentFunk, RARBG (etc,etc)) Search Links to Trakt.tv Calendar Page
//               See bottom row of icons on each calendar item (skull&bones icons)
//               Search results sorted by size ascending.
//               -- TorrentProject gives errors. ExtraTorrent is back --
// @author       Perilin Night <perilin.night@gmail.com>
// @copyright    2018, Perilin Night
// @date         2016/12/03-2018/01/27
// @match        https://trakt.tv/calendars*
// @match        http://trakt.tv/calendars*
// @grant        none
// @run-at       document-end
// @downloadURL  https://openuserjs.org/src/scripts/Perilin/Add_Various_Torrent_Search_Links_to_Trakt.tv_Calendar.user.js
// @updateURL    https://openuserjs.org/meta/Perilin/Add_Various_Torrent_Search_Links_to_Trakt.tv_Calendar.meta.js
// @priority     1
// @license      MIT
// @icon         https://cdn0.iconfinder.com/data/icons/security-outlines/100/11-128.png
// @screenshot   https://greasyfork.org/system/screenshots/screenshots/000/006/000/original/Untitled.png?1481634810
// @namespace    https://greasyfork.org/users/84102
// ==/UserScript==
(function ()
 {
    'use strict';
    var myStyles = $('<style type="text/css">' +
                     '.trakt-icon-skull-bones-extratorrent:before ' +
                     '{' +
                     '  content: "\\e620";' +
                     '  color: rgb(131, 201, 244);' +
                     '}' +

                     '.trakt-icon-skull-bones-torrentfunk:before ' +
                     '{' +
                     '  content: "\\e620";' +
                     '  color: rgb(135, 212, 44);' +
                     '}' +
/*
  '.trakt-icon-skull-bones-torrentproject:before ' +
  '{' +
  '  content: "\\e620";' +
  '  color: rgb(224, 118, 124);' +
  '}' +
*/
                     '.trakt-icon-skull-bones-rarbg:before ' +
                     '{' +
                     '  content: "\\e620";' +
                     '  color: rgb(56, 96, 187);' +
                     '}' +

                     '.trakt-icon-skull-bones-idope:before ' +
                     '{' +
                     '  content: "\\e620";' +
                     '  color: rgb(233, 68, 53);' +
                     '}' +
                     '</style>');
    $('head').append(myStyles);
    $('div[itemprop="episode"] ').each(function (index)
                                       {
        var objParent = $($(this).find(' > a') [0]);
        var objActions = $($(this).find('> div.quick-icons > div.actions') [0]);
        var objNumbers = $($(objParent).find('span.main-title-sxe') [0]);
        var strNumbers = objNumbers.text();
        var arrNumbers = strNumbers.split('x');
        arrNumbers.forEach(function (item, index, arr)
                           {
            if (item.length <= 1)
            {
                arr[index] = '0' + item;
            }
        }
                          );
        var strEpiNumber = 's' + arrNumbers.join('e').replace('Special', '00');
        var objSeries = $($(objParent).find('span[itemprop="partOfSeries"] meta[itemprop="name"]') [0]);
        var strSeries = objSeries.attr('content');
        
        var strURL_ExtraTorrent = "http://extratorrent.ag/search/?s_cat=&pp=&srt=size&order=asc&search=" + strSeries + " " + strEpiNumber;
        objActions.append(
            '<a class="torrsearch" data-original-title="Search for this episode on ExtraTorrent" title="Search for this episode on ExtraTorrent" href="' + strURL_ExtraTorrent + '" target="' + strSeries + " " + strEpiNumber + '-extratorrent"> ' +
            ' <div class="base"></div>' +
            ' <div class="trakt-icon-skull-bones-extratorrent"></div>' +
            '</a>'
        );
        
        var strURL_TorrentFunk = 'https://www.torrentfunk.com/television/torrents/' + strSeries.toLowerCase().replace(/ +/g, '-') + '-' + strEpiNumber.toLowerCase().replace(/ +/g, '-') + '.html?v=&smi=&sma=&i=50&sort=size&o=asc';
        objActions.append('<a class="torrsearch" data-original-title="Search for this episode on TorrentFunk" title="Search for this episode on TorrentFunk" href="' + strURL_TorrentFunk + '" target="' + strSeries + ' ' + strEpiNumber + '-torrentfunk"> ' +
                          ' <div class="base"></div>' +
                          ' <div class="trakt-icon-skull-bones-torrentfunk"></div>' +
                          '</a>'
                         );

/*
    var strURL_TorrentProject = 'http://torrentproject.se/?hl=en&num=20&start=0&filter=0&safe=on&orderby=sizeA&s=' + strSeries + ' ' + strEpiNumber;
    objActions.append('<a class="torrsearch" data-original-title="Search for this episode on TorrentProject" title="Search for this episode on TorrentProject" href="' + strURL_TorrentProject + '" target="' + strSeries + ' ' + strEpiNumber + '-torrentproject"> ' +
    ' <div class="base"></div>' +
    ' <div class="trakt-icon-skull-bones-torrentproject"></div>' +
    '</a>'
    );
*/
        var strURL_RARBG = 'https://rarbg.to/torrents.php?order=size&by=ASC&search=' + strSeries + ' ' + strEpiNumber;
        objActions.append('<a class="torrsearch" data-original-title="Search for this episode on RARBG" title="Search for this episode on RARBG" href="' + strURL_RARBG + '" target="' + strSeries + ' ' + strEpiNumber + '-rarbg"> ' +
                          ' <div class="base"></div>' +
                          ' <div class="trakt-icon-skull-bones-rarbg"></div>' +
                          '</a>'
                         );

        var strURL_iDope = 'https://idope.se/torrent-list/' + strSeries + ' ' + strEpiNumber + '/?&o=2&c=3';
        objActions.append('<a class="torrsearch" data-original-title="Search for this episode on iDope" title="Search for this episode on iDope" href="' + strURL_iDope + '" target="' + strSeries + ' ' + strEpiNumber + '-idope"> ' +
                          ' <div class="base"></div>' +
                          ' <div class="trakt-icon-skull-bones-idope"></div>' +
                          '</a>'
                         );	   
    });
}) ();