Greasy Fork

Greasy Fork is available in English.

Copy Manga Simple Read

manga reader for copymanga, J/K for DOWN/UP, LEFT/RIGHT for previous/next chapter.

当前为 2021-09-07 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Copy Manga Simple Read
// @namespace   http://tampermonkey.net/
// @match       https://www.copymanga.com/comic/*/chapter/*
// @grant       none
// @version     1.2
// @author      chemPolonium
// @description manga reader for copymanga, J/K for DOWN/UP, LEFT/RIGHT for previous/next chapter.
// @run-at      document-end
// ==/UserScript==

(function() {
  'use strict'
  
  console.log('test');
  
  let clientHeight = document.body.clientHeight;
  
  document.getElementsByClassName('header')[0].remove();
  
  let comicList = document.getElementsByClassName('comicContent-list')[0];
  // let headerWhiteSpace = comicList.children[0].children[0].offsetTop;
  
  let currentPageInd = -1;
  let currentImage;
  
  let movePage = ((x) => {
    currentPageInd += x;
    currentPageInd = currentPageInd >= 0 ? currentPageInd : 0;
    currentPageInd = currentPageInd < comicList.children.length ? currentPageInd : comicList.children.length - 1;
    currentImage = comicList.children[currentPageInd].children[0];
  })
  
  // window.scrollTo(0, headerWhiteSpace);
  
  let evt = new UIEvent('scroll');
  
  let onePageDown = (() => {
    // simulate the scroll for preload
    // the script is like this: total client height / 3 < window scrollY then not load
    // so first scroll Y to 0
    window.scrollTo(0, 0);
    for (let i = 0; i < 2; i++) {
      window.dispatchEvent(evt);
      // dispatch the scroll event for preload
      movePage(1);
      // the set will not work if important is not added
      currentImage.setAttribute('style', 'height: 100vh !important; width: unset !important;');
    }
    window.scrollTo(0, currentImage.offsetTop);
  })
  
  let onePageUp = (() => {
    movePage(-2);
    window.scrollTo(0, currentImage.offsetTop);
  })
  
  let footer = document.getElementsByClassName('footer')[0];
  let footerChildren = footer.children;
  let prevChapterHref = footerChildren[1].children[0].href;
  let nextChapterHref = footerChildren[3].children[0].href;
  let chapterListHref = footerChildren[4].children[0].href;
  
  document.addEventListener('keydown', (event) => {
    switch (event.code) {
      case 'ArrowRight':
        window.location = nextChapterHref;
        break;
      case 'ArrowLeft':
        window.location = prevChapterHref;
        break;
      case 'KeyK':
        onePageUp();
        break;
      case 'KeyJ':
        onePageDown();
        break;
      case 'KeyL':
        window.location = chapterListHref;
        break;
      default:
        console.log('key: ' + event.key + ' code: ' + event.code);
    }
  });
  
  footer.remove();
  comicList.setAttribute('style', 'display:grid;grid-template-columns: repeat(2, 1fr);direction: rtl;')
  
})();