Fix Yify

Add content ratings to Yify listings and replace torrent urls with magnet links.

Per 24-10-2015. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name        Fix Yify
// @namespace   yts.to
// @description Add content ratings to Yify listings and replace torrent urls with magnet links.
//
// @include     https://yify-movie.com/search*
// @include     http://yify-movie.com/search*
// @require     http://code.jquery.com/jquery-1.11.0.min.js
// @version     0.2.0
// @grant       GM_xmlhttpRequest
// ==/UserScript==

function addTorrentLink(dom, div) {
  $("dd:nth-child(17)", $(dom)).each(function(i) {
    mpr = $(this).text();
  });
  $("dd:nth-child(20)", $(dom)).each(function(i) {
    imdb = $(this).text();
  });
  $("#dm", $(dom)).each(function(i) {
    magnet = $(this).attr('href');
  });

  var title = div.find('h3').text();

  var newText = '<figcaption><a href="'+magnet+'" title="click to download">';
  newText += "<h3 style='color:black;'>";
  newText += title+'<br/>';
  newText += 'MPR: '+mpr+'<br/>';
  newText += 'IMDB: '+imdb+'<br/>';
  newText += "</h3>";
  newText += "</figcaption></a>";

  div.find('figcaption').replaceWith(newText);
}

function addPopupCast(dom, div) {
  var cast = 'ACTORS: ';
  $("span:nth-child(5) span", $(dom)).each(function(i) {
    cast += $(this).text() + ', ';
  });
  cast = cast.replace(/, $/, '');
  console.log("CAST: "+cast);
  // div.find("a").title = cast;
  div.find("a").prop("title", cast);
}

function imposeMyWill(url, div) {
  var data = null;
  // console.log("DIV: "+ div);
  GM_xmlhttpRequest({
    method: "GET",
    url: url,
    onload: function(response) {
      // We've received a response
      data = $.parseHTML(response.responseText);
      // console.log("DATA: "+ data);
      addTorrentLink(data, div);
      addPopupCast(data, div);
      return;
    },
    onerror: function(response) {
      data = JSON.parse(response.responseText);
      console.log('ERROR: '+data);
      // $('#yts-options').html('<p>ERROR! Failed to connect to the YTS website.</p>');
    }
  });
}

function removeAds() {
  var ads = $('a.hidden-xs');
  if (ads.length) {
    console.log('Removing ad box.');
    ads.remove();
  }
}

$(document).ready(function() {
  var divs = $("article.img-item");
  var link = null;
  var url = null;

  // removeAds();

  $(divs).each(function(i) {
    link = $(this).find('h3 a');
    url = link.attr('href');
    // console.log("URL: "+url);
    imposeMyWill(url, $(this));
  });
});