Pixiv - Full size and image search

By Mango Last update Feb 1, 2011 — Installed 4,220 times.

There are 11 previous versions of this script.

// ==UserScript==
// @name            Pixiv - Full size and image search
// @namespace       http://userscripts.org/scripts/show/49738
// @include         http://www.pixiv.net/member_illust.php?*mode=*
// @description     Makes Pixiv use the largest image size for medium images and adds image search links
// @updated         2011-01-31
// ==/UserScript==

var imageSearch =
	"http://danbooru.iqdb.hanyuu.net/db-search.php?url=";//Danbooru
	//"http://iqdb.hanyuu.net/?url=";//Multi-service search

var mode = location.href.replace(/(.*(&|\?)mode=|&.*)/g,'');
var image = null;

if( mode == 'medium' )
{
	var link = document.evaluate("//div/a[contains(@href,'mode=big') or contains(@href,'mode=manga')]",
                                  document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

	//Make link open in same window
	link.removeAttribute('target');

	//For non-manga images, force the display of the full size (scaled) and link it to the image search
	if( /mode=big/.test(link.href) )
	{
		image = link.firstChild;
		image.setAttribute("style", "max-width: 740px; height: auto; width: auto;");
		image.src = image.src.replace(/(\/\d+)_m\./,'$1.');
		link.href = imageSearch + image.src.replace(/(\.[^\.]+$)/,'_s$1') + "&fullimage=" + image.src;
	}
}

else if( mode == 'manga' )
{
	var bigLink = 'http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id='+location.href.replace(/(.*illust_id=|[^\d].*)/g,'') + '&page=';
	var scriptList = document.getElementById("image").getElementsByTagName("script");
	for( var i in scriptList )
	{
		scriptList[i].parentNode.innerHTML += '<br><font size="+3"><a href="' + bigLink + i + '">Big Size</a> - <a href="' + imageSearch + scriptList[i].innerHTML.replace(/(.*unshift\(('|")|('|").*)/g,'') + '&fullimage=' + bigLink + i + '">Image Search</a></font><br>';
	}
}

else if( mode == 'manga_big' || mode == 'big' )
{
	var link = document.getElementsByTagName("a")[0];
	link.removeAttribute( "onclick" );
	image = link.firstChild;
	link.href = imageSearch + image.src;
}

//"View image" shortcut with Ctrl+x when viewing single image
if( image )
	window.addEventListener("keypress", function(key)
	{
		if( key.ctrlKey && String.fromCharCode(key.charCode) == 'x' )
			location.href = image.src;
	}, true);
	
//Check for updates
function updateCheck( dayDelay )
{
	var scriptNum = 49738;
	if( parseInt( GM_getValue('last_check', 0) ) + 24*3600*1000 < new Date().getTime() ) GM_xmlhttpRequest(
	{
		method: 'GET',
		url: 'http://userscripts.org/scripts/source/'+scriptNum+'.meta.js?'+new Date().getTime(),
		headers: { 'Cache-Control': 'no-cache' },
		onload: function(response)
		{
			GM_setValue( 'last_check', ''+new Date().getTime() );

			var localVersion = parseInt( GM_getValue( 'local_version', 0 ) );
			var remoteVersion = parseInt( /@uso:version\s*([0-9]+?)\s*$/m.exec(response.responseText)[1] );
			dayDelay = parseInt( GM_getValue( 'day_delay', dayDelay ) );
			
			if( !localVersion || remoteVersion <= localVersion )
				GM_setValue( 'local_version', remoteVersion );
			else if( dayDelay > 0 )
				GM_setValue( 'day_delay', dayDelay - 1 );
			else if( confirm( 'There is an update available for the Greasemonkey script "'+/@name\s*(.*?)\s*$/m.exec(response.responseText)[1]+'".\nWould you like to go to the install page now?' ) )
			{
				GM_openInTab( 'http://userscripts.org/scripts/show/'+scriptNum );
				GM_setValue( 'local_version', remoteVersion );
				GM_deleteValue( 'day_delay' );
			}
		}
	});
} updateCheck(2);