Open nhentai.net from Tsumino

When clicking on the book cover on a book information page on Tsumino, execute a search by title on nhentai.net and start reading the first result

Versión del día 20/05/2019. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name        Open nhentai.net from Tsumino
// @description When clicking on the book cover on a book information page on Tsumino, execute a search by title on nhentai.net and start reading the first result
// @namespace   xspeed.net
// @version     1.0
// @icon        https://static.nhentai.net/img/logo.650c98bbb08e.svg
// @match       *://www.tsumino.com/Book/Info/*
// @grant       GM_xmlhttpRequest
// ==/UserScript==

(function() {
  'use strict';

  if (location.href.indexOf('/Book/Info/') != -1) {
    
    var title = $('.row>.book-title').text();
    
    var ix = title.indexOf('/');
    if (ix != -1) {
      title = title.substring(0, ix);
    }
    
    ix = title.indexOf('|');
    if (ix != -1) {
      title = title.substring(0, ix);
    }
    
    var url = 'https://nhentai.net/search/?q=english ' + title.replace('?', '').replace('&', '').replace('  ', ' ');
    var elem = $('.book-page-cover > a[href^="/Read/View/"]');
    
    elem.attr('href', '#');
    elem.unbind('click');
    elem.click(function() {
      var onerror = function() {
        location.assign(url);
      }
      
      var onload = function(resp) {
        var respDoc = $(resp.responseText);
        var cover = respDoc.find('.cover');
        if (cover) {
          location.assign('https://nhentai.net' + cover.attr('href') + '1/');
        }
        else {
          onerror();
        }
      };

      GM_xmlhttpRequest({ method: "GET", url: url, onload: onload, onerror: onerror });
    });
  }
  
})();