Sleazy Fork is available in English.

Eza's Image Glutton

Redirects to high-res images on gallery sites, skipping past descriptions and comments

От 05.05.2015. Виж последната версия.

// ==UserScript==
// @name        Eza's Image Glutton
// @namespace   https://inkbunny.net/ezalias
// @author			Ezalias
// @description Redirects to high-res images on gallery sites, skipping past descriptions and comments
// @license     Public domain / No rights reserved
// @include     /^https*://www\.furaffinity\.net/(view|full)/.*/
// @include     https://inkbunny.net/submissionview.php*
// @include     http://gelbooru.com/*page=post&s=view*
// @include     http://youhate.us/*page=post&s=view*
// @include     http://www.gelbooru.com/*s=view*
// @include     http://danbooru.donmai.us/posts/*
// @include     https://danbooru.donmai.us/posts/*
// @include     http://*.tumblr.com/image/*
// @include     /^http(s|)://e(621|926)\.net/post/show*//
// @include     http://*.deviantart.com/art/*
// @include     http://*.hentai-foundry.com/pictures/*
// @include     /^https*://www\.sofurry\.com/view/*//
// @include     https://www.weasyl.com/*
// @include     http://www.y-gallery.net/view/*
// @include     http://rule34.paheal.net/post/view/*
// @include     http://rule34.xxx/index.php?page=post*
// @include     http://rule34hentai.net/post/view/*
// @include     /^https*://derpiboo.ru/*//
// @include     /^https*://derpibooru.org/.*/
// @include     http://*.booru.org/*s=view*
// @include     http://mspabooru.com/*s=view*
// @include     http://safebooru.org/*s=view*
// @include     http://www.majhost.com/cgi-bin/gallery.cgi?i=*
// @include     http://g.e-hentai.org/s/*
// @include     http://nijie.info/view.php?id=*
// @include     http://www.pixiv.net/member_illust.php?mode=medium&illust_id=*
// @include     http://sleepymaid.com/*
// @include     https://*.sankakucomplex.com/post/*
// @include     http://*.bronibooru.com/posts/*
// @include     http://luscious.net/c/*
// @include     https://luscious.net/c/*
// @include     http://imageboard.neko-sentai.com/post/*
// @include     https://uberbooru.com/posts/*
// @exclude    http://www.deviantart.com/users/outgoing?*
// @exclude    *#dnr
// @version     1.24.2
// ==/UserScript==



// Any single-image submission will redirect to the full-size image. On multi-image submissions, every page except the first will redirect to its full-size image. 
// If you go "back" to the normal gallery page (to favorite the image, read its description, leave a comment, etc.) then this script will not send you forward again. 
// https://greasyfork.org/scripts/4713-eza-s-image-glutton
// http://userscripts-mirror.org/scripts/show/169968 (waaay out of date)



// TO DO: 
// for modify_tumblr: for photoset pages (but everywhere, to be safe) make unlinked images link to themselves. I want nice, clean, chronological tabs for multi-image comics. 
// ugh. test without adblock enabled. 
// modify_furaffinity to change prev/next/fav links with pre-appended #dnr. not raw html fiddling: use the DOM and getElementsByType or whatever. thingy.href=url_plus_dnr. 
// flickr? maybe separately. that whole site is a mess. also full-size images are sometimes gigantic, like dozens of megabytes. 
// inkbunny: move page links above first-page preview on multi-image submissions? - by altering divs or css, if possible. minimal molestation implies better future-proofing. 
	// weasyl: replace bespoke thumbnails with smallest preview images? eh, do these as separate scripts, once userscripts stops fucking around.
// Consider changing some @includes to @match. 
// What the hell is @grant? 
// Consider refactoring all Eza's scripts to create and destroy fewer variables. Garbage collection might be why these scripts are rough on CPU use. 
	// Is there some way to tell JS to ditch all variables? There are points in all my scripts where they're 100% finished and can mark all memory as disposable. 
	// Maybe change text-scrape functions to grab a large but fixed-size block of text. Or ditch html_dump entirely and use soft-scrape functions that treat document.etc as a const of absurd size. 
	// There's a 'delete' operator, but it only removes properties from objects. So maybe I can do var thing = new Object; thing.stuff = longstring; ... delete thing.stuff. 
	// I mention this because I'm not considering grabbing Pixiv pages to ensure I have full-size images with a single redirect. 
// http://thehentaiworld.com/hentai-doujinshi/theres-something-about-sakura-naruto/ ? I already do rule34; there's no pretending this is just about "art." 
	// Almost deserves a more Pixiv Fixiv-like fix. Maybe just a link dump like that DeviantArt gallery script?
// Swagster.com? Eh. The name alone rubs me the wrong way. Ugh, and they watermark. 
// Nijie.info support might be missing out on multipage submissions? I don't even have an account. 
// Metabooru is either blocking the US or went down completely three months ago. Leave it in for now, just in case. 
// might've backed the wrong horse with greasyfork. openuserjs seems much livelier. mirror to there, at least. I don't want to switch over after having declared that 'image glutton has a new home.' (incidentally, "image glutton" in quotes already returns the greasyfork page.) - https://openuserjs.org/user/add/scripts - 
// Greasyfork install page as options page? 
// I probably shouldn't redirect to anything ending in swf. 
// Opening many e621 links sometimes produces #dnr pages with no redirect. I reeeally wish I could '@run-at start' and prevent images from loading. 
// auto-reload? e.g. to skip fa's 503  nonsense. generalize to 'automatic_reload_if' or something. slight delay, then location.reload(). 
	// function reload_if( text_found ). 
	// Problem with gelbooru: pages load, images 503. no way to run the script on images without redirect loops. blar. 
	// http://simg3.gelbooru.com//images/0c/95/0c95669a094fcc24986923b3e5231a3d.jpg?779021 
// How should I handle deleted works on Pixiv? E.g. http://www.pixiv.net/member_illust.php?mode=medium&illust_id=34604157
// This would work faster if I could delay or prevent the loading of images. E.g., execute script before loading page, define CSS that doesn't download embedded images, wait for page to load, scrape image_url, and then redirect as usual. Since the script wouldn't trigger on #dnr (which I should do as an @exclude, I guess) images would load as usual when you clicked 'back.' 
	// This thought is mostly driven by opening a bunch of e.g. Gelbooru links all at once. They spend long enough loading that the full-size images are usually half-done before the redirect happens. 
// Getting a generic Pixiv error on http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46742182 
// Redirects to http://www.pixiv.net/member_illust.php?mode=manga&illust_id=46693388 
// Escape function in JS is encodeURI. Also use in Tumblr Scraper, where we need 'safe' URLs as tag IDs. 
// FurAffinity stories redirect to thumbnail, e.g. http://www.furaffinity.net/view/15903888/ - might need to break out a whole complex function here. 
// DeviantArt stories redirect to thumbnails. 
// http://seiga.nicovideo.jp/seiga/im4507046 ? 
// My Nijie support is basically nonexistant because I didn't have an account. Turns out they're more like Pixiv now, including multi-image posts. This is problematic. (Animations work, though.) 
// Doublecheck DeviantArt support. Seems wonky. 
// Inkbunny broke. 

// Added Luscious.net 
// Added Neko-Sentai.com 
// Added Uberbooru.
// Fixed / simplified DA. 
// Fixed Inkbunny. 

// Since I'm just leafing through HTML (usually), can I jump to the image /before/ trying to load the page? GreaseMonkey has a wonky option for running the script before the page runs, but I don't think we get all the HTML first. Maybe... maybe AJAX the page we're on? Like, @RunAtStart or whatever, then create a little blank page, then grab the URL via XmlHTTPgetObject or whatever, then read the HTML as responseText. The trouble (I expect) would be going back to the normal page when someone hits 'back.' This script shouldn't run... but any browser will probably have cached the fake page. 

// Do-before-load, grab page via ajax, and process as text to redirect before DOM even knows what's going on?
	// intent is to fully prevent rendering of images / execution of other JS, to hastily redirect to whatever image URL is required. 
	// Surprisingly, it works! Any site relying on extract-image-url-after is easy to please. 
	// Cons: still not blazing-fast. Probably doubles GET requests to server, though overall bandwidth might be lower. Forces reliance on extract-etc function. 503-fixer seems busted. 
		// Getting "too much recursion" errors in ctrl+shift+j (error console). 503s still boned. 
	// Reverted. It was an interesting idea, but it was added complexity that broke some useful features. (And then broke entirely. Recursion? WTF?) 
	// Can I run-at document-start and then fire a function at document-end? That might allow me to </html> ASAP, killing the page's execution... but then we'd need to reload if we don't redirect. Hm. 
	// Is there JS to prevent the execution of JS? 

// Owyn Tyler has a ridiculously replete script with similar goals called Handy Just Image - http://userscripts.org/scripts/show/166494
// The supported-site list is waaay longer than mine, and/but his goals are more complex. Image Glutton exists only to deliver the image. 
// He's having trouble with back-trapping, though. His solution sounds absurdly complex even compared to mine. Test the script and recommend help if possible. 






// global variables, for simplicity
var image_url = '';		// location of the full-size image to redirect to
var wait_for_dnr = false;		// some site URLs use "#" liberally, so if this var isn't empty, only "#dnr" will stop a redirect
var page_failed = false; 		// If the page 503s or otherwise forces us to reload, wait a moment, then reload. 



// detect site, extract image URL, then decide whether or not to redirect
	////////// 		Simple extract_image_url_after sites
if ( address_bar_contains('e621.net') ) { extract_image_url_after( '>Respond</a>', 'https://' ); }
else if ( address_bar_contains('e926.net') ) { extract_image_url_after( '<li>Size:', 'http' ); }
else if ( address_bar_contains('weasyl.com') ) { extract_image_url_after( '<div id="detail-art">', '/' ); }		// also redirects to plaintext/HTML on stories, haha
else if ( address_bar_contains('hentai-foundry.com') ) { extract_image_url_after( '<center><img', '//' ); reload_if( '<h1>An error occurred.' ); }
else if ( address_bar_contains('y-gallery.net') ) { extract_image_url_after( 'a_center container2">', 'http://' ); }
else if ( address_bar_contains('rule34.xxx') ) { extract_image_url_after( '>Edit</a></li>', 'http://' ); }
else if ( address_bar_contains('derpiboo.ru') ) { extract_image_url_after( '>View<', '//' ); }
else if ( address_bar_contains('derpibooru.org') ) { extract_image_url_after( '>View<', '//' ); }
else if ( address_bar_contains('sankakucomplex.com') ) { extract_image_url_after( '<li>Original:', '//' ); } 
	////////// 		Slightly complicated extract_image_url_after sites
else if ( address_bar_contains('rule34hentai.net') ) { extract_image_url_after( 'shm-zoomer', '/_images/' ); wait_for_dnr = true; }
else if ( address_bar_contains('rule34.paheal.net') ) { extract_image_url_after( 'shm-zoomer', 'http://' ); wait_for_dnr = true; }
else if ( address_bar_contains('majhost.com') ) { image_url = document.getElementsByTagName( "img" )[0].src; }		// first and only <img> tag
else if ( address_bar_contains('luscious.net') ) { image_url = document.getElementById( 'original' ).href; } 
	////////// 		Simple custom sites
else if ( address_bar_contains('sofurry.com') ) {
	image_url = window.location.href.replace('sofurry.com/view/','sofurryfiles.com/std/content?page='); 
	if( document.body.outerHTML.indexOf( '<div id="sfContentImage' ) < 0 ) { image_url = ''; } 		// Do not redirect from stories
	if( document.body.outerHTML.indexOf( '<div class="sf-story"' ) > 0 ) { image_url = ''; } } 		// Really do not redirect from stories
else if ( address_bar_contains('danbooru.donmai.us') ) { 
	extract_image_url_after( '% of original (', '/data/' );		// resized images will say "X% of original (view full" or something like that
	if( image_url == '' ) {extract_image_url_after( 'twitter:image:src', 'http://' );		// otherwise just grab the preview-sized image (this also works on pages claiming you need Gold to see them)
	image_url = image_url.replace( '/sample/sample-', '/' ); }	 }	// if the preview-sized image is a sample, fix that - this sometimes fails for PNG images with JPG previews
else if ( address_bar_contains('furaffinity.net') ) {
	reload_if( 'center;">Error 503' ); 
	if (unsafeWindow.full_url)			// Basically stolen from http://userscripts.org/scripts/review/157574 - but FA's kind enough to define the URL as a var, so why fight the obvious approach? 
		{ image_url = unsafeWindow.full_url; } 		// use full_url variable from live window HTML
	//if( document.getElementsByTagName('html')[0].innerHTML.indexOf( 'Category:</b> Story' ) > 0 ) { image_url = ''; } 		// Don't redirect from stories. 
	// Arg, still redirecting from music. There's a table with the text in it... but it has no unique ID. Has different width on images? Blarg, also width=1% on music (to fit to content). 
	// Can't just check 'category: art' because there's a wide variety. 
	}
else if ( address_bar_contains('http://g.e-hentai.org/s/') ) { 
	var image_index = document.body.outerHTML.indexOf( '</iframe>' );		// jump to end of navigation iframe
	image_index = document.body.outerHTML.indexOf( 'http://', image_index+1 );		// find next URL (link to next page)
	image_index = document.body.outerHTML.indexOf( 'http://', image_index+1 );		// find URL after that (image source)
	image_url = document.body.outerHTML.substring( image_index, document.body.outerHTML.indexOf( '"', image_index ) ); }		// grab image src, delimited by doublequote 
else if ( address_bar_contains('nijie.info') ) {
	extract_image_url_after( 'name="twitter:image"', 'http://' );		// some images are behind some sort of barrier, so let's grab the twitter-size image instead...
	image_url = image_url.replace( '/sp/', '/' ); }		// ... and drop the /sp/ to get the full-size URL. 
else if ( address_bar_contains('sleepymaid.com') ) { 
	image_url = document.getElementById( 'the-image' ).src; 
	if( document.getElementById( 'next' ) ) { image_url = ''; } }		// Don't redirect on comic pages 
else if ( address_bar_contains('neko-sentai.com') ) { image_url = document.getElementById( 'main_image' ).src; } 
//else if ( address_bar_contains( 'uberbooru.com' ) ) { image_url = document.getElementById( 'image' ).src; extract_image_url_after( 'Size: <a', 'https://' ); }
//else if ( address_bar_contains( 'uberbooru.com' ) ) { image_url = document.getElementById( 'image' ).src; image_url = document.getElementById( 'image-resize-link' ).href; }  
//else if ( address_bar_contains( 'uberbooru.com' ) ) { image_url = document.getElementById( 'image-container' ).data-file-url; }
//else if ( address_bar_contains( 'uberbooru.com' ) ) { image_url = document.getElementById( 'image-container' )["data-file-url"]; } 
//else if ( address_bar_contains( 'uberbooru.com' ) ) { image_url = document.getElementById( 'image-container' )['data-id']; } 
else if ( address_bar_contains( 'uberbooru.com' ) ) { extract_image_url_after( 'id="image-container', 'https://' ); } 
	////////// 		Sites complex enough to shove into a function down below 
else if ( address_bar_contains( 'deviantart.com' ) ) { scrape_deviantart(); wait_for_dnr = true; }
else if ( address_bar_contains( 'inkbunny.net' ) ) { scrape_inkbunny(); }
//else if ( address_bar_contains( 'tumblr.com' ) ) { scrape_tumblr(); } 		// Tumblr is now limited to /image/ URLs. Post-redirection was really inconsistent and overzealous. 
else if ( address_bar_contains( 'tumblr.com' ) ) { extract_image_url_after( 'id="content-image"', 'http://' ); }
else if ( address_bar_contains( 'pixiv.net' ) ) { scrape_pixiv(); }
else if ( address_bar_contains( 'gelbooru.com' ) ) { scrape_booru(); } 
else if ( address_bar_contains( 'youhate.us' ) ) { scrape_booru(); } 
else if ( address_bar_contains( '.booru.org' ) ) { scrape_booru(); } 
else if ( address_bar_contains( 'mspabooru.com' ) ) { scrape_booru(); } 
else if ( address_bar_contains( 'safebooru.org' ) ) { scrape_booru(); } 
else if ( address_bar_contains( 'bronibooru.com' ) ) { scrape_booru(); } 



// If the page didn't load properly, but could be fixed by reloading, then wait a moment and reload 
if( page_failed ) { 		// If we get a 503 or other 'please reload' error
	image_url = ''; 		// do not redirect this time
	setTimeout( function inline_reload() { location.reload(); }, Math.floor((Math.random() * 10) + 1) * 1000 ); 		// 1s-10s pause. Can't believe you have to name inline functions. 
//	document.getElementsByTagName('html')[0].innerHTML = "It worked."; 		// debug 
//	alert( '503' ); 		// debug 
}



// having defined image_url by scraping the page's HTML, modify the current URL to prevent back-traps, then redirect to that full image 
if( image_url !== '' && (!address_bar_contains('#') || wait_for_dnr) ) 		// do nothing if image_url is empty. ignore pages with a "#", unless wait_for_dnr makes you wait for a full "#dnr". 
{
		// some images don't redirect properly, even if you manually "view image" - so we append ".jpg" to URLs without file extensions, forcing the browser to consider them images
		// even if this doesn't work, the new URL should just 404, which is better than the semi-modal "octet stream" dialog seen otherwise. 
	if( image_url.lastIndexOf( '/' ) > image_url.lastIndexOf( '.' ) ) { image_url = image_url + '.jpg'; }		// if there's not a "." after the last "/" then slap a file extension on there 
	if( image_url[ image_url.length - 1 ] == '.' ) { image_url = image_url + 'jpg'; }		// if the URL ends with a dot, slap a file extension on there 

		// modify current location, so that when the user clicks "back," they aren't immediately sent forward again
	modified_url = window.location.href + '#dnr'; 		// add do-not-redirect tag to current URL
	history.replaceState( {foo:'bar'}, 'Do-not-redirect version', modified_url);		// modify URL without redirecting. the {foo:'bar'} thing is a state object that I don't care about, but the function needs one.

//	window.location.href = image_url;		// redirect to full image
	location.assign("javascript:window.location.href=\""+image_url+"\";");		// pixiv-friendly redirect to full image: maintains referral, happens within document's scope instead of within greasemonkey's
}		// end of main execution





// ----- //			Functions for readability





function extract_image_url_after( string_before_url, url_begins_with ) {		// extract the first quote-delimited string that appears after unique first var and begins with second var
	var html_elements = document.getElementsByTagName('html'); 		// this way we avoiding doing getElementsEtc every time, and we still access the whole page's HTML by reference
	var string_index = html_elements[0].innerHTML.indexOf( string_before_url ); 		// find a unique string somewhere before the image URL
	if( string_index > -1 ) {
		var image_index = html_elements[0].innerHTML.indexOf( url_begins_with, string_index );  		// find where the image URL starts after the unique string
		var delimiter_index = html_elements[0].innerHTML.indexOf( '"', image_index ); 		// find first doublequote after the image URL starts
		image_url = html_elements[0].innerHTML.substring( image_index, delimiter_index ); 		// grab the image URL up to the next doublequote 
	}
}

function address_bar_contains( string_to_look_for ) {	// I'm so tired of typing out window.location.etc == -1. It's stupidly verbose and it looks terrible.
	return (window.location.href.indexOf( string_to_look_for ) !== -1);		// this makes code more concise and readable. if( address_bar_contains( 'tld.com' ) ) { do tld.com stuff; }
}

function reload_if( error_string ) { 
	var html_elements = document.getElementsByTagName('html'); 		// this way we avoiding doing getElementsEtc every time, and we still access the whole page's HTML by reference
	var string_index = html_elements[0].innerHTML.indexOf( error_string ); 		// look for a string indicating the page failed to load 
	if( string_index > -1 ) { page_failed = true; } 
}





// ----- //			Functions for individual websites (separated for being especially long)




/*
function scrape_tumblr() {
	// Tumblr's goals are basically like Inkbunny's:
	//		- On a generic post or /image/ page with a single image: redirect to that image in the highest resolution available
	//		- On a multi-image post: do nothing, since photosets already are or link to their highest-resolution versions
	if( address_bar_contains('/image/') ) { 		// on centered-image pages
		extract_image_url_after( 'id="content-image"', 'http://' );		// get conveniently-labeled id="image" image
	}		// The above will handle /post/ to /image/ URL conversions in a sort of double-redirect, letting Tumblr do the hard work of finding the highest-res version of an image
	else if( address_bar_contains( '/post/' ) ) {		// on generic Tumblr posts
		image_url = window.location.href.replace( '/post/', '/image/' );  
		var comment_check_index = image_url.lastIndexOf( '/' );		// if the /post/ contained text, it gets appended after the post/image number and screws up the URL...
		if( image_url.substring( comment_check_index - 6, comment_check_index ) !== '/image' ) {		// ... so if the last '/' isn't the latter in '/image/' then we dump everything after that '/'...
			image_url = image_url.substring( 0, comment_check_index );		// ... by taking the substring up to the index of that final '/'.
		}
			// If the theme is kind enough to use proper Open Graph tags, let's use those instead for a single redirect:
		var post_image_url = image_url;		// store the double-redirect URL just in case
		extract_image_url_after( 'property="og:image"', 'http' );
		if( image_url.indexOf( '_1280.' ) == -1 ) { image_url = post_image_url; }		// if the Open Graph isn't _1280 (and thus might be misdefined at low-res), just double-redirect instead  
	}		// this might also trigger on images with no _size in the URL, but I think those are all tumblr-feed:entry items anyway. hardly matters. /image/ would still work. 

		// Now that image_url is defined, we can blank it out if we don't want to redirect. Much easier than piling on if( || && || )-style logic. 
	if( address_bar_contains( '_iframe/' ) ) { image_url = ''; }		// Do not redirect from photoset iframe pages, since they trigger their own instance of this script
	if( document.body.outerHTML.indexOf( 'class="html_photoset"' ) !== -1 ) { image_url = ''; }		// Do not redirect from photosets (because photoset images always are or link to highest-res versions)
	if( document.head.outerHTML.indexOf( 'content="tumblr-feed:entry"' ) !== -1 ) { image_url = ''; }	// Do not redirect if Open Graph indicates a text-only post (as opposed to tumblr-feed:photo). 
	if( document.head.outerHTML.indexOf( 'content="tumblr-feed:photoset""' ) !== -1 ) { image_url = ''; }	// Do not redirect if Open Graph indicates a text-only post (as opposed to tumblr-feed:photo). 
}
*/

// DeviantArt sometimes doesn't redirect until you F5. I suspect it's their fancy-pants not-actually-redirecting nonsense. Websites - stop acting stupid and just /be documents./ You are not an app. 
function scrape_deviantart() {		// this doesn't use ditch_html_before because data-super-full-img's appear for random links - we need to avoid grabbing one from the ass-end of small-image pages
	/*
	var image_index = document.body.outerHTML.indexOf( 'class="dev-view-deviation"' ); 		// jump to unique and hopefully universal dev-view-deviation div
	if( image_index > 0 ) { 		// Don't redirect on pages without a deviation (e.g. "oops not found" faux-404s). 
		var image_index = document.body.outerHTML.indexOf( 'src=', image_index+1 ); 		// jump to first src (preview size)
		var image_index = document.body.outerHTML.indexOf( 'http://', image_index+1 ); 		// jump to the URL defined in src
		image_url = document.body.outerHTML.substring( image_index, document.body.outerHTML.indexOf( '"', image_index ) ); 		// grab URL, delimited by doublequote
		if( image_url.indexOf( "/PRE/" ) > 0 ) { image_url = image_url.replace( "/PRE/", "/" ); } 		// fix preview-size image to be full-size
	} 
	if( document.body.outerHTML.indexOf( '<div id="flashed-in"' ) > 0 ) { image_url = ''; } 		// Do not redirect on flash pages 
	*/

	image_url = document.getElementsByClassName( "dev-content-full" )[0].src; 		// Woo, document-object model.
	// This still isn't always full-size, because DeviantArt is awful. 
	// E.g. http://whiskypaint.deviantart.com/art/Commission-Pinup-style-526359546 fails - the Download size is bigger than any display size, and there's no way to see just the image.
}

function scrape_inkbunny() {
	var image_index = document.body.outerHTML.indexOf( 'https://us.ib.metapix.net/files/screen/' );		// look for screen-size image URL 
	if( image_index !== -1 )		// if that URL is found
	{
		var delimiter_index = document.body.outerHTML.indexOf( '"', image_index );		// find first doublequote delimiter after URL
		image_url = document.body.outerHTML.substring( image_index, delimiter_index );		// grab delimited URL 
		image_url = image_url.replace( '/screen/', '/full/' );		// turn screen URL into full URL - we don't care if /screen/ is already full-size, because /full/ will kindly redirect anyway
	}

	// if this page is the landing page for a multi-image submission, do not redirect 
	if ( document.body.outerHTML.indexOf( '<form id="changethumboriginal_form"' ) !== -1 && !address_bar_contains( '&page=' ) ) {		// look for language-agnostic 'show custom thumbnails' button
		image_url = '';		// note: we do redirect on URLs for individual pages, including the first. 
	}
}

// Getting a generic Pixiv error on http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46742182 
// Redirects to http://www.pixiv.net/member_illust.php?mode=manga&illust_id=46693388 
// Should apparently go to http://i1.pixiv.net/img-original/img/2014/10/23/18/06/17/46693388_p0.jpg 
// Arg, some images still use the old _p0_1200 nonsense. 

// http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46628167 
// should go to http://i4.pixiv.net/img-original/img/2014/10/19/13/08/37/46628167_p0.jpg 
// same idea, _p0_master1200 nonsense. 
// http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46444244 screws up 
// should be http://i1.pixiv.net/img-original/img/2014/10/09/17/29/07/46444244_p0.jpg 

// http://www.pixiv.net/member_illust.php?mode=medium&illust_id=48506438#dnr
// http://i3.pixiv.net/img-original/img/2015/02/02/00/00/54/48506438_p0.jpg
// http://i3.pixiv.net/c/150x150/img-master/img/2015/02/02/00/00/54/48506438_p0_master1200.jpg
// http://i3.pixiv.net/c/150x150/img-original/img/2015/02/02/00/00/54/48506438_p0.jpg

// Shit, now mangas don't redirect. 
function scrape_pixiv() { 
	extract_image_url_after( 'class="_illust_modal', 'http://' ); 		// Oh, what now? Code below doesn't work for some pages, so do this instead. (This goes first because only the last successful 'extraction' matters.) 
	extract_image_url_after( 'class="big"', 'http://' ); 		// New Pixiv pages (Dec '14) provide the big URL rather directly. 

	if( image_url == '') { 		// try this old nonsense first, because god forbid these sites update all their code to be remotely fucking consistent
//		extract_image_url_after( '_illust_modal">', 'http://' ); 		// grab preview image from "medium" landing page
		extract_image_url_after( 'bookmark_modal_thumbnail', 'http://' ); 		// grab bookmark-thumbnail image from "medium" landing page  
			// convert URL to full-size. 
		image_url = image_url.replace( '_m.', '.' ); 		// old style: remove _m for full-size URL
//		image_url = image_url.replace( '/c/600x600', '' ); 		// new style: remove /c/600x600, swap image-master for image-original, remove _master1200. 
		image_url = image_url.replace( '/c/150x150', '' ); 		// new style: remove /c/150x150, swap image-master for image-original, remove _master1200. 
		image_url = image_url.replace( '/img-master/', '/img-original/' ); 
		image_url = image_url.replace( '_master1200', '' ); 
	}

	// Through sheer accident, the old manga code still works after Pixiv's latest change. 
//	if( image_url == '') { 		// if there's no 'big' link and thus no image was grabbed, it's probably manga
	if( document.getElementsByTagName('html')[0].innerHTML.indexOf( '<a href="member_illust.php?mode=manga' ) > 0 ) { 		// If the works_display preview links to the manga, go there instead
		image_url = window.location.href.replace( 'mode=medium', 'mode=manga' );		// manga pages deserve their own HTML, so just go to that page 
		// Users: please consider Eza's Pixiv Fixiv, which replaces the default manga HTML with full images and none of that scroll-to-load nonsense. 
	} 

	// Don't redirect to "Ugoira" animations (ZIP full of JPGs, played as HTML slideshow) 
	if( document.getElementsByTagName('html')[0].innerHTML.indexOf( 'class="_ugoku' ) > 0 ) { 		// A little messy since we ditched html_copy, isn't it? 
		image_url = ''; 		// prevent redirect by blanking image_url
		// add link to ZIP for Ugoira, purely for archival purposes 
		var ugoku_link = pixiv.context.ugokuIllustData.src;
		document.getElementsByClassName( '_ugoku-illust-player-container' )[0].innerHTML += '<br><a href="' + ugoku_link + '">Download Ugoku frames as ZIP file</a>';  
	} 
}

function scrape_booru() {		// this works on a wide variety of booru-style imageboards. 
//	extract_image_url_after( '>Resize image</a>', 'http://' );		// for booru's which have automatic resizing and images which require it
	extract_image_url_after( "$('edit_form')", 'http://' ); 		// For booru's with automatic resizing on, use the Original Image link, which appears after the Edit button
	if( image_url == '' ) {		// otherwise, use the image that's being displayed 
		var container = document.getElementById( 'image' ); 		// Instead of lurching through raw HTML, let's just grab the display image via the DOM. 
		image_url = container.src; 		// "You think it's cool that things don't always have to be a federal fucking issue." 
	} 
}









/*
Test suite of random URLs from the relevant sites: 
http://www.hentai-foundry.com/pictures/user/Bottlesoldier/133840/Akibabuse
http://www.hentai-foundry.com/pictures/user/Bottlesoldier/214533/Lil-Gwendolyn
https://inkbunny.net/submissionview.php?id=483550
https://inkbunny.net/submissionview.php?id=374519
http://rule34.xxx/index.php?page=post&s=view&id=1399731
http://rule34.xxx/index.php?page=post&s=view&id=1415193
http://equi.booru.org/index.php?page=post&s=view&id=56940
http://furry.booru.org/index.php?page=post&s=view&id=340299
http://derpibooru.org/470074?scope=scpe80a78d33e96a29ea172a0d93e6e90b47c6a431ea
http://mspabooru.com/index.php?page=post&s=view&id=131809
http://mspabooru.com/index.php?page=post&s=view&id=131804
http://shiniez.deviantart.com/art/thanx-for-5-m-alan-in-some-heavy-makeup-XD-413414430
http://danbooru.donmai.us/posts/1250724?tags=dennou_coil
http://danbooru.donmai.us/posts/1162284?tags=dennou_coildata:text/html,<img src='http://example.com/image.jpg'>
http://www.furaffinity.net/view/12077223/
http://gamesbynick.tumblr.com/post/67039820534/the-secrets-out-guys-the-secret-is-out
http://honeyclop.tumblr.com/post/67122645946/stallion-foursome-commission-for-ciderbarrel-d
http://shubbabang.tumblr.com/post/20990300285/new-headcanon-karkat-is-ridiculously-good-at
http://www.furaffinity.net/view/12092394/
https://e621.net/post/show?md5=25385d2349ae11f2057874f0479422ad
http://sandralvv.tumblr.com/post/64933897836/how-did-varrick-get-that-film-cuz-i-want-a-copy
*/