Greasy Fork

Greasy Fork is available in English.

wanbentxt

https://m.wanbentxt.com/ 的小说下载

当前为 2019-08-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         wanbentxt
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  https://m.wanbentxt.com/ 的小说下载
// @author       You
// @match        https://m.wanbentxt.com/*
// @require      http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/FileSaver.min.js
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function () {
    'use strict';


    var DivInited = false;
    var WCContent, WCWords, WCQuit, WCSave, WCContinue;
    var pagenum = 0, chapternum = 0;
    var title, Id, authior, desc;
    var listpage = [];
    var oldurl = 'null';

    function initDiv() {
        console.log("initDiv");
        if (DivInited) return;
        DivInited = true;
        var content = document.createElement("div");
        document.body.appendChild(content);
        content.outerHTML = `
      <div id="CWDownContent" >
        <div style="width:360px;height:100px;position:fixed;left:50%;top:50%;margin-top:-50px;margin-left:-180px;z-index:100000;background-color:#ffffff;border:1px solid #afb3b6;opacity:0.95;filter:alpha(opacity=95);box-shadow:5px 5px 20px 0px#000;">
          <div id="CWDownWords" style="font-size:12px;position:absolute;width:290px;height:90px;padding: 8px;border-radius: 10px;float: left;">
          </div>
          <div style="float: right;">
            <div id="CWDownSave" style="width:43px;height:26px;cursor: pointer;background-color:#3169da;margin: 5px 5px 3px 3px;">
              <span style="line-height:25px;display:block;color:#FFF;text-align:center;font-size:14px;">保存</span>
            </div>
            <div id="CWDownQuit" style="width:43px;height:26px;cursor: pointer;background-color:#3169da;margin: 3px;">
              <span style="line-height:25px;display:block;color:#FFF;text-align:center;font-size:14px;">取消</span>
            </div>
            <div id="CWCContinue" style="width:43px;height:26px;cursor: pointer;background-color:#3169da;margin: 3px;">
            <span style="line-height:25px;display:block;color:#FFF;text-align:center;font-size:14px;">繼續</span>
          </div>
          </div>
        </div>
      </div>
      `;

        WCContent = document.querySelector("#CWDownContent");
        WCWords = document.querySelector("#CWDownWords");
        WCQuit = document.querySelector("#CWDownQuit");
        WCSave = document.querySelector("#CWDownSave");
        WCContinue = document.querySelector("#CWCContinue");
        WCContinue.style.display = "none";

        WCQuit.onclick = function () {
            DivInited = false;
            WCContent.style.display = "none";
            WCWords.innerHTML = '';
            WCContent.parentNode.removeChild(WCContent);
        };
        WCContinue.onclick = function () {
        };
        WCSave.onclick = function () {
            SaveText();
        };
    }

    function ShowWords(value) {
        WCWords.innerHTML = (title ? title + '<br>' : '') + value;
    }

    function inits() {
        var content = document.createElement("div");
        document.body.appendChild(content);
        content.outerHTML = `
        <div id="initsContent">
        <div style="width:40px;height:25px;position:fixed;left:10PX;top:10PX;z-index:100000;/*! background-color:#ffffff; *//*! border:1px solid #afb3b6; *//*! opacity:0.95; */filter:alpha(opacity=95);">
          <div id="initsSave" style="/*! width:43px; *//*! height:26px; */cursor: pointer;background-color:#3169da;/*! margin: 2px 5px 3px 10px; */">
            <span style="line-height:25px;display:block;color:#FFF;text-align:center;font-size: 10px;">下载</span>
          </div>
        </div>
        </div>
`;

        var initsSave = document.querySelector("#initsSave");

        initsSave.onclick = function () {
            initDiv();
            run();
        }
    }

    function getElementRootText(element) {
        let ret = "";
        for (const i of element.childNodes) {
            if (i.nodeType === i.TEXT_NODE || i.nodeName == 'T') {
                ret += i.nodeValue + '\r\n';
            }
        }
        return ret.replace(/^\s+|\s+$/g, "");
    }

    async function gethtml(url) {
        return new Promise((resolve, reject) => {
            GM_xmlhttpRequest(
                {
                    url: url,
                    method: "GET",
                    onload: function (response) {
                        resolve(response.responseText);
                    }
                });
        });
    }


    async function getpage(pageurl) {
        if (!pageurl) return;
        pagenum++;
        let pagestr = await gethtml(pageurl);
        let pagedoc = $('<html></html>');
        pagedoc.html(pagestr);
        var lista = pagedoc.find('.chapterList > ul>a');
        console.log(lista);

        for (let i = 0; i < lista.length; i++) {
            chapternum++;
            ShowWords(`正在下载<br>第${pagenum}页<br>第${chapternum}章节`)
            let url = lista[i].href;
            console.log(url);
            let str = await gethtml(url);
            let doc = $('<html></html>');
            doc.html(str);
            let title = doc.find('.readerTop h3').text();
            let content = doc.find('.raderCon');
            //console.log(content);
            /*             let listtxt = [];
                        for (const i of doc[0].querySelectorAll(".raderCon")) {
                            let line = getElementRootText(i);
                            console.log(line);
                            listtxt.push(line);
                        }
                        listpage.push({ title: title, content: listtxt.join('\r\n') }) */

            let value = content.html();
            //console.log(value);

            value = value.replace(/<br>/g, "\r\n");
            value = value.replace(/一秒记住.*?找不到书请留言!/, '');
            value = value.replace(/一秒记住.*?m.wanbentxt.com/, '');
            value = value.replace(/支持.*?找不到书请留言!/, '');
            value = value.replace(/支持.*?你们的宣传支持就是最的动力/, '');
            value = value.replace(/支持.*?你们的支持就是大大的动力!/, '');
            value = value.replace(/支持.*?分享给你们的好友!/, '');
            value = value.replace(/【完本神站】.*?永不丢失!/, '');
            value = value.replace('更多绝版完结好文搜索', '');
            value = value.replace('书荒就搜', '');


            value = value.replace(/&amp;/g, "&");
            value = value.replace(/&lt;/g, "<");
            value = value.replace(/&gt;/g, ">");
            value = value.replace(/&nbsp;/g, " ");
            value = value.replace(/&quot/g, "'");

            value = value.replace(/<[^<>]+?>/g, '');

            value = value.replace(/完[\s\S]{0,8}本[\s\S]{0,8}神[\s\S]{0,8}站/, '');

            //console.log(value);

            listpage.push({ title: title, content: value });

        }

        var next = pagedoc.find('.page > a:nth-child(3)');
        if (next.length > 0) {
            let nexturl = 'https://m.wanbentxt.com' + next.attr('href');
            if (oldurl != nexturl) {
                oldurl = nexturl;
                console.log(nexturl);
                await getpage(nexturl);
            } else {
                console.log('end');
                console.log(listpage);
            }
        }

    }

    async function gettitle() {
        var m = /m\.wanbentxt\.com\/(\w+)/.exec(location.href);
        console.log(m);
        if (m) {
            Id = m[1];
            let Idurl = 'https://m.wanbentxt.com/' + Id + '/';
            let Idstr = await gethtml(Idurl);
            let Iddoc = $('<html></html>');
            Iddoc.html(Idstr);
            desc = Iddoc.find('.bookInfo').text();
            authior = Iddoc.find('.bookPhrMid p:nth-child(1)').text();
            title = Iddoc.find('.bookPhr h2').text();
            return 'https://m.wanbentxt.com/' + Id + '/all.html'
        }
        return null;
    }


    async function run() {

        let reurl = await gettitle();

        await getpage(reurl);
        console.log('end');
        SaveText();
    }

    function SaveText() {
        if (!listpage || listpage.length == 0) return;

        let save = [];
        $.each(listpage, function (index, value) {
            save.push(value.title + '\r\n' + value.content + '\r\n\r\n');
        });
        ShowWords(`已下载完成<br>共${pagenum}页<br>共${chapternum}章节`)
        var blob = new Blob([title, "\r\n", authior, "\r\n", desc, "\r\n\r\n", save.join('\r\n')], { type: "text/plain;charset=utf-8" });
        saveAs(blob, title + '.txt');
    }

    inits();



})();