Perilin / Add Various Search Links to Trakt.tv Calendar

// ==UserScript==
// @name         Add Various Search Links to Trakt.tv Calendar
// @version      0.6.6
// @description  Adds  Various (ie, 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 (where possible).
//               -- TorrentProject gives errors. ExtraTorrent is back --
// @author       Perilin Night <perilin.night@gmail.com>
// @copyright    2020, Perilin Night
// @date         2016/12/03-2020/10/01
// @match        https://trakt.tv/calendars*
// @match        http://trakt.tv/calendars*
// @grant        none
// @run-at       document-end
// @downloadURL  https://openuserjs.org/install/Perilin/Add_Various_Search_Links_to_Trakt.tv_Calendar.user.js
// @updateURL    https://openuserjs.org/meta/Perilin/Add_Various_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';

  jQuery.expr[':'].regex = function (elem, index, match) {
    var matchParams = match[3].split(','),
      validLabels = /^(data|css):/,
      attr = {
        method: matchParams[0].match(validLabels) ?
          matchParams[0].split(':')[0] : 'attr',
        property: matchParams.shift().replace(validLabels, '')
      },
      regexFlags = 'ig',
      regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g, ''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
  }

  var adAttrTypes = ['id', 'class', 'name'];
  for (var adAttrTypeIndex = -1; adAttrTypeIndex <= 2; adAttrTypeIndex++) {
    console.log(' adAttrTypeIndex = ' + adAttrTypeIndex);
    var adAttrType = adAttrTypes[adAttrTypeIndex];
    console.log(' adAttrType = ' + adAttrType);
    if (typeof (adAttrType) == "string") {
      jQuery(':regex(' + adAttrType + ', .*?-.*)').each(function (index, item) {
        console.log(index + ": " + $(item).attr(adAttrType).replace(/-/gi, ''));
        if ($(item).attr(adAttrType).replace(/-/gi, '').match(/.*?huckster.*/ig)) {
          console.log(index + ": " + $(item).attr(adAttrType).replace(/-/gi, '') + ' - removed.... ');
          $(item).remove();
        }
      })
    }
    adAttrType = undefined;
  }
  var myStyles = jQuery('<style type="text/css">' +

    '.trakt-icon-skull-bones-torrentfunk:before ' +
    '{' +
    '  content: "\\e620";' +
    '  color: rgb(135, 212, 44);' +
    '}' +

    '.trakt-icon-skull-bones-rarbg:before ' +
    '{' +
    '  content: "\\e620";' +
    '  color: rgb(56, 96, 187);' +
    '}' +

    '.trakt-icon-skull-bones-ddl:before ' +
    '{' +
    '  content: "\\e620";' +
    '  color: white;' +
    '}' +

    '.trakt-icon-skull-bones-rlsbb:before ' +
    '{' +
    '  content: "\\e620";' +
    '  color: orange;' +
    '}' +
    /*
                 '.trakt-icon-skull-bones-fmovies:before ' +
                 '{' +
                 '  content: "\\e620";' +
                 '  color: #00acc1;' +
                 '}' +
    */
    '.trakt-icon-skull-bones-primewire:before ' +
    '{' +
    '  content: "\\e620";' +
    '  color: #2c81c1;' +
    '}' +

    '.trakt-icon-skull-bones-hastidl:before ' +
    '{' +
    '  content: "\\e620";' +
    '  color: #56D397;' +
    '}' +

    '</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_TorrentFunk = 'https://www.torrentfunk.com/television/torrents/' + encodeURIComponent(strSeries.toLowerCase().replace(/ +/g, '-').replace("'", '') + '-' + 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_RARBG = 'https://rarbg.to/torrents.php?order=size&by=ASC&search=' + encodeURIComponent(strSeries + ' ' + strEpiNumber).replace(/%20/g, '+');
    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_DDL = 'https://www.google.co.za/search?q=%22' + encodeURIComponent(strSeries + ' ' + strEpiNumber) + '%22+%2B(mp4|avi|mkv|mpg|mov)+-inurl:(jsp|pl|php|html|aspx|htm|cf|shtml|xml) intitle:index.of+-inurl:(listen77|mp3raid|mp3toss|mp3drug|index_of|wallywashis|feeds)';
    objActions.append('<a class="torrsearch" data-original-title="Search for this episode on Google" title="Search for this episode on Google" href="' + strURL_DDL + '" target="' + strSeries + ' ' + strEpiNumber + '-ddl"> ' +
      ' <div class="base"></div>' +
      ' <div class="trakt-icon-skull-bones-ddl"></div>' +
      '</a>'
    );

    var strURL_rlsBB = 'http://rlsbb.ru/search/' + encodeURIComponent(strSeries + ' ' + strEpiNumber).replace(/%20/g, '+');
    objActions.append('<a class="torrsearch" data-original-title="Search for this episode on ReleaseBB" title="Search for this episode on ReleaseBB" href="' + strURL_rlsBB + '" target="' + strSeries + ' ' + strEpiNumber + '-rlsbb"> ' +
      ' <div class="base"></div>' +
      ' <div class="trakt-icon-skull-bones-rlsbb"></div>' +
      '</a>'
    );
    /*
        var strURL_fmovies = 'https://fmovies.to/search?keyword=' + encodeURIComponent(strSeries + ' ' + strEpiNumber).replace(/%20/g, '+');
        objActions.append('<a class="torrsearch" data-original-title="Search for this episode on FMovies" title="Search for this episode on FMovies" href="' + strURL_fmovies + '" target="' + strSeries + ' ' + strEpiNumber + '-fmovies"> ' +
                ' <div class="base"></div>' +
                ' <div class="trakt-icon-skull-bones-fmovies"></div>' +
                '</a>'
                 );
    */

    var strURL_primewire = 'https://www.primewire.li/?s=' + encodeURIComponent(strSeries).replace(/%20/g, '+') + '&sort=Release&links=With+Links&type=tv&t=y&m=m&w=q';
    objActions.append('<a class="torrsearch" data-original-title="Search for this show on PrimeWire" title="Search for this show on PrimeWire" href="' + strURL_primewire + '" target="' + strSeries + ' ' + strEpiNumber + '-primewire"> ' +
      ' <div class="base"></div>' +
      ' <div class="trakt-icon-skull-bones-primewire"></div>' +
      '</a>'
    );

    var strURL_hastiDL = 'http://myhastidl10.top/?s=' + encodeURIComponent(strSeries).replace(/%20/g, '+');
    objActions.append('<a class="torrsearch" data-original-title="Search for this episode on HastiDL" title="Search for this episode on HastiDL" href="' + strURL_hastiDL + '" target="' + strSeries + ' ' + strEpiNumber + '-hastidl"> ' +
      ' <div class="base"></div>' +
      ' <div class="trakt-icon-skull-bones-hastidl"></div>' +
      '</a>'
    );

  });
})();