Greasy Fork is available in English.

Resizer for readcomiconline.to

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

2019-01-13 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Resizer for readcomiconline.to
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Make comic book pages fit on screen, because you're worth it.
  6. // @author itsnotlupus
  7. // @match https://readcomiconline.to/*
  8. // @grant GM_xmlhttpRequest
  9. // @require https://unpkg.com/jquery@3.3.1/dist/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. const buttonholder = ".btnZoom-container";
  15. const images = "#divImage>p>img";
  16.  
  17. const a = $("<a href=# class='btnZoom resize'>#</a>");
  18. $(buttonholder).append(a);
  19. a.click(e => {
  20. const pageWidth = document.body.clientWidth;
  21. $(images).each(async (i, elt) => {
  22. const { url, width, height } = await removeBanner(await blobify(elt.src));
  23.  
  24. elt.src = url;
  25. // force cover to sit by itself.
  26. elt.style.maxWidth = "inherit";
  27. elt.style.maxHeight = "inherit";
  28. if (i===0) {
  29. // v1
  30. elt.style.display="block";
  31. elt.style.marginLeft = elt.style.marginRight = "auto";
  32. } else {
  33. // v2
  34. elt.parentElement.style.display="inline-block";
  35. }
  36. if (width>height) {
  37. // double pages. make it fit, even if you need to upscale.
  38. if (width/height > pageWidth/innerHeight) {
  39. elt.style.width = pageWidth+"px";
  40. } else {
  41. elt.style.height = innerHeight + "px";
  42. }
  43. } else {
  44. // single page. we don't upscale for now. maybe we should.
  45. elt.style.maxWidth = pageWidth/2+"px";
  46. elt.style.maxHeight = innerHeight + "px";
  47. }
  48. });
  49. });
  50. addEventListener('keydown', e => {
  51. let nextImage;
  52. switch (e.keyCode){
  53. case 39:
  54. case 40:
  55. nextImage = Array.from($(images)).find(img=>img.offsetTop>scrollY);
  56. break;
  57. case 37:
  58. case 38:
  59. nextImage = Array.from($(images)).reverse().find(img=>img.offsetTop<scrollY);
  60. break;
  61. }
  62. if (nextImage) {
  63. nextImage.scrollIntoView();
  64. e.preventDefault();
  65. }
  66. });
  67. const blobify = url => new Promise(resolve => {
  68. GM_xmlhttpRequest({
  69. method: 'GET',
  70. url,
  71. responseType: 'blob',
  72. onload: xhr => resolve(URL.createObjectURL(xhr.response))
  73. });
  74. });
  75. const removeBanner = (blobUrl) => new Promise(resolve => {
  76. const img = new Image;
  77. img.src = blobUrl;
  78. img.onload = e => {
  79. const canvas = document.createElement('canvas');
  80. const ctx = canvas.getContext('2d');
  81. canvas.width = img.width;
  82. canvas.height = img.height;
  83. ctx.drawImage(img, 0, 0);
  84. // sad test for banner.
  85. const data = ctx.getImageData(0, img.height - 5, img.width, 4).data;
  86. let found = false;
  87. for (let i=0;i<data.length;i++) if (data[i] !== (i%4===3?255:0)) { found = true; break }
  88. if (!found) {
  89. canvas.height -= 80;
  90. ctx.drawImage(img, 0, 0);
  91. canvas.toBlob( blob => {
  92. resolve({
  93. url: URL.createObjectURL(blob),
  94. width: canvas.width,
  95. height: canvas.height
  96. })
  97. });
  98. console.log('removed banner from comic page.');
  99. } else {
  100. // no banner, do nothing.
  101. resolve({ url: blobUrl, width: img.width, height: img.height });
  102. }
  103. };
  104. });
  105. })();