Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ebjhooker
  3. // @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)
  4. // @namespace ebjhooker
  5. // @include https://br.ebookjapan.jp/br/reader/viewer/*
  6. // @version 1.2
  7. // @run-at document-start
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  9. // @require https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.js
  10. // ==/UserScript==
  11.  
  12.  
  13. // Here's some usage tips
  14. // 1. Get the reader to go in single page mode, it'll make your crop job easier later.
  15. // 1.1. Create a transparency mask in PS, set its treshold to 255, trim transparent pixels, easy cropping done in 5 seconds or less.
  16. // 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
  17. // 3. Autoripping won't stop until it gets to the end or if you make it save the same page twice.
  18. // 4. You can just manually rip using the left arrow key to scroll
  19. // 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.
  20.  
  21. var f = HTMLCanvasElement.prototype.toBlob;
  22. var globPress;
  23.  
  24. this.$ = this.jQuery = jQuery.noConflict(true);
  25. pad = function (n, width, z) {
  26. z = z || '0';
  27. n = n + '';
  28. return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
  29. }
  30.  
  31.  
  32. function triggerKey(){
  33. try{
  34. var eventObj = document.createEvent("Events");
  35. eventObj.initEvent("keydown", true, true);
  36. eventObj.which = 37;
  37. eventObj.keyCode = 37;
  38. eventObj.key = "ArrowLeft";
  39. document.dispatchEvent(eventObj);
  40. }
  41. catch(e){
  42. console.log(e);
  43. }
  44. }
  45.  
  46. // wait for page to load
  47. $(document).ready(function(){
  48. var pages = [];
  49. var pagenumber = 0; //cover has page number 0
  50. var pagedata = "";
  51. var interval;
  52. if(confirm("Dump automatically? (Press the up arrow key to turn it on later, or use the left arrow key to rip manually)")){
  53. interval = setInterval(triggerKey,4000);
  54. }
  55. $(document).keydown(function(e){
  56. if(e.keyCode == 37){
  57. pagecanvas = $(".viewer > canvas:nth-of-type(1)");
  58. pagenumber = $(".slider__output").text();
  59. if(pages.includes(pagenumber)){
  60. console.log("Saving done");
  61. clearInterval(interval);
  62. }
  63. else{
  64. var tempCanvas = pagecanvas[0];
  65. tempCanvas.toBlob = f;
  66. tempCanvas.toBlob(function(blob) {
  67. var bookName = $('.header__title > h2').text().replace(' ????�???�_', ' ')
  68. var filename = bookName + pad(parseInt(pagenumber) + 1,4)+'.png';
  69. saveAs(blob, filename);
  70. //console.log("saved as "+filename);
  71. });
  72. pages.push(pagenumber);
  73. }
  74. //super();
  75. }else if(e.keyCode == 38){
  76. console.log("Manually turning on timer");
  77. interval = setInterval(triggerKey,2200);
  78. }
  79. })
  80. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement