番茄小说阅读辅助器

可以下载番茄小说内容,可分卷,已解码,超好用!

// ==UserScript==
// @name         番茄小说阅读辅助器
// @namespace    http://tampermonkey.net/
// @version      1.12
// @description  可以下载番茄小说内容,可分卷,已解码,超好用!
// @author       twjx
// @match        *://fanqienovel.com/*
// @require        https://cdn.jsdelivr.net/npm/lil-gui@0.16
// @require https://update.greasyfork.org/scripts/521360/1506814/unicode1.js
// @license GPL
// @resource       swalStyle https://unpkg.com/sweetalert2@10.16.6/dist/sweetalert2.min.css
// @icon         https://p1-tt.byteimg.com/origin/novel-static/22507f26acbf2c7b65bdb7d8926370df
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    window.data=''
    window.num=0
    window.onstop=false
    window.unicode_data = { '58670':'0', '58413':'1', '58678':'2', '58371':'3', '58353':'4', '58480':'5', '58359':'6', '58449':'7', '58540':'8', '58692':'9', '58712':'a', '58542':'b', '58575':'c', '58626':'d', '58691':'e', '58561':'f', '58362':'g', '58619':'h', '58430':'i', '58531':'j', '58588':'k', '58440':'l', '58681':'m', '58631':'n', '58376':'o', '58429':'p', '58555':'q', '58498':'r', '58518':'s', '58453':'t', '58397':'u', '58356':'v', '58435':'w', '58514':'x', '58482':'y', '58529':'z', '58515':'A', '58688':'B', '58709':'C', '58344':'D', '58656':'E', '58381':'F', '58576':'G', '58516':'H', '58463':'I', '58649':'J', '58571':'K', '58558':'L', '58433':'M', '58517':'N', '58387':'O', '58687':'P', '58537':'Q', '58541':'R', '58458':'S', '58390':'T', '58466':'U', '58386':'V', '58697':'W', '58519':'X', '58511':'Y', '58634':'Z', '58611':'的', '58590':'一', '58398':'是', '58422':'了', '58657':'我', '58666':'不', '58562':'人', '58345':'在', '58510':'他', '58496':'有', '58654':'这', '58441':'个', '58493':'上', '58714':'们', '58618':'来', '58528':'到', '58403':'大', '58461':'地', '58481':'为', '58700':'子', '58708':'中', '58503':'你', '58442':'说', '58639':'生', '58506':'国', '58663':'年', '58436':'着', '58563':'就', '58391':'那', '58357':'和', '58354':'要', '58695':'她', '58372':'出', '58696':'也', '58551':'得', '58445':'里', '58408':'后', '58599':'自', '58424':'以', '58394':'会', '58348':'家', '58426':'可', '58673':'下', '58417':'而', '58556':'过', '58603':'天', '58565':'去', '58604':'能', '58522':'对', '58632':'小', '58622':'多', '58350':'然', '58605':'于', '58617':'心', '58401':'学', '58637':'么', '58684':'之', '58382':'都', '58464':'好', '58487':'看', '58693':'起', '58608':'发', '58392':'当', '58474':'没', '58601':'成', '58355':'只', '58573':'如', '58499':'事', '58469':'把', '58361':'还', '58698':'用', '58489':'第', '58711':'样', '58457':'道', '58635':'想', '58492':'作', '58647':'种', '58623':'开', '58521':'美', '58609':'总', '58530':'从', '58665':'无', '58652':'情', '58676':'己', '58456':'面', '58581':'最', '58509':'女', '58488':'但', '58363':'现', '58685':'前', '58396':'些', '58523':'所', '58471':'同', '58485':'日', '58613':'手', '58533':'又', '58589':'行', '58527':'意', '58593':'动', '58699':'方', '58707':'期', '58414':'它', '58596':'头', '58570':'经', '58660':'长', '58364':'儿', '58526':'回', '58501':'位', '58638':'分', '58404':'爱', '58677':'老', '58535':'因', '58629':'很', '58577':'绘', '58606':'多', '58497':'法', '58662':'间', '58479':'斯', '58532':'知', '58380':'世', '58385':'什', '58405':'两', '58644':'次', '58578':'使', '58505':'身', '58564':'者', '58412':'被', '58686':'高', '58624':'已', '58667':'亲', '58607':'其', '58616':'进', '58368':'此', '58427':'话', '58423':'常', '58633':'与', '58525':'活', '58543':'正', '58418':'感', '58597':'见', '58683':'明', '58507':'问', '58621':'力', '58703':'理', '58438':'尔', '58536':'占', '58384':'文', '58484':'几', '58539':'定', '58554':'木', '58421':'公', '58347':'特', '58569':'做', '58710':'外', '58574':'孩', '58375':'相', '58645':'西', '58592':'果', '58572':'走', '58388':'将', '58370':'月', '58399':'十', '58651':'实', '58546':'向', '58504':'声', '58419':'车', '58407':'全', '58672':'信', '58675':'重', '58538':'三', '58465':'机', '58374':'工', '58579':'物', '58402':'气', '58702':'每', '58553':'并', '58360':'别', '58389':'真', '58560':'打', '58690':'太', '58473':'新', '58512':'比', '58653':'才', '58704':'便', '58545':'夫', '58641':'再', '58475':'书', '58583':'部', '58472':'水', '58478':'像', '58664':'眼', '58586':'等', '58568':'体', '58674':'却', '58490':'加', '58476':'电', '58346':'主', '58630':'界', '58595':'门', '58502':'利', '58713':'海', '58587':'受', '58548':'听', '58351':'表', '58547':'德', '58443':'少', '58460':'克', '58636':'代', '58585':'员', '58625':'许', '58694':'稜', '58428':'先', '58640':'口', '58628':'由', '58612':'死', '58446':'安', '58468':'写', '58410':'性', '58508':'马', '58594':'光', '58483':'白', '58544':'或', '58495':'住', '58450':'难', '58643':'望', '58486':'教', '58406':'命', '58447':'花', '58669':'结', '58415':'乐', '58444':'色', '58549':'更', '58494':'拉', '58409':'东', '58658':'神', '58557':'记', '58602':'处', '58559':'让', '58610':'母', '58513':'父', '58500':'应', '58378':'直', '58680':'字', '58352':'场', '58383':'平', '58454':'报', '58671':'友', '58668':'关', '58452':'放', '58627':'至', '58400':'张', '58455':'认', '58416':'接', '58552':'告', '58614':'入', '58582':'笑', '58534':'内', '58701':'英', '58349':'军', '58491':'候', '58467':'民', '58365':'岁', '58598':'往', '58425':'何', '58462':'度', '58420':'山', '58661':'觉', '58615':'路', '58648':'带', '58470':'万', '58377':'男', '58520':'边', '58646':'风', '58600':'解', '58431':'叫', '58715':'任', '58524':'金', '58439':'快', '58566':'原', '58477':'吃', '58642':'妈', '58437':'变', '58411':'通', '58451':'师', '58395':'立', '58369':'象', '58706':'数', '58705':'四', '58379':'失', '58567':'满', '58373':'战', '58448':'远', '58659':'格', '58434':'士', '58679':'音', '58432':'轻', '58689':'目', '58591':'条', '58682':'呢', }
async function sleep(ms){
    return new Promise(resolve => setTimeout(resolve, ms));
}
function xml(type, src) {
    const xhr = new XMLHttpRequest();
    xhr.open(type, src);
    xhr.overrideMimeType('text/plain; charset=utf-8');
    xhr.onload = function () {
        if (xhr.status === 200) {
            try {
                const responseText = xhr.responseText;
                let content = responseText.split('content noselect"><div>')[1]
                    .split('</div><p>')[0]
                    .replaceAll('<p>', '')
                    .replaceAll('</p>', '\n');
                var decoded = decode(content);
                data += responseText.split('<title>')[1]
                    .split('在线免费阅读_番茄小说官网<')[0] + '\n' + decoded;
            } catch (error) {
                console.error('处理响应内容时出错:', error);
            }
        }
    };
    xhr.send();
}

function decode(content) {
    var newdata = '';
    for (let x of content) {
        if (String(x).charCodeAt(0) in unicode_data == true) {
            newdata += unicode_data[String(x).charCodeAt(0)];
        } else {
            newdata += String(x);
        }
    }
    return newdata;
}
async function dispose(children,type){
    if(onstop==true)return;
    if(type=='phone'){
    if(children.className.includes('volume')){
        data+=children.innerText.trim()+'\n';
        num+=1
    }else{
        xml('GET',children.children[0].href)
        console.log('第'+num+'卷 '+children.innerText.split(' ')[0]+'下载完成')
    }
    }else{
        data+=children.children[0].innerText.trim()+'\n'
        for(let x of children.children[1].children){
            xml('GET',x.children[0].href)
            console.log(children.children[0].innerText.split(':')[0]+' '+x.innerText.split(' ')[0]+'下载完成')
            await sleep(120)
        }
    }
}
    function download(name, text) {
        var dld = document.createElement('a');
        dld.setAttribute('href', 'data:text/plain;charset=utf-8,'+encodeURIComponent(text));
        dld.setAttribute('download', name);
        dld.click();
    }
    async function downloadd(){
        var numd=data.length/document.querySelector('.widget input').value
        if(data[numd]!==undefined){
            var data1=data.split(data[numd-2]+data[numd-1]+data[numd]+data[numd+2]+data[numd+2])
            if(data1.length>=document.querySelector('.widget input').value+1||data1.length<=1){
                alert('分卷进行不了,选择其他数量或等下一个版本')
            }else{
                for(let x=0;x<Number(document.querySelector('.widget input').value);x++){
                    download(window.__INITIAL_STATE__.page.bookName+'(第'+(x+1)+'卷)',window.__INITIAL_STATE__.page.bookName+"\n此文件由番茄小说阅读辅助器下载https://greasyfork.org/zh-CN/scripts/521377-番茄小说阅读辅助器\n请支持正版番茄小说\n作者:"+window.__INITIAL_STATE__.page.bookName,window.__INITIAL_STATE__.page.author+'\n'+data1[x]);
                    console.log('第'+(x+1)+'卷下载成功')
                    await sleep(500)
                }
            }
        }else {download(window.__INITIAL_STATE__.page.bookName,window.__INITIAL_STATE__.page.bookName+"\n此文件由番茄小说阅读辅助器下载https://greasyfork.org/zh-CN/scripts/521377-番茄小说阅读辅助器\n请支持正版番茄小说\n作者:"+window.__INITIAL_STATE__.page.author+'\n'+data)}
        alert('下载完成') 
 gui.domElement.children[1].children[0].children[1].children[2].remove()
        await sleep(1000)
        data=''
    }
    function move(){
        var guid=gui.domElement
        gui.domElement.children[0].onmousedown=function(e) {
            window.onmove=true
        }
        document.onmouseup=function(e) {
            if(Number(guid.style.left.replace('px',''))<0)guid.style.left='0px';
            if(Number(guid.style.top.replace('px',''))<0)guid.style.top='0px';
            window.onmove=false
        }
        document.onmousemove=function(e){
            if(window.onmove==true){
                guid.style.top=e.clientY-15+'px';
                guid.style.left=e.clientX-15+'px'
            }
        }
        guid.onmouseover=function(){
            if(!guid.children[0].innerText.includes('右'))guid.children[0].innerText+=' (右键可移动)';
        }
        guid.onmouseout=function(){
            guid.children[0].innerText='番茄阅读辅助器'
        }
    }
    var main = {
        "copybook" : async()=>{
            data=''

            if(location.href.includes('force_mobile=1')){
                alert('正在整理书籍目录,请稍等...')
            if(document.querySelector('.page-directory-order').innerText=='倒序'){
                document.querySelector('.page-directory-order').click()
            }
            setInterval(()=>{
                if(document.querySelector('.page-directory-more')){
                    document.querySelector('.page-directory-more').click()
                }else{
                    clearInterval()
                }
            },200);
            await sleep(1000)
            alert('请等待提示,现开始复制\n可通过控制台查看进度')
            page1.add(main,'stop').name('暂停下载')
            for(let x of document.querySelector('.page-directory-content').children){
                await dispose(x,'phone')
                await sleep(120)
                if(document.querySelector('.page-directory-content').children[document.querySelector('.page-directory-content').children.length-1]==x){
                    await downloadd()
                }

            }
            }else{
                page1.add(main,'stop').name('暂停下载')
                alert('请等待提示,现开始复制\n可通过控制台查看进度')
                  globalThis.a=document.querySelector('.page-directory-content')
                  for(let x of a.children){
                      await dispose(x,'computer')
                      await sleep(120)
                  }
                  await downloadd()
            }
        },
        "a":1,
        "stop":async()=>{
            onstop=true
            alert('已暂停')
            gui.domElement.children[1].children[0].children[1].children[2].innerText='已暂停'
            await sleep(5000)
            gui.domElement.children[1].children[0].children[1].children[2].remove()
        }
    };
    window.gui = new lil.GUI({ title: '番茄阅读辅助器' });
    window.gui.domElement.style.userSelect = 'none';
    move()
    var page1 = gui.addFolder('复制')
    var text='(电脑版)'
    if(location.href.includes('force_mobile=1'))text='(手机版)'
    if(location.href.includes('/page/')){
        page1.add(main,'copybook').name('复制本书全文 '+text)
        page1.add(main,'a').min(1).name('分卷下载')
    }
})();