漫画柜双页

漫画柜双页浏览,全屏显示,从右到左显示。

目前為 2023-03-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         漫画柜双页
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  漫画柜双页浏览,全屏显示,从右到左显示。
// @author       ChatGPT,akira0245 
// @match        https://www.manhuagui.com/comic/*/*.html
// @icon         https://www.google.com/s2/favicons?sz=64&domain=manhuagui.com
// @grant        GM_addStyle
// @license      GPLv3
// ==/UserScript==

(function() {
    'use strict';


var scrollFunction = function(e) {
    e = e || window.event;
    e.preventDefault && e.preventDefault(); //禁止浏览器默认事件
    if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
        if (e.wheelDelta > 0) { //当滑轮向上滚动时
            onePageUp();
        }
        if (e.wheelDelta < 0) { //当滑轮向下滚动时
            onePageDown();
        }

    } else if (e.detail) { //Firefox滑轮事件
        if (e.detail > 0) { //当滑轮向上滚动时
            onePageUp();
        }
        if (e.detail < 0) { //当滑轮向下滚动时
            onePageDown();
        }
    }
}
//给页面绑定滑轮滚动事件
if (document.addEventListener) { //firefox
    document.addEventListener('DOMMouseScroll', scrollFunction, false);
}
//滚动滑轮触发scrollFunction方法  //ie 谷歌
window.addEventListener('mousewheel', scrollFunction, {
    passive: false
});


  function onePageUp() {
    // Find all elements with the data-tag attribute equal to "mangaFile"
    var mangaFileElements = document.querySelectorAll('[data-tag="mangaFile"]');

    // Find the index of the last mangaFile element that is above the current scroll position
    var lastMangaFileIndex = -1;
    var currentScrollPosition = window.pageYOffset;
    for (var i = mangaFileElements.length - 1; i >= 0; i--) {
      if (mangaFileElements[i].getBoundingClientRect().top < 0) {
        lastMangaFileIndex = i;
        break;
      }
    }

    // If there is a mangaFile element above the current position, scroll to its top position
    if (lastMangaFileIndex >= 0) {
      var targetElement = mangaFileElements[lastMangaFileIndex];
      var targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset;
      window.scrollTo(0, targetPosition);
    }else{
      window.scrollTo(0, 0);
    }
  }

  function onePageDown() {
    // Find all elements with the data-tag attribute equal to "mangaFile"
    var mangaFileElements = document.querySelectorAll('[data-tag="mangaFile"]');

    // Find the index of the first mangaFile element that is below the current scroll position
    var nextMangaFileIndex = -1;
    var currentScrollPosition = window.pageYOffset;
    for (var i = 0; i < mangaFileElements.length; i++) {
      if (mangaFileElements[i].getBoundingClientRect().top > 1) {
        nextMangaFileIndex = i;
        break;
      }
    }

    // If there is another mangaFile element below the current position, scroll to its top position
    if (nextMangaFileIndex >= 0 && nextMangaFileIndex < mangaFileElements.length) {
      var targetElement = mangaFileElements[nextMangaFileIndex];
      var targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset;
      window.scrollTo(0, targetPosition);
    }else{
      window.scrollTo(0, 99999);
    }
  }





// 获取需要操作的元素
const mangaBox = document.getElementById('mangaBox');
const mangaMoreBox = document.getElementById('mangaMoreBox');

// 获取mangaBox中的元素
const childNodes = mangaBox.childNodes;

// 将mangaBox中的元素插入到mangaMoreBox的第一个位置
mangaMoreBox.insertBefore(childNodes[0], mangaMoreBox.firstChild);

// 删除mangaBox元素
mangaBox.parentNode.removeChild(mangaBox);


document.addEventListener("keydown", function(event) {
  if (event.key === "5") {
    event.preventDefault();
    let mangaMoreBox = document.getElementById('mangaMoreBox');
    let firstChild = mangaMoreBox.firstChild;
    let placeholder = document.querySelector(".placeholder");
    if (!placeholder) {
      placeholder = firstChild.cloneNode(true);
      placeholder.classList.add("placeholder");
      mangaMoreBox.insertBefore(placeholder, firstChild);
    } else {
      mangaMoreBox.removeChild(placeholder);
    }
  }
});



GM_addStyle(`
    #mangaMoreBox {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        flex-direction: row-reverse;
        /*         width: 100vw */
    }

    [data-tag="mangaFile"] {
        flex: ;
        object-fit: contain;
        max-width: 50%;
        height: 100vh;
    }
    .img_info {
        display: none;
    }
    .pr.tbCenter.cb {
        all: unset !important;
        /* 禁用所有CSS属性 */
    }
`);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址