Greasy Fork is available in English.

在DMZJ订阅页直接打开被屏蔽的漫画

在Timesient的脚本基础上修改为针对订阅页的脚本

Dette scriptet har blitt slettet.

// ==UserScript==
// @name         在DMZJ订阅页直接打开被屏蔽的漫画
// @version      0.1.1
// @description  在Timesient的脚本基础上修改为针对订阅页的脚本
// @author       Timesient
// @author       UnluckyNinja
// @match        *://i.dmzj.com/subscribe*
// @grant        GM_xmlhttpRequest
// @connect      dmzj.com
// @require      https://unpkg.com/lazyload@2.0.0-rc.2/lazyload.js
// @require      https://greasyfork.org/scripts/2199-waitforkeyelements/code/waitForKeyElements.js?version=6349
// @namespace https://greasyfork.org/users/30356
// ==/UserScript==

(function(lazyload) {
  'use strict';

  // A popup modal for reading comic chapter
  class ComicReader {
    constructor (comicId) {
      this.container = document.createElement('div');
      this.pageContainer = document.createElement('div');
      this.currBtn = document.createElement('button');
      this.prevBtn = document.createElement('button');
      this.nextBtn = document.createElement('button');
      this.quitBtn = document.createElement('button');
      this.data = {
        comicId: comicId,
        chaptersData: [],
        chapterIndex: -1
      }
      this.initComponents();
    }

    initComponents () {
      this.container.className = 'comic-reader';
      this.pageContainer.className = 'page-container';

      this.currBtn.className = 'ctrl-btn';
      this.prevBtn.className = 'ctrl-btn prev-btn';
      this.prevBtn.textContent = '上一话';
      this.prevBtn.addEventListener('click', this.loadPrevChapter.bind(this));
      this.nextBtn.className = 'ctrl-btn next-btn';
      this.nextBtn.textContent = '下一话';
      this.nextBtn.addEventListener('click', this.loadNextChapter.bind(this));
      this.quitBtn.className = 'ctrl-btn quit-btn';
      this.quitBtn.textContent = '退出';
      this.quitBtn.addEventListener('click', this.quitReading.bind(this));

      const btnContainer = document.createElement('div');
      btnContainer.className = 'btn-container';
      btnContainer.appendChild(this.currBtn);
      btnContainer.appendChild(this.prevBtn);
      btnContainer.appendChild(this.nextBtn);
      btnContainer.appendChild(this.quitBtn);

      this.container.appendChild(btnContainer);
      this.container.appendChild(this.pageContainer);
      document.body.appendChild(this.container);
    }

    loadChapter (chaptersData, chapterIndex) {
      // update current chapter data
      if (chaptersData) this.data.chaptersData = chaptersData;
      this.data.chapterIndex = chapterIndex;

      const self = this;
      GM_xmlhttpRequest({
        method: 'GET',
        url: `http://v2.api.dmzj.com/chapter/${self.data.comicId}/${chaptersData[chapterIndex].id}.json`,
        onload: function (res) {
            console.log(res.finalUrl);
          const data = JSON.parse(res.response);
          const pageUrls = data.page_url;
          const title = data.title;

          // disable webpage scroll
          document.body.style.height = '100vh';
          document.body.style.overflow = 'hidden';

          // show the modal
          self.container.classList.add('comic-reader--show');

          // reset the scroll bar of page container
          self.pageContainer.scrollTo(0, 0);

          // setup title button
          self.currBtn.textContent = `当前:${title}`;

          // setup prev-chapter button and next-chapter button
          if (chapterIndex === 0) self.prevBtn.classList.add('ctrl-btn--hide');
          if (chapterIndex === self.data.chaptersData.length - 1) self.nextBtn.classList.add('ctrl-btn--hide');

          // load pages
          self.loadPages(pageUrls);
        }
      })
    }

    loadPages (pageUrls) {
      const self = this;

      pageUrls.forEach(function (url, index) {
        const pageImg = document.createElement('img');
        pageImg.className = 'page-item__img';
        pageImg.src = "https://static.dmzj.com/ocomic/images/mh-last/lazyload.gif";

        const pageNumber = document.createElement('p');
        pageNumber.className = 'page-item__number';
        pageNumber.textContent = `第${ index + 1 }页`;

        const pageItem = document.createElement('div');
        pageItem.className = 'page-item';
        pageItem.appendChild(pageImg);
        pageItem.appendChild(pageNumber);

        self.pageContainer.appendChild(pageItem);

        GM_xmlhttpRequest({
          method: 'GET',
          url: url,
          headers: { 'Referer' : 'http://images.dmzj.com/' },
          responseType: 'blob',
          onload: function(res) {
            if (res.status === 200) {
              pageImg.setAttribute('data-src', (window.URL || window.webkitURL).createObjectURL(res.response));
              lazyload(document.querySelectorAll(".page-item__img"));
            }
          }
        });
      });
    }

    loadPrevChapter () {
      this.quitReading();
      this.loadChapter(null, this.data.chapterIndex - 1);
    }

    loadNextChapter () {
      this.quitReading();
      this.loadChapter(null, this.data.chapterIndex + 1);
    }

    quitReading () {
      // hide the modal
      this.container.classList.remove('comic-reader--show');

      // cancel hiding prev-btn and next-btn
      this.prevBtn.classList.remove('ctrl-btn--hide');
      this.nextBtn.classList.remove('ctrl-btn--hide');

      // clear the page container
      this.pageContainer.innerHTML = '';

      // enable webpage scroll
      document.body.style = '';
    }
  }

    // Create comic reader instance
    waitForKeyElements('.dy_content_li', (node)=>{
          // var comicId = node.querySelector('a.qx').value;
          var comicId = $(node).find('a.qx').first().attr('value');
          // var linkNode = node.querySelector('div.dy_r > p:nth-child(2) > em > a');
          var linkNode = $(node).find('div.dy_r > p:nth-child(2) > em > a').first();
          var chapterId = linkNode.attr('href').match(/.*\/(\d+)\.shtml/)[1];
          var title = linkNode.text();
          linkNode.on('click', function(){
              const reader = new ComicReader(comicId);
              console.log(`http://v2.api.dmzj.com/chapter/${comicId}/${chapterId}.json`)
              reader.loadChapter([{id: chapterId, title: title}], 0);
              event.preventDefault();
          });
      });

  const style = document.createElement('style');
  document.head.appendChild(style);
  style.textContent = `
    .comic-reader {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 999999;
      overflow-y: scroll;
      width: 100vw;
      height: 100vh;
      background-color: rgba(0, 0, 0, 0.8);
      display: none;
    }

    .comic-reader::-webkit-scrollbar {
      height: 13px;
      width: 13px;
    }

    .comic-reader::-webkit-scrollbar-thumb {
      background-color: #aaa;
    }

    .comic-reader::-webkit-scrollbar-track {
      background-color: #eee;
    }

    .comic-reader--show {
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .page-container {
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .page-item {
      margin-top: 20px;
      margin-bottom: 20px;
    }

    .page-item__img {
      max-width: 90vw;
      margin-bottom: 10px;
      background-color: #fff;
    }

    .page-item__number {
      color: #aaa;
      font-size: 16px;
      text-align: center;
    }

    .btn-container {
      position: fixed;
      right: 50px;
      bottom: 50px;
      display: flex;
      flex-direction: column;
    }

    .ctrl-btn {
      width: 120px;
      height: 40px;
      margin-top: 30px;
      padding: 0 10px;
      background-color: #4385ff;
      font-size: 14px;
      color: #fff;
      border: none;
      outline: none;
      border-radius: 6px;
      box-shadow: 0 10px 0 0 #2571ff;
      cursor: pointer;
    }

    .ctrl-btn:active {
      transform: translateY(10px);
      box-shadow: none;
    }

    .ctrl-btn--hide { display: none; }

    .chapter-container {
      display: flex;
      flex-direction: column;
      padding: 0;
    }

    .category-container {
      padding: 10px 14px;
      border-top: 1px dashed #0187c5;
    }

    .info-text {
      padding: 10px 0 ;
    }

    .title-text {
      height: 20px;
      font-weight: bold;
    }

    .font-red {
      color: red;
    }

    .font-bold {
      font-weight: bold;
    }
  `;

})(lazyload);