From 3ceb2d5f6061f651968a3e9231d0f9d823a17549 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 4 Oct 2018 21:25:06 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AA=20Download=20single=20cbz=20instea?= =?UTF-8?q?d=20of=20all=20the=20jpgs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves #1 --- viewcomic.scraper.user.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/viewcomic.scraper.user.js b/viewcomic.scraper.user.js index 4ced591..2634910 100644 --- a/viewcomic.scraper.user.js +++ b/viewcomic.scraper.user.js @@ -2,16 +2,17 @@ // ==UserScript== // @name Viewcomic Scraper // @namespace danielrayjones -// @version 0.0.6 +// @version 0.0.7 // @description Scrape comics from viewcomic.com // @author Dan Jones // @match http://viewcomic.com/* // @grant none // @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js // @require https://raw.githubusercontent.com/tommcfarlin/konami-code/master/src/jquery.konami.min.js +// @require https://bowercdn.net/c/jszip-3.1.5/dist/jszip.min.js // ==/UserScript== -/* global jQuery */ +/* global jQuery, JSZip */ (function($) { 'use strict'; @@ -36,23 +37,38 @@ let imgs = $('div.pinbin-copy img.picture, div.pinbin-copy img.hoverZoomLink').toArray(); console.log(imgs); + let cbz = new JSZip(); + + function downloadCbz() { + cbz.generateAsync({type: 'blob'}) + .then(blob => { + let title = name.replace(/-/g, ' ').replace(/\b([0-9]{4})\b/, '($1)'); + + let $el = $(''); + $(document.body).append($el); + $el.attr('href', URL.createObjectURL(blob)); + $el.attr('download', `${title} (viewcomic) (Danjones).cbz`); + $el.get(0).click(); + }); + } + function getOne() { - if (!imgs) return; + if (!imgs || !imgs.length) { + downloadCbz(); + return; + } + let img = imgs.shift(); console.log(img.src); fetch(img.src).then(resp => resp.blob()).then(blob => { - let $el = $(''); - $(document.body).append($el); - $el.attr('href', URL.createObjectURL(blob)); - $el.attr('download', name + '-' + (i < 10 ? '00' : '0' ) + i + '.jpg'); - $el.get(0).click(); + cbz.file(name + '-' + (i < 10 ? '00' : '0' ) + i + '.jpg', blob); i = i+1; - setTimeout(getOne, 1000); + setTimeout(getOne, 0); }); } + getOne(); } - })(jQuery);