E-H Search for nhentai Favorites

Quickly move favourite from nhentai back to e-hentai/exhentai.

As of 2018-11-04. See the latest version.

// ==UserScript==
// @name           E-H Search for nhentai Favorites
// @description    Quickly move favourite from nhentai back to e-hentai/exhentai.
// @author         Hen Tie
// @homepage       https://hen-tie.tumblr.com/
// @namespace      https://greasyfork.org/en/users/8336
// @include        https://nhentai.net/favorites/*
// @require        https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// @icon           https://i.imgur.com/8bq1S92.jpg
// @version        1.5
// ==/UserScript==

$(function(){
	var galTitle = []
	var url = "https://exhentai.org/?f_search="
	$('.gallery-favorite .caption').each(function(){
		var str = $(this).text();
		str = str.replace(/[\][(){}|~,."'!?+*%:$]/igm,' ') //replace search operators and punctuation/formatting characters
		str = str.replace(/ \w{1,2}\b/igm,'') //remove 1 or 2 char keywords, too short to search
		str = str.replace(/ {2,}/igm,' ') //compress 2+ spaces into just one
		str = str.replace(/^ (?=.*$)/igm,'') //remove leading space
		var isEng = str.match(/english/gi) //check for language
		if (isEng !== null) {
			str = str.replace(isEng[0],''); //remove lang
			str = isEng[0] + ' ' + str; //prepend lang
			str = str.replace(/ {2,}/igm,' ') //compress 2+ spaces into just one
		}
		galTitle.push(str);
	})
	$('.remove-button').each(function(i) {
		$(this).after('<button class="btn btn-primary btn-thin" title="Search on Ex-Hentai">' +
			'<a href="' + url + galTitle[i] + '" target="_blank">' +
				'<i class="fa fa-external-link"></i>' +
			'</a>' +
		'</button>');
	})
})