Make comic book pages fit on screen, because you're worth it.
当前为
// ==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();
}
});
})();