Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Webcomic Reader 2
- // @namespace http://to.do.later
- // @version 0.1
- // @description WIP
- /// @match http://*/*
- // @include http://*.keenspot.com/*
- // @include http://www.interrobangstudios.com/potluck*
- // @include http://satwcomic.com/*
- // @include http://www.twogag.com/*
- // @include http://www.vgcats.com/comics/*
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
- // @copyright 2012+, martixy
- // ==/UserScript==
- (function()
- {
- //Init page images first
- var iterator = -1;
- (function()
- {
- var boo = $("img");
- console.log("There are " + boo.length + " images on this page.");
- iterator = boo.length;
- setTimeout(function() {
- if (iterator > 0)
- {
- console.log("Timed out while waiting for " + iterator + " items.");
- iterator=0;
- }
- }, 5000);
- for(var i=0; i<boo.length; i++)
- {
- if( boo[i].clientWidth == 0 && boo[i].clientHeight == 0)//Register the load events for unloaded images.
- {
- $(boo[i])
- .load( function() {
- iterator--;
- console.log((boo.length - iterator) + " out of " + boo.length + " images loaded");
- console.log("Image: " + this.src + "; Dimensions: " + $(this).width() + "*" + $(this).height());
- })
- .error(function() {
- iterator--;
- console.log("Error loading image " + (boo.length - iterator) + " out of " + boo.length + ", moving on...");
- });
- }
- else
- {
- iterator--;
- console.log((boo.length - iterator) + " out of " + boo.length + " images loaded(no event)");
- console.log("Image: " + boo[i].src + "; Dimensions: " + boo[i].clientWidth + "*" + boo[i].clientHeight);
- }
- }
- })();
- function getLargestImage()
- {
- var max = 0;
- var images = $("img");
- console.log("Images on page:" + images.length);
- var dimensions = 0;
- for(var i=0; i<images.length; i++)
- {
- dimensions = images[i].clientWidth * images[i].clientHeight;
- if(dimensions > (images[max].clientWidth * images[max].clientHeight))
- {
- max = i;
- console.log("New biggest image: " + images[i].src + "[" + images[i].clientWidth + "*" + images[i].clientHeight + "]");
- }
- }
- return images[max];
- }
- //continue... fuck JS
- function getLargestImageCallback(){
- setTimeout(function() { if (iterator != 0) getLargestImageCallback();
- else {
- var LargestImage = getLargestImage();
- $(LargestImage).css('border', '10px solid #FF0000');
- console.log("height:" + LargestImage.clientHeight);
- console.log("width:" + LargestImage.clientWidth);
- function loadNext()
- {
- // =============================
- // ASSUMPTION(May not be true)
- // =============================
- // Get its location, without the file name(the common part of the all locations)
- var imageLocation = LargestImage.outerHTML.match(/src="(.*\/).*?(?:png|jpg|gif)"/i)[1];
- console.log("imageLocation as reported: " + imageLocation);
- // Get the link to the next page
- var next
- $('a').each( function(index) {
- if ($(this).prop("outerHTML").toLowerCase().indexOf("next") >= 0)
- next = $(this);
- });
- console.log(next);
- // AJAX to get next page, and find the image location by the common element in its address
- $.ajax({
- url: next[0].href,
- complete: function(jqXHR, status) {
- console.log("XHR status: " + status);
- //$(getLargestImage()).after('<textarea rows="2" cols="20">' + jqXHR.responseText + '</textarea>');
- var regex = new RegExp("<img.*?src=\"(" + imageLocation + ")(?:.*\.(?:png|jpg|gif)).*?>", "gi");
- var nextImage = regex.exec(jqXHR.responseText);
- console.log("Regex matches: " + nextImage.length);
- console.log("Next Image address: " + $(nextImage[0]).attr('src'));
- LargestImage = $(LargestImage).after(nextImage[0].toString());
- },
- });
- }
- loadNext();
- //=========================================================================
- }
- }, 200); // Fuck JS
- }
- getLargestImageCallback();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement