8muses Downloader

Download from 8muses.com

Versione datata 17/08/2019. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         8muses Downloader
// @description  Download from 8muses.com
// @namespace    onlyforfap
// @author       onlyforfap
// @icon         https://www.8muses.com/favicon.ico
// @version      1.1
// @match        https://www.8muses.com/comics/*
// @require      https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.2/jszip.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js
// @noframes
// @connect      self
// @run-at       document-idle
// @grant        GM_xmlhttpRequest
// ==/UserScript==

$(document).ready(function () {
  var l2 = 0;
  $('.c-tile.t-hover').each(function () {
    if ($(this).children().length == 2) {
      l2 += 1;
    }
  });
  if (l2 != 0) {
    var downBtn = $('<button/>', {
      text: 'DOWNLOAD',
    });
    var downBtnParent = $('<div></div>').append(downBtn);
    $(downBtnParent).css('margin', '20px');
    $('.a-image').before(downBtnParent);
    var downloading = false;
    var downloaded = false;
    var images = [];
    var zip = new JSZip();
    var title = '';
    $($('ol')[0]).children().each(function (i, li) {
      if (i != 0) {
        title += li.children[0].text + ' - ';
      }
    });
    title = title.substr(0, title.length - 3);
    $(downBtn).css('background-color', '#2a518e');
    $(downBtn).css('color', '#ffffff');
    $(downBtn).css('font-weight', 'bold');
    $(downBtn).css('font-size', '12pt');
    $(downBtn).css('border', 0);
    $(downBtn).css('width', '100%');
    $(downBtn).css('height', '40px');
    $(downBtn).click(function (event) {
      if (!downloading && !downloaded) {
        $(this).html('DOWNLOADING');
        $(downBtn).css('background-color', '#dbba00');
        downloading = true;
        var idx = 0;
        $('.c-tile.t-hover').each(function () {
          if ($(this).children().length == 2) {
            var imageSrc = $($($(this).children()[0]).children()[0]).attr('data-src').replace('th', 'fl');
            console.log(imageSrc);
            images[idx] = 'https://www.8muses.com' + imageSrc;
            idx += 1;
          }
        });
        var downCount = 0;
        var pad = '';
        for (var i = 0; i < images.length.toString().length; i++) {
          pad += '0';
        }
        $(images).each(function (i, url) {
          GM_xmlhttpRequest({
            method: 'GET',
            url: url,
            responseType: 'arraybuffer',
            onload: function (response) {
              var fileName = pad.substr(0, pad.length - (i + 1).toString().length) + (i + 1) + url.substr(url.length - 4);
              zip.file(fileName, response.response);
              if (downCount + 1 == images.length) {
                downCount += 1;
                $(downBtn).html(downCount + '/' + images.length + ' DONE');
                zip.generateAsync({
                  type: 'blob'
                }).then(function (blob) {
                  saveAs(blob, title + '.zip');
                });
                $(downBtn).html('DOWNLOADED');
                $(downBtn).css('background-color', '#216d28');
                document.title = '[⇓] ' + title;
                downloaded = true;
              }
              else {
                downCount += 1;
                $(downBtn).html(downCount + '/' + images.length + ' DONE');
              }
            }
          });
        });
      }
      else if (downloaded) {
        zip.generateAsync({
          type: 'blob'
        }).then(function (blob) {
          saveAs(blob, title + '.zip');
        });
      }
    });
  }
});