TangThuVien downloader

Tải truyện từ truyen.tangthuvien.vn định dạng epub.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TangThuVien downloader
// @namespace    https://nntoan.com/
// @description  Tải truyện từ truyen.tangthuvien.vn định dạng epub.
// @version      1.1.2
// @icon         https://i.imgur.com/rt1QT6z.png
// @author       Toan Nguyen
// @oujs:author  nntoan
// @license      MIT; https://nntoan.mit-license.org/
// @supportURL   https://github.com/nntoan/UserScripts/issues
// @match        http://truyen.tangthuvien.vn/doc-truyen/*
// @match        https://truyen.tangthuvien.vn/doc-truyen/*
// @require      https://unpkg.com/[email protected]/dist/jszip.min.js
// @require      https://unpkg.com/[email protected]/ejs.min.js
// @require      https://unpkg.com/[email protected]/dist/jepub.min.js
// @require      https://unpkg.com/[email protected]/dist/FileSaver.min.js     
// @connect      self
// @run-at       document-idle
// @noframes
// ==/UserScript==
/*global console, location*/
(function ($, window, document) { // eslint-disable-line
    'use strict';
 
    $(document).ready(function() {
        $.widget('nntoan.mbDownloader', $.nntoan.mbDownloader, {
            _create: function () {
                var self = this;
                this._super();
 
                // Extending options
                this.options.processing.ebookFileName = this.options.general.pathname.slice(12);
                this.options.xhr.chapter.data = $.extend(this.options.xhr.chapter.data, {
                    story_id: self.elements.$novelId.val()
                });
                this.options.xhr.content.url = this.options.general.pathname + this.options.chapters.chapId + '/';
                this.elements.$downloadBtn.css('margin-top', '10px');
 
                console.time('downloadAndGenerateEpub');
            }
        });
 
        $(this).mbDownloader({
            readyToInit: true,
            processing: {
                ebookFileExt: '.epub'
            },
            classNames: {
                novelId: '#story_id_hidden',
                infoBlock: '.book-detail-wrap',
                chapterContent: '.box-chap:not(.hidden)',
                chapterNotContent: 'iframe, script, style, a, div, p:has(a[href*="truyen.tangthuvien.vn"])',
                chapterVip: '#btnChapterVip',
                chapterTitle: 'h2',
                ebookTitle: 'h1',
                ebookAuthor: '#authorId',
                ebookCover: '#bookImg',
                ebookDesc: '.book-intro',
                ebookType: '.tag-wrap a',
                downloadBtnStatus: 'btn-primary btn-success btn-info btn-warning btn-danger blue success warning info danger error',
                downloadAppendTo: '.book-info p:last-child',
            },
            ebook: {
                fallbackCover: 'https://truyen.tangthuvien.vn/images/default-book.png'
            },
            chapters: {
                chapListSlice: [6, -1],
            },
            xhr: {
                chapter: {
                    type: 'GET',
                    url: '/story/chapters',
                },
                content: {
                    type: 'GET',
                    xhrFields: {
                        withCredentials: true
                    }
                }
            },
            bookInfoUpdated: function (event, data) {
                console.log('Book information updated...', data.epubInfo);
            },
            chapTitleUpdated: function(event, data) {
                console.log('Chapter: ' + data.chapNum + ' downloaded...');
            },
            beforeCreateEpub: function(event, that) {
                console.log('Prepare generate epub...');
            },
            complete: function(event, that) {
                console.log('Epub downloaded successfully. Please check your Downloads folder.');
                console.timeEnd('downloadAndGenerateEpub');
            }
        });
    });
})(jQuery, window, document); // eslint-disable-line