Resizer for readcomiconline.to

try to take over the world!

当前为 2019-01-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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();
    }
  });
})();