Copy Manga Simple Read

manga reader for copy manga, J/K for UP/DOWN, LEFT/RIGHT for previous/next page.

נכון ליום 07-09-2021. ראה הגרסה האחרונה.

  1. // ==UserScript==
  2. // @name Copy Manga Simple Read
  3. // @namespace http://tampermonkey.net/
  4. // @match https://www.copymanga.com/comic/*/chapter/*
  5. // @grant none
  6. // @version 1.3
  7. // @author chemPolonium
  8. // @description manga reader for copy manga, J/K for UP/DOWN, LEFT/RIGHT for previous/next page.
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict'
  14. console.log('test');
  15. let clientHeight = document.body.clientHeight;
  16. document.getElementsByClassName('header')[0].remove();
  17. let comicList = document.getElementsByClassName('comicContent-list')[0];
  18. // let headerWhiteSpace = comicList.children[0].children[0].offsetTop;
  19. let currentPageInd = -1;
  20. let currentImage;
  21. let movePage = ((x) => {
  22. currentPageInd += x;
  23. currentPageInd = currentPageInd >= 0 ? currentPageInd : 0;
  24. currentPageInd = currentPageInd < comicList.children.length ? currentPageInd : comicList.children.length - 1;
  25. currentImage = comicList.children[currentPageInd].children[0];
  26. })
  27. // window.scrollTo(0, headerWhiteSpace);
  28. let evt = new UIEvent('scroll');
  29. let onePageDown = (() => {
  30. // simulate the scroll for preload
  31. // the script is like this: total client height / 3 < window scrollY then not load
  32. // so first scroll Y to 0
  33. window.scrollTo(0, 0);
  34. for (let i = 0; i < 2; i++) {
  35. window.dispatchEvent(evt);
  36. // dispatch the scroll event for preload
  37. movePage(1);
  38. // the set will not work if important is not added
  39. currentImage.setAttribute('style', 'height: 100vh !important; width: unset !important;');
  40. }
  41. window.scrollTo(0, currentImage.offsetTop);
  42. })
  43. let onePageUp = (() => {
  44. movePage(-2);
  45. window.scrollTo(0, currentImage.offsetTop);
  46. })
  47. let switchParity = (() => {
  48. if (comicList.children[0].innerText == 'foo') {
  49. comicList.children[0].remove();
  50. } else {
  51. comicList.insertAdjacentHTML('afterbegin','<li>foo</li>');
  52. }
  53. })
  54. let footer = document.getElementsByClassName('footer')[0];
  55. let footerChildren = footer.children;
  56. let prevChapterHref = footerChildren[1].children[0].href;
  57. let nextChapterHref = footerChildren[3].children[0].href;
  58. let chapterListHref = footerChildren[4].children[0].href;
  59. document.addEventListener('keydown', (event) => {
  60. switch (event.code) {
  61. case 'ArrowRight':
  62. window.location = nextChapterHref;
  63. break;
  64. case 'ArrowLeft':
  65. window.location = prevChapterHref;
  66. break;
  67. case 'KeyK':
  68. onePageUp();
  69. break;
  70. case 'KeyJ':
  71. onePageDown();
  72. break;
  73. case 'KeyL':
  74. window.location = chapterListHref;
  75. break;
  76. case 'Semicolon':
  77. switchParity();
  78. default:
  79. console.log('key: ' + event.key + ' code: ' + event.code);
  80. }
  81. });
  82. footer.remove();
  83. comicList.setAttribute('style', 'display:grid;grid-template-columns: repeat(2, 1fr);direction: rtl;')
  84. })();