Eza's Pixiv Fixiv

Loads Pixiv "manga" pages without having to scroll down and wait

目前為 2014-10-06 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Eza's Pixiv Fixiv
// @namespace   https://inkbunny.net/ezalias
// @description Loads Pixiv "manga" pages without having to scroll down and wait
// @include     http://www.pixiv.net/member_illust.php?mode=manga&illust_id=*
// @version     1.4
// ==/UserScript==



// On manga pages, load all images without having to manually scroll to each one. 
// Pixiv is terribly designed. Maybe it's a cultural Japanese thing, where they still expect single-page click-and-wait browsing like it's still 1998. The site is just openly hostile to users' time and enjoyment. 
// To wit, I recommend Eza's Image Glutton, which directs from the "medium" landing pages to either the full-size single image or the manga page. Tedium is for robots. 

// Ideally we'd trigger whatever mechanism tells the page to load each image. 
//		Three problems with that: I'm an HTML/JS amateur, the coders didn't speak much English, and - crucially - we'd still be loading medium-size images.
// So instead we're going to scrape the page for URLs, build our own no-bullshit HTML, and replace the entire Body of the page.
// Pixiv's super-paranoid anti-hotlinking mechanisms will not trigger because it only sees one of its own pages requesting these images. We don't have to worry about 403s.

// mmmaybe replace the custom click-to-advance page with a thumbnail page that instead links to the full-size images? less scrolling through meh, less looking at full-size squick, but more clicking and ctrl+w'ing. 

// can I just 'touch' all the pages and force them to load within pixiv's own source? I mean, I'm essentially recreating their page now. 
// I could also just regex document.body.innerHTML for big images. I think the 'small' mode scales them instead of loading some smaller file. 
// <script>pixiv.context.images[1] = 'http://i2.pixiv.net/img108/img/ukaban/29548141_p1.jpg';pixiv.context.thumbnailImages[1] = 'http://i2.pixiv.net/img108/img/ukaban/mobile/29548141_128x128_p1.jpg';</script></div><div class="item-container"><script>pixiv.context.pages[1] = [2];</script><a href="/member_illust.php?mode=manga_big&amp;illust_id=29548141&amp;page=1" target="_blank" class="full-size-container ui-tooltip" data-tooltip="オリジナルサイズを表示"><i class="_icon sprites-full-size"></i></a><img src="http://source.pixiv.net/www/images/common/transparent.gif" class="image ui-scroll-view" data-filter="manga-image" data-src="http://i2.pixiv.net/img108/img/ukaban/29548141_p1.jpg" data-index="1">

// With 'data-filter="manga-image"' I could potentially loop through, grab every image without determining total page count, and then add _big to each one individually. 
	// Dunno if that's desirable. Looping introduces the potential for infinite loops, while here, we just look for two things. 
	// Are two-pages-at-once mangas still broken? If not, don't. 

// Images could be scaled to "height=100%", and apparently that means window height and not the original height of the image. JS is fuckin' weird. Leaning toward "no" for the sake of tall comics. Width=100% for super-large images sounds good, though. 








var html_dump = document.getElementsByTagName('html')[0].innerHTML;		// read full page HTML as string - admittedly overkill, but it's kilobytes, so who really cares? (Could be a reference if it matters.) 

var new_html = "";
var thumbnail_html = "";

	// All images here use the same base URL, so grab that and we'll append p0, p1, p2, etc. later
var image_url = html_dump.substring( html_dump.indexOf( 'data-filter="manga-image"' ) );		// skip to where the first page is defined
image_url = image_url.substring( image_url.indexOf( "http:" ) );		// grab that image's URL
image_url = image_url.substring( 0, image_url.indexOf( '"' ) ); 		// (doublequote inside singlequotes) 
image_url = image_url.replace( '_p0', '_p' ); 		// remove page number so we can add our own later
// e.g. http://i2.pixiv.net/img06/img/nekopuchi/33798018_p0.jpg

	// Figure out how many pages there are, based on the page text
var page_count = html_dump.substring( html_dump.indexOf( '<span class="total">' ) );		// skip to where the page declares itself a manga submission
page_count = page_count.substring( page_count.indexOf( ">" )+1, page_count.indexOf( "</" ) );		// extract the latter number from where the page reads e.g. "2 / 2"
page_count = parseInt( page_count );		// cast as integer 

	// Build a simplified version of the manga page, using high-res images. Clicking an image jumps to the next one. (Keyboard controls not implemented.) 
for( var page_number = 0; page_number < page_count; page_number++ ) {
	var page_url = image_url.replace( "_p", "_big_p" + page_number ); 		// We'll assume "big" pages exist for every image, then fix it if we're wrong. 

		// Display thumbnails for an overview of this manga's contents (and easy links to each page) 
	thumbnail_html = thumbnail_html + "<a href='#" + page_number + "'>";		// link thumbnail to the relevant page anchor
	thumbnail_html = thumbnail_html + "<img src='" + page_url + "' height='100' width='auto' onerror='this.src = this.src.replace(\"_big_p\", \"_p\");'></a> ";
		// display thumbnail at fixed height - browser should maintain aspect ratio
		// onError function replaces "big" page with normal-size page, if "big" page turns out not to exist. 

		// Display pages centered, each linked to the next, kind of like Pixiv does
	new_html = new_html + "<a id='" + page_number + "'>"; 		// Anchor for thumbnails and previous page to link to
	new_html = new_html + "<a href='#" + (1.0+page_number) + "'>"; 		// Link this image to the next image's anchor
	new_html = new_html + "<img src='" + page_url + "' onerror='this.src = this.src.replace(\"_big_p\", \"_p\");getElementById(\""+page_number+"link\").href=this.src;'></a></br>";
		// onError function replaces "big" page with normal, but also finds the image link by its ID and makes it link to the correct source image. Sorry this is a clusterfuck. 
	new_html = new_html + "<a id='" + page_number + "link' href='" + page_url + "'>Image link</a>"; 		// Link to the image, so it's easy to open a particular page in tabs
	new_html = new_html + "<br><br>"; 
}

	// Replace page with our custom HTML. 
new_html = new_html + "<br><br><br><a id = '" + page_count + "'></a>";		// add one last anchor tag, so clicking the last image brings you to the end of the page 
new_html = thumbnail_html + "<center><br><br><br>" + new_html;		// thumbnails first, then main images
document.body.innerHTML = new_html;		// replace the HTML body with new_html, which should now contain a long list of <img>s that load in a sensible manner