Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ebjhooker
- // @description Grabs image data from the browser viewer to save locally. Still a bit buggy. Currently works when you click off one of the pages. Source has further comments. Updated by Cure (08/13/2017)
- // @namespace ebjhooker
- // @include https://br.ebookjapan.jp/br/reader/viewer/*
- // @version 1.2
- // @run-at document-start
- // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
- // @require https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.js
- // ==/UserScript==
- // Here's some usage tips
- // 1. Get the reader to go in single page mode, it'll make your crop job easier later.
- // 1.1. Create a transparency mask in PS, set its treshold to 255, trim transparent pixels, easy cropping done in 5 seconds or less.
- // 2. If you pressed cancel at the prompt or if it didn't show at all, press the 'up' key on your keyboard to turn on autoripping
- // 3. Autoripping won't stop until it gets to the end or if you make it save the same page twice.
- // 4. You can just manually rip using the left arrow key to scroll
- // 5. If you want to start ripping at a certain spot, just use any method to get through the book that isn't the left arrow key and it won't rip anything.
- var f = HTMLCanvasElement.prototype.toBlob;
- var globPress;
- this.$ = this.jQuery = jQuery.noConflict(true);
- pad = function (n, width, z) {
- z = z || '0';
- n = n + '';
- return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
- }
- function triggerKey(){
- try{
- var eventObj = document.createEvent("Events");
- eventObj.initEvent("keydown", true, true);
- eventObj.which = 37;
- eventObj.keyCode = 37;
- eventObj.key = "ArrowLeft";
- document.dispatchEvent(eventObj);
- }
- catch(e){
- console.log(e);
- }
- }
- // wait for page to load
- $(document).ready(function(){
- var pages = [];
- var pagenumber = 0; //cover has page number 0
- var pagedata = "";
- var interval;
- if(confirm("Dump automatically? (Press the up arrow key to turn it on later, or use the left arrow key to rip manually)")){
- interval = setInterval(triggerKey,4000);
- }
- $(document).keydown(function(e){
- if(e.keyCode == 37){
- pagecanvas = $(".viewer > canvas:nth-of-type(1)");
- pagenumber = $(".slider__output").text();
- if(pages.includes(pagenumber)){
- console.log("Saving done");
- clearInterval(interval);
- }
- else{
- var tempCanvas = pagecanvas[0];
- tempCanvas.toBlob = f;
- tempCanvas.toBlob(function(blob) {
- var bookName = $('.header__title > h2').text().replace(' ????�???�_', ' ')
- var filename = bookName + pad(parseInt(pagenumber) + 1,4)+'.png';
- saveAs(blob, filename);
- //console.log("saved as "+filename);
- });
- pages.push(pagenumber);
- }
- //super();
- }else if(e.keyCode == 38){
- console.log("Manually turning on timer");
- interval = setInterval(triggerKey,2200);
- }
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement