Resizer for readcomiconline.to

try to take over the world!

Від 10.01.2019. Дивіться остання версія.

// ==UserScript==
// @name         Resizer for readcomiconline.to
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https?://readcomiconline.to/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  const buttonholder = ".btnZoom-container";
  const images = "#divImage>p>img";

  const a = $("<a href=# class='btnZoom resize'>#</a>");
  $(buttonholder).append(a);
  a.click(e => {
    const width = document.body.clientWidth;
    $(images).each((i, elt) => {
      const img = new Image();
      img.src = elt.src;
      img.onload = e => {
        // force cover to sit by itself.
        elt.style.maxWidth = "inherit";
        elt.style.maxHeight = "inherit";
        if (i===0) {
          // v1
          elt.style.display="block";
          elt.style.marginLeft = elt.style.marginRight = "auto";
        } else {
          // v2
          elt.parentElement.style.display="inline-block";
        }
        if (img.width>img.height) {
          // double pages. make it fit, even if you need to upscale.
          if (img.width/img.height > width/(innerHeight-20)) {
              elt.style.width = width+"px";
          } else {
              elt.style.height = (innerHeight-20)+"px";
          }
        } else {
          // single page. we don't upscale for now. maybe we should.
          elt.style.maxWidth = width/2+"px";
          elt.style.maxHeight = (innerHeight-20)+"px";
        }
      };
    });
  });
  addEventListener('keydown', e => {
    let nextImage;
    switch (e.keyCode){
      case 39:
      case 40:
        nextImage = Array.from($(images)).find(img=>img.offsetTop>scrollY);
        break;
      case 37:
      case 38:
        nextImage = Array.from($(images)).reverse().find(img=>img.offsetTop<scrollY);
        break;
    }
    if (nextImage) {
      nextImage.scrollIntoView();
      e.preventDefault();
    }
  });
})();