起点小说解锁

可解锁起点小说VIP付费章节

目前為 2021-01-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         起点小说解锁
// @version      1.0
// @description  可解锁起点小说VIP付费章节
// @author       JiGuang
// @namespace    www.xyde.net.cn
// @homepageURL  http://www.xyde.net.cn
// @match        https://vipreader.qidian.com/chapter/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequesta
// ==/UserScript==

(function() {
  'use strict';

    //获取章节名
    function QDgetBookChapter(){
      if(document.querySelector("div > div.text-head > h3 > span.content-wrap")){
        let res = '' + document.querySelector("div > div.text-head > h3 > span.content-wrap").innerText
        res = res.replace(' ','')
        return res
      }
      return undefined
    }

    //获取书本名
    function QDgetBookName(){
      return document.querySelector("#bookImg").innerText
    }

    //设置页面阅读内容
    function QDsetContent(content){
      document.querySelector("div > div.read-content.j_readContent").innerHTML = content
      document.querySelector("div > div.vip-limit-wrap > h3").innerText = '已订阅本章付费VIP章节'
    }

    //将请求的url的html内容转化成document对象
    async function parseDocFromAjax(method,url){
      return new Promise((resolve,reject) => {
          GM_xmlhttpRequest({
              method,
              url,
              onload:(res) => {
                console.log(res)
                  let htmldoc = document.createElement('html')
                  htmldoc.innerHTML = res.response
                  resolve(htmldoc)
              },
              onerror:(err) => {
                  reject(err)
              }
          })
      })
    }

    //搜索小说并返回结果
    async function searchBook(){
      const r = await parseDocFromAjax('GET','http://www.mibaoge.com/search.php?q=' + QDgetBookName())
      const bookList = r.querySelectorAll("body > div.result-list > div > div.result-game-item-detail > h3 > a")
      const authorList = r.querySelectorAll("body > div.result-list > div > div.result-game-item-detail > div > p:nth-child(1) > span:nth-child(2)")
      let resList = []
      for(let i in bookList){
        if(bookList[i].title){
          resList.push({bookName:bookList[i].title,author:authorList[i].innerText,url:'http://www.mibaoge.com' + bookList[i].pathname})
        }
      }
      return resList
    }

    //获取小说目录
    async function getChapterList(bookUrl){
      let resList = []
      const r = await parseDocFromAjax('GET',bookUrl)
      const cateList = r.querySelectorAll("#list > dl > dd > a")
      for(let i in cateList){
        let url = '' + cateList[i].href
        url = url.replace('https://vipreader.qidian.com/','http://www.mibaoge.com/')
        resList.push({title:cateList[i].innerText,url:url})
      }
      return resList
    }

    //获取章节内容
    async function getContent(pageUrl){
      const res = await parseDocFromAjax('GET',pageUrl)
      return res.querySelector("#content").innerHTML
    }


    //解析页面函数
    async function a(){
      //搜索小说名字
      const r = await searchBook()
      let ii = 0
      //优先匹配名字相同的
      for(let suoyin in r){
        if(r[suoyin].bookName == QDgetBookName()){
          ii = suoyin
          console.log(r[suoyin])
        }
      }
      //获取第一项结果章节目录
      if(r[ii] == undefined){
        alert('该小说暂无资源')
        return
      }else{
        console.log(r[ii].url)
      }
      const clist = await getChapterList(r[ii].url)
      console.log(clist)
      if(QDgetBookChapter() == undefined){
        console.log('抓取目录失败')
        return
      }
      //获取章节名
      for(let i in clist){
        let tit = '' + clist[i].title
        tit = tit.replace(' ','')
        //console.log('匹配',tit,QDgetBookChapter())
        if(tit == QDgetBookChapter()){
          console.log('检查到结果')
          console.log(clist[i])

          const content = await getContent(clist[i].url)

          QDsetContent(content)
          console.log('写入成功')
        }
      }
    }
    console.log(`您正在阅读${QDgetBookName()}的${QDgetBookChapter()}`)
    a()

  //   GM_xmlhttpRequest({
  //       method:'GET',
  //       url:'http://www.mibaoge.com/search.php?q='+getBookName(),
  //       onload:function(res){
  //         console.log(res.responseXML)
  //       }
  //   })
        // Your code here...
})();

QingJ © 2025

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