neoCmoaRipper

GrimRipper Cmoa upgraded

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         neoCmoaRipper
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  GrimRipper Cmoa upgraded
// @author       XXXXXXXXXIII, weebuwy
// @match        https://www.cmoa.jp/bib/speedreader/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cmoa.jp
// @license      MIT
// ==/UserScript==

const width = 1125; // USER: image size
const height = 1600;

let downloaded = [];

(function() {
    'use strict';
    var page = -1;

    setInterval(() => {
        try {
            if (page < 1) page = getPageNum();
          	page = getPageNum();
          
          	for (let i = 1; i <= page; i++) {
            	if (downloaded.includes(i)) continue;
              setContainer(i);
              let imgs = getImgs(i);
              saveImage(imgs, i);
              downloaded.push(i);
            }
        } catch (e) {
            console.log(e.message);
        }
    }, 100);
})();

function saveImage(imgs, page) {
  	console.log(`saved page ${page}`);
  
    let canvas = document.createElement('canvas');
    let ctx = canvas.getContext('2d');
    canvas.width = 1125;
    canvas.height = 1600;
    ctx.drawImage(imgs[0], 0, 0);
    ctx.drawImage(imgs[1], 0, canvas.height * 0.3325);
    ctx.drawImage(imgs[2], 0, canvas.height * 0.665 );
    canvas.toBlob((blob) => {
        var image = URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = image;
        document.body.appendChild(a);
        a.download = page + ".png";
        a.click(); // USER: Disable ask where to store file location setting for usability
        document.body.removeChild(a);
    }, 'image/png', 1);
}

function setContainer(page) {
    var container = document.getElementById('content-p' + page);
    container.style.width = width + 'px';
    container.style.height = height + 'px';
}

function getImgs(page) {
    return document.getElementById('content-p' + page).getElementsByTagName('IMG');
}

function getPageNum() {
    var pageNum = document.getElementById('menu_slidercaption').innerHTML;
    return Number(pageNum.replace(/\/.*/i, ""));
}