番茄全文在线免费读

番茄小说免费网页阅读 不用客户端 可下载小说

目前為 2023-10-04 提交的版本,檢視 最新版本

// ==UserScript==
// @name              番茄全文在线免费读
// @namespace         https://shequ.codemao.cn/user/2856172
// @namespace         https://github.com/ibxff
// @version           1.0
// @description       番茄小说免费网页阅读 不用客户端 可下载小说
// @description:zh-cn 番茄小说免费网页阅读 不用客户端 可下载小说
// @description:en    Fanqien Novel Reading, No Need for a Client, Novels Available for Download
// @author            ibxff
// @license           MIT License
// @match             https://fanqienovel.com/*
// @require           https://unpkg.com/[email protected]/dist/FileSaver.min.js
// @icon              https://static.box3.codemao.cn/block/QmWXABqpkiyqwsMnLAkRaZtEEo14YrrpYJgHdAnZeNXemN
// @grant             GM_xmlhttpRequest
// ==/UserScript==

const styleElement = document.createElement("style");
const cssRule = `
    @keyframes hideAnimation {
      0% {
        opacity: 1;
      }
      50% {
        opacity: 0.75;
      }
      100% {
        opacity: 0;
        display: none;
      }
    }

    option:checked {
        background-color: #ffb144;
        color: white;
    }
    `;

styleElement.innerHTML = cssRule;
document.head.appendChild(styleElement);

function hideElement(ele) {
  ele.style.animation = "hideAnimation 1.5s ease";
  ele.addEventListener("animationend", function () {
    ele.style.display = "none";
  });
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

const mark=(ele)=>ele.style.boxShadow = "0px 0px 50px rgba(0, 0, 0, 0.2)";

(function() {
    'use strict';
    switch(window.location.href.match(/\/([^/]+)\/\d/)[1]){
        case 'reader':
            const div=document.querySelector("#app > div > div > div > div.reader-toolbar > div > div.reader-toolbar-item.reader-toolbar-item-download")
            const text=div.querySelector('div:nth-child(2)')
            mark(div)
            div.querySelector('div:nth-child(2)').innerHTML='处理中'

            document.title=document.title.replace(/在线免费阅读_番茄小说官网$/, '')

            var currentURL=window.location.href
            setInterval(() => window.location.href !== currentURL ? location.reload() : null, 1000);

            const url = window.location.href;
            const regex = /\/(\d+)/;
            const match = url.match(regex);
            const extractedId = match[1];
            const apiUrl = `https://novel.snssdk.com/api/novel/book/reader/full/v1/?device_platform=android&parent_enterfrom=novel_channel_search.tab.&aid=2329&platform_id=1&group_id=${extractedId}&item_id=${extractedId}`;

            GM_xmlhttpRequest({
                method: "GET",
                url: apiUrl,
                onload: function(response) {
                    if (response.status === 200) {
                        const data = JSON.parse(response.responseText);
                        const content = data.data.content;
                        console.log(content);
                        document.getElementsByClassName('muye-to-fanqie')[0] ?. remove()
                        const regex = /<article>([\s\S]*?)<\/article>/;
                        const match = content.match(regex)[1]
                        document.getElementsByClassName('muye-reader-content noselect')[0].innerHTML=match

                        div.style.backgroundColor='#B0E57C'
                        text.innerHTML='成功'
                        hideElement(div)
                    }
                },
                onerror: function(error) {
                    div.style.backgroundColor='pink'
                    text.innerHTML='失败'
                    hideElement(div)
                    console.error(`Fetch error: ${error}`);
                }
            });
     break;

     case 'page':

            const title = document.querySelector("#app > div > div.muye.muye-page > div > div.page-wrap > div > div.page-header-info > div.info > div.info-name > h1").innerHTML
            var content='使用油猴插件(番茄小说读或下全文)下载\n'+
                        +document.querySelector("#app > div > div.muye.muye-page > div > div.page-wrap > div > div.page-header-info > div.info > div.info-name > h1").innerHTML+'\n'
                        +document.getElementsByClassName('page-header-info')[0].textContent
                        .replace('继续阅读').replace('下载番茄小说').replace('开始阅读').replace('*下载全本')
                       +'\n'+document.querySelector("#app > div > div.muye.muye-page > div > div.page-body-wrap > div > div.page-abstract-content > p").innerHTML
            content.replace('undefined').replace('null').replace('NaN')
            console.log(content)

            sleep(1500).then(()=>{
            document.querySelector("#app > div > div.muye.muye-page > div > div.page-wrap > div > div.page-header-info > div.info > div.download-icon.muyeicon-tomato").remove()
            const download=document.querySelector("#app > div > div.muye.muye-page > div > div.page-wrap > div > div.page-header-info > div.info > a")
            download.querySelector('button > span').innerHTML='*下载全本'
            download.href='javascript:void 0'


            const parentElement = document.querySelector("#app > div > div.muye.muye-page > div > div.page-wrap > div > div.page-header-info > div.info");
            const selectElement = document.createElement("select");
            selectElement.className = "byte-btn byte-btn-primary byte-btn-size-large byte-btn-shape-square muye-button";
            const options = [
                {text: "UTF-8" },
                {text: "GBK" },
                {text: "UNICODE" },
                {text:'UTF-16'},
                {text:'ASCII'}
            ];
            options.forEach(function(optionData) {
                var option = document.createElement("option");
                option.text = optionData.text;
                option.value= optionData.text
                selectElement.appendChild(option);
            });
            selectElement.style.position = "absolute";
            selectElement.style.left = "320px";
            selectElement.style.bottom = "0px";
            selectElement.style.height = "32px";
            selectElement.style.width = "80px";
            selectElement.style.fontSize = "15px";
            parentElement.appendChild(selectElement);


            const books=Array.from(document.getElementsByClassName('chapter-item'))
            //books.shift()
            //var index=0
            var accomplish=false

            function next(){
                const ele=books[0].querySelector('a')
                ele.style.border = "3px solid navajowhite"
                ele.style.borderRadius = "5px"
                ele.style.backgroundColor = "navajowhite"
                const url = ele.href;
                console.log(url)
                const regex = /\/(\d+)/;
                const match = url.match(regex);
                const extractedId = match[1];
                const apiURL = `https://novel.snssdk.com/api/novel/book/reader/full/v1/?device_platform=android&parent_enterfrom=novel_channel_search.tab.&aid=2329&platform_id=1&group_id=${extractedId}&item_id=${extractedId}`;

                content+='\n\n'+ele.innerHTML+'\n'
                GM_xmlhttpRequest({
                    method: "GET",
                    url: apiURL,
                    onload: function(response) {
                        if (response.status === 200) {
                            const data = JSON.parse(response.responseText);
                            const rcontent = data.data.content;
                            const regex = /<article>([\s\S]*?)<\/article>/;
                            const match = rcontent.match(regex)[1]
                            content+=match.replace(/<\/p>/g,'\n').replace(/<\w+>/g,'')
                            ele.style.backgroundColor='#D2F9D1'
                            ele.style.border = "2px solid #D2F9D1"
                            //index+=1
                            books.shift()
                            console.log(books)
                            if(!books.length){
                                console.log('执行完成 开始保存')
                                const charset=selectElement.value
                                console.log(charset)
                                const blob = new Blob([new TextEncoder(charset).encode(content)], { type: `text/plain;charset=`+charset });
                                saveAs(blob, title+".txt");
                                return
                            }
                            else{
                                next()
                            }
                         }
                    },
                    onerror: function(error) {
                        hideElement(div)
                        console.error(`Fetch error: ${error}`);
                        ele.style.backgroundColor='pink'
                        ele.style.border = "2px solid pink"
                        //index+=1
                        next()
                    }
                });
             }
             download.addEventListener('click',next)
             download.addEventListener('click',()=>{download.style.display='none';selectElement.style.display='none'})

            })
      break;


    }
}
)();