Eza's Image Glutton

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

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

  1. // ==UserScript==
  2. // @name Eza's Image Glutton
  3. // @namespace https://inkbunny.net/ezalias
  4. // @homepage https://greasyfork.org/en/users/4876-ezalias
  5. // @author Ezalias
  6. // @description Redirects to high-res images on gallery sites, skipping past descriptions and comments
  7. // @license MIT
  8. // @license Public domain / No rights reserved
  9. // @include *://www.furaffinity.net/view/*
  10. // @include *://www.furaffinity.net/full/*
  11. // @include https://inkbunny.net/submissionview.php*
  12. // @include https://inkbunny.net/s/*
  13. // @include http://gelbooru.com/*page=post&s=view*
  14. // @include http://youhate.us/*page=post&s=view*
  15. // @include https://youhate.us/*page=post&s=view*
  16. // @include *://www.gelbooru.com/*s=view*
  17. // @include *://gelbooru.com/*s=view*
  18. // @include *://danbooru.donmai.us/posts/*
  19. // @include *://*.tumblr.com/image/*
  20. // @include /^http(s|)://e(621|926)\.net/post/show*//
  21. // @include *://e621.net/post/show*
  22. // @include *://e926.net/post/show*
  23. // @include *://*.deviantart.com/art/*
  24. // @include *://*.deviantart.com/*/art/*
  25. // @include /^https?://w*\.*hentai-foundry\.com/pictures/user/.*/[0-9]*/.*/
  26. // @include /^https*://www\.sofurry\.com/view/*//
  27. // @include https://www.weasyl.com/*
  28. // @include http://www.y-gallery.net/view/*
  29. // @include *://rule34.paheal.net/post/view/*
  30. // @include *://rule34.xxx/index.php?page=post*
  31. // @include *://rule34hentai.net/post/view/*
  32. // @include /^https*://derpibooru.org/.*/
  33. // @include *://*.booru.org/*s=view*
  34. // @include *://mspabooru.com/*s=view*
  35. // @include *://safebooru.org/*s=view*
  36. // @include *://www.majhost.com/cgi-bin/gallery.cgi?i=*
  37. // @include *://e-hentai.org/s/*
  38. // @include *://nijie.info/view.php?id=*
  39. // @include *://www.pixiv.net/member_illust.php?mode=medium&illust_id=*
  40. // @include *://www.pixiv.net/jump.php?*
  41. // @include *://www.pixiv.net/*/artworks/*
  42. // @include http://*sleepymaid.com/*
  43. // @include *://*.sankakucomplex.com/post/*
  44. // @include *://*.bronibooru.com/posts/*
  45. // @include *://bronibooru.com/posts/*
  46. // @include *://luscious.net/c/*
  47. // @include *://luscious.net/pictures/c/*
  48. // @include *://imageboard.neko-sentai.com/post/*
  49. // @include *://uberbooru.com/posts/*
  50. // @include *://www.furiffic.com/*/view/*
  51. // @include *://beta.furrynetwork.com/artwork/*
  52. // @include *://hiccears.com/picture.php?pid=*
  53. // @include *://www.hiccears.com/picture.php?pid=*
  54. // @include *://www.jabarchives.com/main/post/*
  55. // @include *://aryion.com/g4/view/*
  56. // @include *://www.newgrounds.com/art/view/*/*
  57. // @include *://lolibooru.moe/post/show/*
  58. // @include *://pbs.twimg.com/media/*
  59. // @include *://gfycat.com/*
  60. // @exclude *://pbs.twimg.com/media/*=orig
  61. // @exclude *://www.deviantart.com/users/outgoing?*
  62. // @exclude *#comment*
  63. // @exclude *#c*
  64. // @exclude *#dnr
  65. // @version 1.31.2
  66. // ==/UserScript==
  67.  
  68.  
  69.  
  70. // 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.
  71. // 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.
  72. // https://greasyfork.org/scripts/4713-eza-s-image-glutton
  73. // https://sleazyfork.org/scripts/4713-eza-s-image-glutton
  74.  
  75.  
  76.  
  77. // Commentary on the UserScript block:
  78. // @exclude #dnr - This string is appened to a URL when redirecting, to prevent back-trapping.
  79. // @exclude http://www.deviantart.com/users/outgoing?* - Archaic misfire prevention; should probably be changed to automatically redirect through.
  80. // @exclude ?comment_id or whatever - Site-specific cases where redirecting to the image is not desirable. E.g. when linked to individuals comments / comment pages. TBD.
  81.  
  82.  
  83.  
  84. // TO DO:
  85. // 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.
  86. // 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.
  87. // flickr? maybe separately. that whole site is a mess. also full-size images are sometimes gigantic, like dozens of megabytes.
  88. // Consider changing some @includes to @match.
  89. // http://thehentaiworld.com/hentai-doujinshi/theres-something-about-sakura-naruto/ ? I already do rule34; there's no pretending this is just about "art."
  90. // Almost deserves a more Pixiv Fixiv-like fix. Maybe just a link dump like that DeviantArt gallery script?
  91. // Greasyfork install page as options page?
  92. // 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.'
  93. // 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.
  94. // Escape function in JS is encodeURI. Also use in Tumblr Scraper, where we need 'safe' URLs as tag IDs.
  95. // FurAffinity stories redirect to thumbnail, e.g. http://www.furaffinity.net/view/15903888/ - might need to break out a whole complex function here.
  96. // http://seiga.nicovideo.jp/seiga/im4507046 ?
  97. // Nijie.info support might be missing out on multipage submissions? I don't even have an account.
  98. // 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.)
  99. // Make undersized images link to themselves on imgur.
  100. // Eza's image glutton as described on http://cuddle.horse/post/109728993805/a-few-browser-extensions-that-make-furaffinity-a -
  101. // Eza’s Image Glutton: This affects websites beyond just FA but is a unique tool for powerbrowsing and such. When you open a page with a single image it skips all comments and descriptions and just shows the image in the highest quality possible. If you want to see all the items that are hidden all you have to do is go back a page.
  102. // good rundown from a third party. 'A page with a single image' is clearer than 'gallery submission page.'
  103. // It's impossible to find this script after Greasyfork fucked over "adult" scripts. SleazyFork does not appear in search engines, at all. The empty GreasyFork page doesn't show up. All that people will see if they don't already know where to go is userscripts-mirror.org, which was last updated in twenty-fucking-twelve. This is completely unacceptable.
  104. // On the other hand, Yahoo also won't find 'greasyfork ezalias,' so what the fuck. Google finds it. Yahoo just sucks.
  105. // Apparently Chrome doesn't redirect properly - there's no 'back' functionality. Grand.
  106. // ... there's back functionality if and only if the page finishes first. Fuck Chrome.
  107. // Fixing what ain't broken - I could "//@include *" and keep the switch-case business, if only to skirt GreasyFork's dumb "adult" rules.
  108. // Ugh, I'd probably be marked "adult" just for mentioning that it works on "adult" sites. Like e621... but not tumblr or pixiv. What even.
  109. // Could also generalize all extract_image_url_after guff to a for-loop over an array of search strings.
  110. // GreasyFork is wise to my bullshit, and specifies that even mentioning adult sites makes the script "adult." Can't even host code without censorship.
  111. // @include * might still be a good idea, because I can check the browser-recognized domain instead of just the URL string.
  112. // Or I guess I could switch by domain anyway.
  113. // @including all sites would mean I need to check per-site URL formats in the switch-case block. E.g. example.com/art/1234 but not example.com/blog/2345.
  114. // The deciding factor is whether JS makes it easy to get domains without subdomain - regexing just to figure out if we're on *.booru.org sucks. www alone would hurt.
  115. // view-source:https://inkbunny.net/submissionview.php?id=1325657 - inkbunny 'friends only' page -
  116. // Finally on Pawoo, let's add that. Ugh - Twitter-style presentation. Gimme a gallery grid.
  117. // Might be more like that Tumblr bare-image resizer, which this script should also mimic. Bare images are linked. Are those max size?
  118. // https://curate.mastodon.art/gallery/media_attachments/files/000/088/717/original/525713c353f7db21.jpg
  119. // https://files.mastodon.social/media_attachments/files/000/963/359/original/ccfa625b17d2e1d0.png
  120. // https://files.mastodon.social/media_attachments/files/000/963/345/original/d23781d67022b95f.png
  121. // Compare:
  122. // https://pawoo.net/media/r89DgtVaqQeydHyPb1g
  123. // https://img.pawoo.net/media_attachments/files/001/246/940/original/b4a22a1ea4433a9f.jpg
  124. // Totally arbitrary, no way to figure one from another. Hmm.
  125. // https://www.hentai-foundry.com/pictures/user/teku/566798/Daisy-Darret-and-Penny#dnr loads an image from the description?
  126. // Fiddled with @includes to consolidate http/https under http*. Seems to work? Might open execution to e.g. http://maliciousdomain.com/?//gelbooru etc.
  127. // Yeah, it's an attack vector worth worrying about. Admittedly the switch case is on document.domain - the attack site would have to end correctly.
  128. // Goddammit, this is possible anyway, since http://*.gelbooru.org matches http://maliciousdomain.com?.gelbooru.org as-is!
  129. // Aaaugh Greasemonkey needs a goddamn domain inclusion method besides string-matching.
  130. // Twitter broke videos - even on mobile. Fuck that, give me the MP4. You can't show me a video and pretend I don't have it.
  131. // <video preload="none" playsinline="" style="width: 100%; height: 100%; position: absolute; transform: rotate(0deg) scale(1);" poster="https://pbs.twimg.com/media/DdFx3A9VAAEEqA9.jpg"><source src="https://video.twimg.com/amplify_video/995698796209225728/pl/qWXZDSRj7npFBnoS.m3u8?tag=2" type="application/x-mpegURL"><source src="https://video.twimg.com/amplify_video/995698796209225728/vid/720x720/hjcLz5e56ojDYS8j.mp4?tag=2" type="video/mp4"></video>
  132. // And here's the "button" that steals clicks:
  133. // <div style="position: relative; width: 100%; height: 100%; background-color: black;"><video preload="none" playsinline="" style="width: 100%; height: 100%; position: absolute; transform: rotate(0deg) scale(1);" poster="https://pbs.twimg.com/media/DdFx3A9VAAEEqA9.jpg"><source src="https://video.twimg.com/amplify_video/995698796209225728/pl/qWXZDSRj7npFBnoS.m3u8?tag=2" type="application/x-mpegURL"><source src="https://video.twimg.com/amplify_video/995698796209225728/vid/720x720/hjcLz5e56ojDYS8j.mp4?tag=2" type="video/mp4"></video></div>
  134. // https://the-collection.booru.org/index.php?page=post&s=view&id=74939 ?
  135. // https://thehentaiworld.com/hentai-images/asami-and-korra-sunsetriders7-the-legend-of-korra/ ?
  136. // Twitter: auto-click click-to-view nonsense?
  137. // Image Glutton: https://yande.re/post/show?md5=936f8ff6b34aacd80fa0038505b0c61a
  138. // Oh, and Tumblr lost their goddamn minds following the Great Purge. What the fuck is a PNJ? GifV is not a real format. You embed WebMs for lossless sprite work? Whaaat?
  139. // https://baraag.net/@conoghi/101982558283665128
  140. // Not on multi-image submissions like https://baraag.net/@conoghi/102022419532733468 1
  141. // Oh my god I might already have a newgrounds account. What year would that be? 2003? Yahoo.com e-mail address? Well before Gmail. Possibly AOL.
  142. // PB went to a "dellnet" e-mail, so that's not me. Sorry, rando. Welcome to my special hell. No account for my yahoo name. Nevermind, guess I never signed up.
  143. // Nijie support is broken and someone finally noticed. I guess I'll do it properly.
  144. // Should I extend Pixiv Fixiv support to Nijie? The initial motivation was Pixiv's awful lazy-loading. Nijie is high-quality, high-res, and low-nonsense.
  145. // At least consider inserting some direct image links on Nijie. Maybe below each image for accessibility... maybe invisible, for DownThemAll.
  146. // Oh, split the difference: add thumbnails to the top of the page. (Would they link to the image files, or #diff_n? Bluh.)
  147. // https://nijie.info/view.php?id=232449 - what is this nonsense? A single-image multi-image post? Fuck off, Nijie.
  148. // Apparently it has multiple pages, but the second one is "guro" - so it doesn't link it? Qua?
  149. // You know, since I check document.domain and silently fail on unknown domains, I could probably change @includes to *// instead of http/https.
  150. // First check if address_bar_contains can safely be reconfigured to domain_name_contains. We want to prevent maliciousexample.com/?.tumblr.com crap.
  151. // @include /^https*://www\.furaffinity\.net/(view|full)/.*/
  152. // One reason not to do this (or not to keep it) is if it breaks GreasyFork's domain detection.
  153. // Listing the filters instead of plain domain names is fine - but people can browse by domain. This won't show up on 'scripts for Pixiv' without detecting pixiv.com.
  154. // I probably can't know whether this "works" until I upload a version with these @includes. Bluh.
  155. // Should probably replace all indexOf > -1 stuff with match.
  156. // Twitter: https://pbs.twimg.com/media/D_iookgXkAA0eCM?format=jpg&name=small:orig.jpg infinitely loops.
  157. // Ah goddammit they might have broken everything in their shitty redesign.
  158. // https://pbs.twimg.com/media/D_iookgXkAA0eCM?format=jpg&name=small
  159. // https://pbs.twimg.com/media/D_iookgXkAA0eCM?format=jpg&name=orig
  160. // GfyCat might already have broken.
  161. // Double-check that Weasyl and SoFurry actually work.
  162.  
  163. // 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.
  164.  
  165. // Owyn Tyler has a ridiculously replete script with similar goals called Handy Just Image - http://userscripts.org/scripts/show/166494
  166. // The supported-site list is waaay longer than mine, and/but his goals are more complex. Image Glutton exists only to deliver the image.
  167. // 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.
  168.  
  169. // Changes since last upload:
  170. // Excluded #c instead of / in addition to full #comment - e.g. for Paheal. This one might not make it to production.
  171. // Fixed Pixiv yet again, this time by ignoring the page and grabbing JSON directly.
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. // global variables, for simplicity
  181. var image_url = ''; // location of the full-size image to redirect to
  182. var wait_for_dnr = false; // some site URLs use "#" liberally, so if this var isn't empty, only "#dnr" will stop a redirect
  183. var simple_redirect = false; // some domains are kicking back my JS redirect (for native referral), so do naive location=url instead
  184. var page_failed = false; // If the page 503s or otherwise forces us to reload, wait a moment, then reload.
  185. var interval_handle; // In case we need to set an interval, this is the global handle to kill it. Because a simple "die" or "clearInterval( this )" would be too much to ask.
  186. var assume_extension = true; // Most sites should obviously point to an image, so if there's no file extension, guess ".jpg". This breaks DeviantArt.
  187.  
  188. // detect site, extract image URL, then decide whether or not to redirect
  189. switch( document.domain.replace( 'www.', '' ) ) { // Remove "www" to avoid cases where both example.com and www.example.com are supported.
  190. ////////// Simple extract_image_url_after sites
  191. case 'e621.net': image_url = document.getElementById( 'highres' ).href; break;
  192. case 'e926.net': image_url = document.getElementById( 'highres' ).href; break;
  193. case 'weasyl.com': extract_image_url_after( '<div id="detail-art">', '/' ); break; // also redirects to plaintext/HTML on stories, haha
  194. case 'y-gallery.net':
  195. extract_image_url_after( 'id="idPreviewImage"', 'http://' );
  196. break; // Fucked, but they say they're coming back eventually
  197. case 'rule34.xxx': extract_image_url_after( '>Edit</a></li>', '//' ); break;
  198. case 'derpibooru.org': extract_image_url_after( ' View</a>', '//' ); simple_redirect = true; break;
  199. case 'chan.sankakucomplex.com': extract_image_url_after( '<li>Original:', '//' ); image_url = image_url.replace( '&amp;', '&' ); break;
  200. case 'idol.sankakucomplex.com': extract_image_url_after( '<li>Original:', '//' ); image_url = image_url.replace( '&amp;', '&' ); break;
  201. case 'furiffic.com': extract_image_url_after( 'onload="$', '//' ); break; // Not using og:image because different URL causes image to re-load is user hits Back
  202. case 'jabarchives.com': extract_image_url_after( 'class="group1"', '/main' ); break;
  203. case 'gfycat.com': extract_image_url_after( 'og:video', '//' ); break;
  204. ////////// Slightly complicated extract_image_url_after sites
  205. case 'rule34hentai.net': extract_image_url_after( 'shm-zoomer', '/_images/' ); wait_for_dnr = true; reload_if( '<h2>Rate limit hit' ); break; // wtf? even 'view image' returns text nonsense. images save fine. I bet the site's lying about the mime type. google's not helping for other answers, and I can't fix that, so 'meh' for now. sorry.
  206. case 'rule34.paheal.net': extract_image_url_after( 'Links</th>', 'http' ); wait_for_dnr = true; reload_if( '<h1>429 Too Many Requests' ); break;
  207. case 'majhost.com': image_url = document.getElementsByTagName( "img" )[0].src; break; // first and only <img> tag
  208. case 'luscious.net': image_url = document.getElementsByClassName( 'icon-download' )[0].href; wait_for_dnr = true; break;
  209. case 'gelbooru.com': extract_image_url_after( "og:image", '//' ); simple_redirect = true; break;
  210. case 'youhate.us': extract_image_url_after( "og:image", '//' ); simple_redirect = true; break;
  211. case 'aryion.com': extract_image_url_after( "item-box", '//' ); image_url = image_url.split("'")[0]; simple_redirect = true; break; // Singlequote terminator
  212. case 'newgrounds.com': extract_image_url_after( 'full_image_text', '\\/\\/' ); image_url = image_url.split('\\').join(''); simple_redirect = true; break; // Un-escape URL
  213. ////////// Simple custom sites
  214. case 'sofurry.com':
  215. image_url = window.location.href.replace('sofurry.com/view/','sofurryfiles.com/std/content?page=');
  216. if( document.body.outerHTML.indexOf( '<div id="sfContentImage' ) < 0 ) { image_url = ''; } // Do not redirect from stories
  217. if( document.body.outerHTML.indexOf( '<div class="sf-story"' ) > 0 ) { image_url = ''; } // Really do not redirect from stories
  218. break;
  219. case 'danbooru.donmai.us':
  220. extract_image_url_after( '% of original (', '/data/' ); // resized images will say "X% of original (view full)" or something like that
  221. if( image_url === '' ) { image_url = document.getElementById( "image" ).src; } // IMG and VIDEO both use SRC. Thank god.
  222. break;
  223. case 'furaffinity.net': // This is a mess because I'm trying not to redirect from stories / music... but FA kindly links the thumbnail images for those.
  224. reload_if( 'center;">Error 503' );
  225. extract_image_url_after( '<div class="alt1 actions', '//' ); // Works even when not signed in
  226. // Choosing not to redirect based on content type is impossible because FA's tags and categories are a complete joke. Nothing is reliable.
  227. if( document.getElementsByTagName('html')[0].innerHTML.indexOf('/themes/beta') > -1 ) { // Total kludge. If beta theme, use full-url, audio files be damned.
  228. image_url = unsafeWindow.full_url;
  229. }
  230. break;
  231. case 'e-hentai.org': image_url = document.getElementById( 'img' ).src; break;
  232. case 'nijie.info':
  233. reload_if( 'title>429' );
  234. extract_image_url_after( '"thumbnailUrl":', 'http' ); // E.g. https://pic01.nijie.info/__rs_l160x160/nijie_picture/530703_20190520024721_0.jpg
  235. let url_parts = image_url.split( '/' ); // Can't chain these because splice returns the spliced element instead of the array minus that element.
  236. url_parts.splice( 3,1 );
  237. image_url = url_parts.join( '/' ); // E.g. https://pic01.nijie.info/nijie_picture/530703_20190520024721_0.jpg
  238. if( document.body.outerHTML.indexOf( '#diff_' ) > 0 ) { image_url = window.location.href.replace( 'view.php', 'view_popup.php' ); } // Multi-page view, not single image.
  239. // I probably want to insert links to the individual images, on the view_popup page.
  240. break;
  241. case 'sleepymaid.com':
  242. case 'yay.sleepymaid.com':
  243. image_url = document.getElementById( 'the-image' ).src;
  244. if( document.getElementById( 'next' ) ) { image_url = ''; } // Don't redirect on comic pages
  245. break;
  246. case 'imageboard.neko-sentai.com': image_url = document.getElementById( 'main_image' ).src; break;
  247. case 'uberbooru.com':
  248. extract_image_url_after( 'Size: <a', '/data' );
  249. if( image_url.indexOf( '<' ) > -1 ) { image_url = ''; } // Uberbooru is having back-end problems with missing images. Don't redirect if we grabbed HTML instead.
  250. break;
  251. case 'hiccears.com': extract_image_url_after( 'href="./upl0ads', './' ); break; // Wow, long garbage names. Can we use Download titles? Apparently not.
  252. case 'hentai-foundry.com':
  253. extract_image_url_after( ' ', '//pictures.' );
  254. if( image_url.indexOf( "';" ) > 0 ) { image_url = image_url.substring( 0, image_url.indexOf( "';" ) ) } // Singlequote terminate, more or less - only on resizable images
  255. reload_if( '<h1>An error occurred.' );
  256. break;
  257. case 'pbs.twimg.com':
  258. // image_url = window.location.href.split( ':' )[1] + ':orig'; // Remove e.g. ':large' if present, add ':orig'. Casually removes http: / https: but works anyway.
  259. image_url = window.location.href.split( '&' ).filter( s => ! s.match( 'name=' ) ).join( '&' ) + '&name=orig';
  260. assume_extension = false;
  261. break;
  262. case 'lolibooru.moe': image_url = document.getElementById( 'highres' ).href; break;
  263. ////////// Sites complex enough to shove into a function down below
  264. case 'inkbunny.net': scrape_inkbunny(); break;
  265. case 'pixiv.net': scrape_pixiv(); break;
  266. case 'mspabooru.com': scrape_booru(); break;
  267. case 'safebooru.org': scrape_booru(); break;
  268. case 'bronibooru.com': scrape_booru(); break;
  269. }
  270. ////////// Holdovers from the previous method; domains that don't neatly conform to document.domain switch selection.
  271. if( document.domain.match( 'tumblr.com' ) ) { extract_image_url_after( '"og:image"', 'http' ); simple_redirect = true; }
  272. if( document.domain.match( 'deviantart.com' ) ) { scrape_deviantart(); wait_for_dnr = true; }
  273. if( document.domain.match( '.booru.org' ) ) { scrape_booru(); }
  274. if( document.domain.match( 'beta.furrynetwork.com' ) ) { interval_handle = setInterval( scrape_furrynetwork, 500 ); } // This site's designers are loons.
  275.  
  276.  
  277.  
  278. // If the page didn't load properly, but could be fixed by reloading, then wait a moment and reload
  279. if( page_failed ) { // If we get a 503 or other 'please reload' error
  280. image_url = ''; // do not redirect this time
  281. 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.
  282. }
  283.  
  284.  
  285.  
  286. // Don't redirect if the filetype is obviously not an image. SWF, TXT, MP3, etc.
  287. // It's tedious to detect flash, story, and music pages on every website supported, so instead let's just cancel redirection based on those file extensions.
  288. // Added ZIP & RAR because apparently DeviantArt lets you host 3D models and stuff. Automatically downloading those is not what this script is for.
  289. var ext = image_url.substring( image_url.lastIndexOf( '.' ) + 1, image_url.length ); // e.g. "png"
  290. var not_images = [ 'mp3', 'swf', 'txt', 'docx', 'pdf', 'doc', 'rtf', 'midi', 'mid', 'wav', 'flv', 'cab', 'zip', 'rar' ];
  291. for( var n in not_images ) { if( ext == not_images[n] ) { image_url = ''; } } // If the extension is in our blacklist, don't redirect.
  292. // Oh right. Doesn't work on FA because FA points to the icon. Yaaayfuck.
  293.  
  294. redirect(); // Slightly clunky way to trigger this from website-specific functions. "Don't repeat yourself." Execution continues:
  295.  
  296. function redirect() {
  297. // Having defined image_url based on the page's HTML or DOM, modify the current URL to prevent back-traps, then redirect to that full image.
  298. var do_we_redirect = true; // If we've come this far we'll probably go to an image.
  299. if( image_url == '' ) { do_we_redirect = false; } // Don't redirect to an empty string. (Emptying this string is how some functions fail safe.)
  300. if( !wait_for_dnr && window.location.href.match( '#' ) ) { do_we_redirect = false; } // Don't redirect if the wait_for_dnr flag is false and there's a hash. (E.g. FA comments.)
  301. if( window.location.href.match( '#dnr' ) ) { do_we_redirect = false; } // Don't redirect if there's a #dnr in the URL.
  302. if( do_we_redirect == true ) // So much clearer than a mess of &&s and ||s.
  303. {
  304. // some images don't redirect properly, even if you manually "view image" - so we append ".jpg" to URLs without extensions, forcing the browser to consider them images
  305. // even if this doesn't work, the new URL should just 404, which is better than the semi-modal "octet stream" dialog seen otherwise.
  306. if( assume_extension ) {
  307. 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
  308. 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
  309. }
  310.  
  311. // modify current location, so that when the user clicks "back," they aren't immediately sent forward again
  312. modified_url = window.location.href + '#dnr'; // add do-not-redirect tag to current URL
  313. history.replaceState( {foo:'bar'}, 'Do-not-redirect version', modified_url ); // modify URL without redirecting. {foo:'bar'} is a meaningless but necessary state object.
  314.  
  315. image_url = encodeURI( image_url ); // Executing code with strings from the page has always been a mildly horrifying attack surface - hopefully this defangs it.
  316. if( simple_redirect ) { window.location.href = image_url; } // This has different referral properties than clicking a link or displaying an image, so some sites 403
  317. else { location.assign("javascript:window.location.href=\""+image_url+"\";"); } // Pixiv-friendly redirect to full image: maintains referral, happens within document's scope.
  318. }
  319. } // end of main execution
  320.  
  321.  
  322.  
  323.  
  324.  
  325. // ----- // Functions for readability
  326.  
  327.  
  328.  
  329.  
  330.  
  331. 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
  332. var html_elements = document.getElementsByTagName('html'); // this avoids doing getElementsEtc every time, while accessing the whole page HTML by reference
  333. var string_index = html_elements[0].innerHTML.indexOf( string_before_url ); // find a unique string somewhere before the image URL
  334.  
  335. if( string_index > -1 ) {
  336. var image_index = html_elements[0].innerHTML.indexOf( url_begins_with, string_index ); // find where the image URL starts after the unique string
  337. var delimiter_index = html_elements[0].innerHTML.indexOf( '"', image_index ); // find first doublequote after the image URL starts
  338. image_url = html_elements[0].innerHTML.substring( image_index, delimiter_index ); // grab the image URL up to the next doublequote
  339. }
  340. // return image_url; // Debug
  341. }
  342.  
  343. function reload_if( error_string ) {
  344. var html_elements = document.getElementsByTagName('html'); // avoid doing getElementsEtc every time, while still accessing the whole page's HTML by reference
  345. var string_index = html_elements[0].innerHTML.indexOf( error_string ); // look for a string indicating the page failed to load
  346. if( string_index > -1 ) { page_failed = true; }
  347. }
  348.  
  349.  
  350.  
  351.  
  352.  
  353. // ----- // Functions for individual websites (separated for being especially long)
  354.  
  355.  
  356.  
  357.  
  358.  
  359. // 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.
  360. // This used to be horrible, then it was simple, then it was horrible again. Images have some ridiculous "token," without which they 404, 401, or simply hang.
  361. // I hate this website.
  362. function scrape_deviantart() {
  363. // extract_image_url_after( 'dev-view-main-content">', '//' ); // Get main image
  364. // image_url = image_url.split( '/v1/' )[0]; // Should ditch any resizing directions in the URL.
  365. setInterval( function() {
  366. extract_image_url_after( 'class="dev-content-normal', '//' ); // Get large-size image with correct token, once it appears
  367. if( image_url != '' ) { redirect(); }
  368. }, 300 ); // Several times a second sounds reasonable. This shouldn't trigger at all when you navigate back.
  369. }
  370.  
  371. function scrape_inkbunny() {
  372. var image_index = document.body.outerHTML.indexOf( 'files/screen/' ); // Find the middle of a screen-sized image URL
  373. image_index = document.body.outerHTML.lastIndexOf( 'https://', image_index ); // ... then back up to the start of it
  374. if( image_index !== -1 ) // if that URL is found
  375. {
  376. var delimiter_index = document.body.outerHTML.indexOf( '"', image_index ); // find first doublequote delimiter after URL
  377. image_url = document.body.outerHTML.substring( image_index, delimiter_index ); // grab delimited URL
  378. 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
  379. }
  380. wait_for_dnr = true;
  381.  
  382. // if this page is the landing page for a multi-image submission, do not redirect
  383. // Look for 'show custom thumbnails' button (indicating multi-page submission) or #pictop (which doesn't appear on landing pages for multi-page submissions)
  384. if ( document.body.outerHTML.indexOf( '<form id="changethumboriginal_form"' ) !== -1 && !window.location.href.match( '#pictop' ) ) {
  385. image_url = ''; // note: we do redirect on URLs for individual pages, including the first.
  386. }
  387. }
  388.  
  389. // Furrynetwork is a joke because every single page has the same HTML. We have to use the DOM, but on an unknown delay, because these fools were too clever to just deliver a goddamn document.
  390. function scrape_furrynetwork() {
  391. let link_list = Array.from( document.getElementsByClassName( 't--reset-link' ) );
  392. if( link_list.length > 0 ) {
  393. clearInterval( interval_handle ); // Once we detect something - anything - stop looping.
  394. image_url = link_list[0].href; // Safely handling an HTMLcollection, because Javascript is pain.
  395. if( image_url !== window.location.href ) {
  396. // Fuck it, copy-paste for now. This can't just 'return' because it's faux-parallel.
  397. let modified_url = window.location.href + '#dnr'; // add do-not-redirect tag to current URL
  398. history.replaceState( {foo:'bar'}, 'Do-not-redirect version', modified_url ); // modify URL without redirecting.
  399. window.location.href = image_url;
  400. }
  401. }
  402. }
  403.  
  404. // Miraculously, Ugoira stuff still works.
  405. function scrape_pixiv() {
  406. // If this is a redirect page, just fucking redirect. Test case:
  407. // https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72946956#dnr
  408. if( window.location.href.match( 'jump.php?' ) ) {
  409. extract_image_url_after( 'noopener noreferrer', 'http' );
  410. simple_redirect = true;
  411. assume_extension = false;
  412. return; // Skip all this other stuff
  413. }
  414.  
  415. // How does the non-simple redirect manage to put the code into the address but but then not work? The page displays the URL as text.
  416. // But if you highlight the address bar and hit enter, it actually goes to that URL, like on any other dang website.
  417. // I want some variation on history.replaceState that forces us to -go- to the same page. Maybe push to 'forward' and then 'go forward.'
  418.  
  419. let submission = window.location.href.split( '/' ).pop().split( '#' )[0]; // E.g. https://www.pixiv.net/en/artworks/12345#etc -> 12345
  420. fetch( 'https://www.pixiv.net/ajax/illust/' + submission, { credentials: 'include' } ).then( response => response.text() ).then( text => {
  421. // Thanks again to Pixiv Plus for identifying the relevant JSON at a predictable URL.
  422. pixiv_data = JSON.parse( text ).body; // There's probably more direct way to 'JSON.parse( url )'. It's why JSON exists.
  423. image_url = pixiv_data.urls.original;
  424. if( pixiv_data.pageCount > 1 ) { image_url = ''; } // Don't redirect to a single image if this is a multi-image "manga" submission.
  425.  
  426. // Bringing back Ugoira / Ugoku animation links in the absence of the pixiv.context object required cleverness, research, and then giving up and reading Pixiv Plus's source.
  427. // So thanks and kudos to those guys for finding a page JSON file that points to an ugoira JSON file that names a URL that's basically just the image URL plus "ugoira."
  428. // E.g. '/ajax/illust/65423021' and 'ajax/illust/65423021/ugoira_meta' are the JSON for id=65423021. The latter names several ZIP files.
  429. // So basically this takes
  430. // https://i.pximg.net/img-original/img/2017/10/14/06/24/30/65423021_ugoira0.jpg and outputs
  431. // https://i.pximg.net/img-zip-ugoira/img/2017/10/14/06/24/30/65423021_ugoira1920x1080.zip then links to that instead of redirecting.
  432. // I don't actually know if all sizes are universal. 600x600 seems to be the baseline. Do they ever top 1920x1080?
  433. // See if globalInitData contains any ugoira information. (Doesn't appear so.)
  434. if( image_url.indexOf( 'ugoira' ) > -1 ) {
  435. var animation_url = image_url.split( 'ugoira0' )[0]; // E.g. 65423021_ugoira0.jpg -> 65423021_
  436. animation_url = animation_url + 'ugoira1920x1080.zip'; // E.g. 65423021_ -> 65423021_ugoira1920x1080.zip
  437. animation_url = animation_url.replace( 'img-original', 'img-zip-ugoira' ); // Middle bit in the URL. Same server, different directory.
  438. animation_url = animation_url.split( '\\' ).join( '' ); // Remove all escaping backlashes. Should be decodeURI, but that sometimes leaves a trailing backslash.
  439.  
  440. var download_string = '<a style="text-decoration:none" href="' + animation_url + '">Download Ugoira animation frames (.zip)</a>';
  441. // Can I give this a class such that it matches the original appearance? Pixiv is such a mess.
  442.  
  443. // All this frustrating bullshit just to insert a link:
  444. var download_interval = setInterval( function() {
  445. // Repeatedly check until the clientside nonsense page generates its "figcaption" element
  446. if( document.getElementsByTagName( 'figcaption' ) && !document.getElementById( 'download_link' ) ) {
  447. var temp_html = document.getElementsByTagName( 'figcaption' )[0].innerHTML;
  448.  
  449. // Complete jank: insert the download link, as a string, immediately following the h1 tag.
  450. // Would be "more correct" to do this with string.slice.
  451. // I don't know where those commas come from.
  452. var split_html = temp_html.split( '</h1>' );
  453. split_html.splice( 1, 0, '</h1>' + download_string ); // Surprise, this operation has a side effect instead of returning a string. Aristocrats.js.
  454. document.getElementsByTagName( 'figcaption' )[0].innerHTML = split_html.join();
  455. clearInterval( download_interval ); // Can I clear the interval variable, from inside the interval? Is JS that friendly about sloppy global variables? Apparently so!
  456. }
  457. }, 1000 )
  458. image_url = ''; // Don't redirect on animated images.
  459. }
  460.  
  461. redirect(); // We have to do this manually now, since we're in a callback.
  462. } )
  463. }
  464.  
  465. // Maybe clean this up now that Gelbooru's stupid shit gets its own function.
  466. function scrape_booru() { // this works on a wide variety of booru-style imageboards.
  467. extract_image_url_after( '>Resize image</a>', 'http://' ); // for booru's which have automatic resizing and images which require it
  468. // Gelbooru's anti-adblock shit might make the script fail the FIRST time you load a page, but not subsequent times. God dammit.
  469. // Might be time for Gelbooru to get its own scrape function, because god damn.
  470. extract_image_url_after( "$('edit_form')", '//' ); // For booru's with automatic resizing on, use the Original Image link, which appears after the Edit button
  471. if( image_url === '' ) { extract_image_url_after( "$('resized_notice')", '//' ); } // Hey guess what! Gelbooru now serves different sidebars for adblock. Fuck you!
  472. if( image_url === '' ) { extract_image_url_after( 'class="showEditBox">', '//' ); } // Hey guess what!!! Gelbooru now just tells you not to adblock! Fuuuck youuu!
  473. if( image_url === '' ) { // otherwise, use the image that's being displayed
  474. var container = document.getElementById( 'image' ); // Instead of lurching through raw HTML, let's just grab the display image via the DOM.
  475. image_url = container.src; // "You think it's cool that things don't always have to be a federal fucking issue."
  476. }
  477. }
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485. /*
  486. Test suite of random URLs from the relevant sites:
  487. http://www.hentai-foundry.com/pictures/user/Bottlesoldier/133840/Akibabuse
  488. http://www.hentai-foundry.com/pictures/user/Bottlesoldier/214533/Lil-Gwendolyn
  489. https://inkbunny.net/submissionview.php?id=483550
  490. https://inkbunny.net/submissionview.php?id=374519
  491. http://rule34.xxx/index.php?page=post&s=view&id=1399731
  492. http://rule34.xxx/index.php?page=post&s=view&id=1415193
  493. http://equi.booru.org/index.php?page=post&s=view&id=56940
  494. http://furry.booru.org/index.php?page=post&s=view&id=340299
  495. http://derpibooru.org/470074?scope=scpe80a78d33e96a29ea172a0d93e6e90b47c6a431ea
  496. http://mspabooru.com/index.php?page=post&s=view&id=131809
  497. http://mspabooru.com/index.php?page=post&s=view&id=131804
  498. http://shiniez.deviantart.com/art/thanx-for-5-m-alan-in-some-heavy-makeup-XD-413414430
  499. http://danbooru.donmai.us/posts/1250724?tags=dennou_coil
  500. http://danbooru.donmai.us/posts/1162284?tags=dennou_coildata:text/html,<img src='http://example.com/image.jpg'>
  501. http://www.furaffinity.net/view/12077223/
  502. http://gamesbynick.tumblr.com/post/67039820534/the-secrets-out-guys-the-secret-is-out
  503. http://honeyclop.tumblr.com/post/67122645946/stallion-foursome-commission-for-ciderbarrel-d
  504. http://shubbabang.tumblr.com/post/20990300285/new-headcanon-karkat-is-ridiculously-good-at
  505.  
  506. http://www.furaffinity.net/view/12092394/
  507. https://e621.net/post/show?md5=25385d2349ae11f2057874f0479422ad
  508. http://sandralvv.tumblr.com/post/64933897836/how-did-varrick-get-that-film-cuz-i-want-a-copy
  509. */