-
-
Save PudiccaA/3f6f5c1eb4b28d8dc1b4cba0a634ccab 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 EBookJapanRipper | |
// @version 1.10 | |
// @downloadURL https://gist.githubusercontent.com/chocolatkey/ad0c04b0768f5fcdd3ea3c6cb089b8b2/raw | |
// @supportURL https://gist.github.com/chocolatkey/ad0c04b0768f5fcdd3ea3c6cb089b8b2 | |
// @description Send my regards to "t-hamaguchi" lol | |
// @author chocolatkey | |
// @homepage https:/github.com/chocolatkey | |
// @include http://*br.ebookjapan.jp* | |
// @include https://*br.ebookjapan.jp* | |
// @run-at document-start | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js | |
// @require https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.min.js | |
// ==/UserScript== | |
var min = 1; | |
var max = 0; | |
(function (unsafeWindow) { | |
var already = false; | |
$( document ).ready(function() { | |
console.log( "Ripper available" ); | |
}); | |
$(document).on("keydown", function(e) { | |
if((e.shiftKey && e.keyCode == 68) && !already) | |
{ | |
console.log( "Ripper shown" ); | |
already = true; | |
max = BR_slider.maxNum + 1; | |
$( "#viewArea" ).append( "\ | |
<div style='position: fixed; top: 5px; right: 5px; width: 150px; height: auto; background: #e2e2e2; padding: 5px; z-index: 999;'>\ | |
<center><b><h3 id='ebjrp-title'>==== Ripper ====</h3></b></center>\ | |
<button id='ebjrp-start' style='width: 150px;'>Rip!</button><br>\ | |
First:<input type='number' id='eb1' style='width: 40px;' name='quantity' min='1' max='" + (BR_slider.maxNum + 1) + "' value='1'> \ | |
Last:<input type='number' id='eb2' style='width: 40px;' name='quantity' min='1' max='" + (BR_slider.maxNum + 1) + "' value='" + (BR_slider.maxNum + 1) + "'>\ | |
</div>\ | |
" ); | |
$( "#eb1" ).change(function() { | |
min = $(this).val(); | |
}); | |
$( "#eb2" ).change(function() { | |
max = $(this).val(); | |
}); | |
$( "#ebjrp-start" ).click(function() { | |
console.log( "Rippin' " + min + "-" + max); | |
$("#ebjrp-title").html("<i>This may take a while...</i>"); | |
for (i = (min-1); i <= (max-1); i++) { | |
worker(i); | |
} | |
}); | |
} | |
}); | |
function worker(i) { | |
__get_image(i, function(c) { | |
console.log("p" + i + " ready"); | |
$("#ebjrp-title").html("Latest: p" + (i+1) + " ready"); | |
var cname = "ebjrp-c-" + i; | |
BR_ROOT.BR_global.BR_ViewerGlobal.BR_inner.append('<canvas id="' + cname + '" style="top:-9999px;"></canvas>'); | |
var f = document.getElementById(cname); | |
f.height = BR_page.jsonData.pif[i].Height; | |
f.width = BR_page.jsonData.pif[i].Width; | |
var h = f.getContext("2d"); | |
h.clearRect(0, 0, BR_page.jsonData.pif[i].Width, BR_page.jsonData.pif[i].Height); | |
h.strokeStyle = "rgba(0,0,0,0)"; //Last page ;) | |
var im = new Image; | |
im.onload = function() { | |
Module.__xx(h, im, i, false); | |
console.log("p" + i + " drawn"); | |
$( "#" + cname ).each(function() { | |
$( this )[0].toBlob(function(blob) { | |
console.log("p" + i + " saving"); | |
saveAs(blob, pad((i+1), 3) + ".png"); | |
$( "#" + cname ).remove(); | |
console.log("p" + i + " done"); | |
$("#ebjrp-title").html("Latest: p" + (i+1) + " done"); | |
}); | |
}); | |
}; | |
im.src = c; | |
}); | |
} | |
function pad (str, max) { | |
str = str.toString(); | |
return str.length < max ? pad("0" + str, max) : str; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment