Created
February 15, 2016 14:17
-
-
Save Saoneth/3030fee25c6a6d9c098a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bato.to Preload | |
// @namespace http://saoneth.pl/ | |
// @version 0.1 | |
// @description All pages on one site | |
// @author Saoneth | |
// @match http://bato.to/reader | |
// @grant none | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
var k = function(e) { | |
console.log(this.width); | |
var canvas = document.createElement('canvas'); | |
canvas.width = this.width; | |
canvas.height = this.height; | |
var ctx = canvas.getContext('2d'); | |
ctx.drawImage(this, 0, 0); | |
var w = canvas.width, | |
h = canvas.height, | |
pix = {x:[], y:[]}, | |
imageData = ctx.getImageData(0,0,canvas.width,canvas.height), | |
x, y, index; | |
for (y = 0; y < h; y++) { | |
for (x = 0; x < w; x++) { | |
index = (y * w + x) * 4; | |
if (imageData.data[index+3] > 0) { | |
pix.x.push(x); | |
pix.y.push(y); | |
} | |
} | |
} | |
pix.x.sort(function(a,b){return a-b;}); | |
pix.y.sort(function(a,b){return a-b;}); | |
var n = pix.x.length-1; | |
w = pix.x[n] - pix.x[0]; | |
h = pix.y[n] - pix.y[0]; | |
var cut = ctx.getImageData(pix.x[0], pix.y[0], w, h); | |
canvas.width = w; | |
canvas.height = h; | |
ctx.putImageData(cut, 0, 0); | |
var image = canvas.toDataURL(); | |
var win = window.open(image, '_blank'); | |
win.focus(); | |
}; | |
var img = []; | |
var w = function(e) { | |
e.preventDefault(); | |
this.style.maxWidth = this.style.maxWidth=='100%'?'':'100%'; | |
}; | |
var g = function(id, p) { | |
jQuery.get('http://bato.to/areader?id='+id+'&p='+p, function(h) { | |
var d = document.createElement('div'); | |
d.innerHTML = h; | |
if(p == 1) { | |
var c = document.querySelector('#comic_wrap'); | |
c.style.maxWidth = '100%'; | |
c.innerHTML = ''; | |
var pages = d.querySelector('#page_select option:last-child').value.split('_')[1]; | |
for(var page=1; page<=pages; page++) { | |
img[page] = new Image(); | |
img[page].style.maxWidth = '100%'; | |
img[page].style.display = 'block'; | |
img[page].style.margin = '0 auto'; | |
img[page].addEventListener('click', w); | |
//img[page].onload = k; | |
c.appendChild(img[page]); | |
} | |
for(var page=3; page<=pages; page+=2) | |
g(id, page); | |
} | |
img[p].src = d.querySelector('#full_image img').src; | |
var s = d.querySelector('script'); | |
img[p+1].src = s.innerText.split('"')[1]; | |
}); | |
}; | |
g(location.hash.substring(1).split('_')[0], 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment