Resizer for readcomiconline.to

Make comic book pages fit on screen, because you're worth it.

目前為 2019-01-12 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Resizer for readcomiconline.to
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Make comic book pages fit on screen, because you're worth it.
// @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) {
              elt.style.width = width+"px";
          } else {
              elt.style.height = innerHeight + "px";
          }
        } else {
          // single page. we don't upscale for now. maybe we should.
          elt.style.maxWidth = width/2+"px";
          elt.style.maxHeight = innerHeight + "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();
    }
  });
})();