ComicDaysDownloader

Manga downloader for comic-days.com and other sites using the same reader

目前为 2022-12-02 提交的版本。查看 最新版本

// ==UserScript==
// @name         ComicDaysDownloader
// @namespace    ComicDays
// @version      0.2
// @description  Manga downloader for comic-days.com and other sites using the same reader
// @homepage     https://github.com/Timesient/manga-download-scripts
// @author       Timesient
// @license      GPL-3.0
// @match        https://comic-days.com/*/*
// @match        https://shonenjumpplus.com/*/*
// @match        https://kuragebunch.com/*/*
// @match        https://www.sunday-webry.com/*/*
// @match        https://comicbushi-web.com/*/*
// @match        https://tonarinoyj.jp/*/*
// @match        https://comic-gardo.com/*/*
// @match        https://pocket.shonenmagazine.com/*/*
// @match        https://comic-zenon.com/*/*
// @match        https://comic-trail.com/*/*
// @match        https://comic-action.com/*/*
// @match        https://magcomi.com/*/*
// @match        https://viewer.heros-web.com/*/*
// @match        https://feelweb.jp/*/*
// @match        https://comicborder.com/*/*
// @match        https://comic-ogyaaa.com/*/*
// @match        https://www.corocoro.jp/*/*
// @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://gf.qytechs.cn/scripts/451810-imagedownloaderlib/code/ImageDownloaderLib.js?version=1096733
// @grant        GM_xmlhttpRequest
// @grant        window.onurlchange
// ==/UserScript==

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

  // reload page after url changed
  window.onurlchange = () => window.location.reload();

  // get JSON data of episode
  const jsonData = await new Promise(resolve => {
    GM_xmlhttpRequest({
      method: 'GET',
      url: window.location.origin + window.location.pathname + '.json',
      responseType: 'json',
      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 => resolve(res.response)
    });
  });

  // get url of images and title
  const imageURLs = jsonData.readableProduct.pageStructure.pages.filter(item => item.src).map(item => item.src);
  const title = jsonData.readableProduct.title;

  // setup control panel
  setupControlPanel(imageURLs.length);

  // setup ImageDownloader
  ImageDownloader({
    getImagePromises,
    isOKToDownload,
    title,
    cssVerticalDistance: 'top: 120px',
  });

  // collect promises of image
  function getImagePromises() {
    const startNum = parseInt(document.getElementById('start-input').value);
    const endNum = parseInt(document.getElementById('end-input').value);

    return imageURLs.slice(startNum - 1, endNum).map(url => axios.get(url, { responseType: 'arraybuffer' }).then(res => res.data));
  }

  // setup control panel for page number input
  function setupControlPanel(maxNum) {
    const panelElement = document.createElement('div');
    const inputStyle = `
      width: 40%;
      height: 26px;

      border: 1px solid #aaa;
      border-radius: 4px;
      
      font-family: 'Consolas', 'Monaco', 'Microsoft YaHei';
      text-align: center;
    `;

    panelElement.innerHTML = `
      <input id="start-input" style="${inputStyle}" type="text" value="1" />
      <span style="margin: 0 4px; transform: translateY(-0.5px);">to</span>
      <input id="end-input" style="${inputStyle}" type="text" value="${maxNum}" />
    `;

    panelElement.style = `
      position: fixed;
      top: 72px;
      left: 72px;
      z-index: 888;

      box-sizing: border-box;
      width: 144px;
      height: 104px;
      padding: 8px;

      display: flex;
      justify-content: center;
      align-items: baseline;

      font-size: 14px;
      font-family: 'Consolas', 'Monaco', 'Microsoft YaHei';
      background-color: #f1f1f1;
      border: 1px solid #aaa;
      border-radius: 4px;
    `;

    document.body.appendChild(panelElement);
  }

  // check validity of page nums from input
  function isOKToDownload() {
    const maxNum = imageURLs.length;
    const startNum = parseInt(document.getElementById('start-input').value);
    const endNum = parseInt(document.getElementById('end-input').value);

    if (isNaN(startNum) || isNaN(endNum)) {
      alert("请正确输入数值\nPlease enter page number correctly.");
      return false;
    }

    if (startNum < 1 || endNum < 1) {
      alert("页码的值不能小于1\nPage number should not smaller than 1.");
      return false;
    }

    if (startNum > maxNum || endNum > maxNum) {
      alert(`页码的值不能大于${maxNum}\nPage number should not bigger than ${maxNum}.`);
      return false;
    }
    
    if (startNum > endNum) {
      alert("起始页码的值不能大于终止页码的值\nNumber of start should not bigger than number of end.");
      return false;
    }

    return true;
  }

})(axios, JSZip, saveAs, ImageDownloader);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址