Viewer for www.xiurenji.cc

Viewer for xiurenji.cc

目前為 2021-06-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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));
      },
    });
  }

})();