Viewer for www.xiurenji.cc

Viewer for xiurenji.cc

Ajankohdalta 4.6.2021. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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));
      },
    });
  }

})();