MangaboxDownloader

Manga downloader for www.mangabox.me

// ==UserScript==
// @name         MangaboxDownloader
// @namespace    https://github.com/Timesient/manga-download-scripts
// @version      0.6
// @license      GPL-3.0
// @author       Timesient
// @description  Manga downloader for www.mangabox.me
// @icon         https://image-a.mangabox.me/static/assets/favicon.ico
// @homepageURL  https://greasyfork.org/scripts/455860-mangaboxdownloader
// @supportURL   https://github.com/Timesient/manga-download-scripts/issues
// @match        https://www.mangabox.me/reader/*/episodes/*
// @require      https://unpkg.com/[email protected]/dist/axios.min.js
// @require      https://unpkg.com/[email protected]/dist/jszip.min.js
// @require      https://unpkg.com/[email protected]/dist/FileSaver.min.js
// @require      https://update.greasyfork.org/scripts/451810/1398192/ImageDownloaderLib.js
// @grant        GM_info
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(async function(axios, JSZip, saveAs, ImageDownloader) {
  'use strict';

  // get url of images
  const imageURLs = await new Promise(resolve => {
    GM_xmlhttpRequest({
      method: 'GET',
      url: window.location.href,
      responseType: 'text',
      headers: { 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' },
      onload: res => {
        const html = res.response;
        const urls = html.match(/https:\/\/image-a.mangabox.me\/static\/content\/reader\/\d+\/[a-z0-9]{64}\/sp\/\d+\.(jpg|png)\?t=\d{10}/g);
        resolve(urls);
      }
    });
  });

  // get title
  const title = document.querySelector('body > header > h2').innerText;

  // setup ImageDownloader
  ImageDownloader.init({
    maxImageAmount: imageURLs.length,
    getImagePromises,
    title
  });

  // collect promises of image
  function getImagePromises(startNum, endNum) {
    return imageURLs
      .slice(startNum - 1, endNum)
      .map(url => getImage(url)
        .then(ImageDownloader.fulfillHandler)
        .catch(ImageDownloader.rejectHandler)
      );
  }

  // get promise of image
  function getImage(url) {
    return new Promise(resolve => {
      GM_xmlhttpRequest({
        method: 'GET',
        url,
        responseType: 'arraybuffer',
        onload: res => resolve(res.response)
      });
    });
  }
  
})(axios, JSZip, saveAs, ImageDownloader);