Viewer for www.xiurenji.cc

Viewer for xiurenji.cc

2021-06-04 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Viewer for www.xiurenji.cc
// @namespace    http://tampermonkey.net/xiurenji
// @version      0.2
// @description  Viewer for xiurenji.cc
// @author       You
// @match        https://www.xiurenji.cc/*
// @icon         https://www.google.com/s2/favicons?domain=xiurenji.cc
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @grant        GM_getResourceText
// @require      https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.9.0/viewer.min.js
// @resource     viewerCSS   https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.9.0/viewer.min.css
// ==/UserScript==

(function () {
  'use strict';
  GM_addStyle(GM_getResourceText('viewerCSS'));
  var href = window.location.href;

  var new_image_viewer_ul = document.createElement('ul');
  var img_container = document.getElementsByClassName('img')[0];

  new_image_viewer_ul.setAttribute('id', 'imagesViewer');
  img_container.appendChild(new_image_viewer_ul);

  var gallery = new Viewer(new_image_viewer_ul, { fullscreen: false, interval: 1400, loop: false });
  document.querySelector("body > div.nr3 > table:nth-child(6) > tbody > tr > td > div > p").remove()

  // getPageImages from html page source
  function getPageImages(htmlDoc) {
    return htmlDoc.getElementsByClassName('img')[0].getElementsByTagName('img');
  }

  var page_ind = document.querySelector(
    'body > div.nr3 > table:nth-child(4) > tbody > tr:nth-child(1) > td > div');
  var pages_num = page_ind.innerText.split('\n');
  var pages_url = [];
  var pages_map = {};
  pages_url.push(href); // 第 0 页

  function update_img_set(page, img_set) {
    pages_map[page] = img_set
    console.log(`加载页面 ${page + 1} / ${pages_url.length}`)
    if (Object.keys(pages_map).length === pages_url.length) {
      console.log(" 所有页面的信息已经加载到 pages_url 中")
      for (let i = 0; i < pages_url.length; i++) {
        img_set = pages_map['' + i]
        for (let img of img_set) {
          img.setAttribute('style', 'max-height: 1080px');
          new_image_viewer_ul.appendChild(img);
        }
      }
    }
    gallery.update();
  }

  for (let i = 0; i < pages_num.length; i++) {
    let page = parseInt(pages_num[i]);
    if (page) {
      if (page - 1 === 0) continue;
      // console.log(parseInt(page - 1))
      pages_url.push(href.slice(0, href.lastIndexOf('.')) + `_${page - 1}.html`);
    }
  }

  (function addBtn(text, disable) {
    let btn = document.createElement('input');
    let div = document.createElement('dpiv');

    let btnFarther = document.getElementsByClassName('ina')[0];

    div.appendChild(btn);
    btnFarther.appendChild(div);

    div.style.textAlign = 'center';

    btn.disabled = disable;
    btn.type = 'submit';
    btn.value = text;
    btn.style.textAlign = 'center';
    btn.style.verticalAlign = 'middle';
    btn.style.color = '#666666';
    btn.style.background = '#fff';
    btn.style.width = '10rem';
    btn.style.height = '2rem';
    btn.style.background = '-webkit-gradient(linear,left top, right top,from(#02fdfe),to(#d3fb42))';
    btn.style.border = '1px';
    btn.style.borderRadius = '3rem';

    btn.onclick = function () { gallery.show(); };
  })('Play by Viewer', false);

  for (let i = 0; i < pages_url.length; i++) {
    let durl = pages_url[i];
    console.log(durl);

    GM_xmlhttpRequest({
      url: durl, method: 'GET',
      onload: xhr => {
        let data = xhr.response;
        let htmlDoc = new DOMParser().parseFromString(data, 'text/html');
        update_img_set(i, getPageImages(htmlDoc));
      },
    });
  }

})();