Đăng Nhập

Vui lòng khai báo chính xác tên truy cập và mật khẩu!

Quên mật khẩu?

Đăng Ký

Bạn phải điền đầy đủ thông tin đăng ký!

  


Search found 1 match for truyencv

[Userscript] TruyenCV downloader - 09.08.16 14:24

Tải truyện từ TruyenCV.com định dạng htm. Sau đó, bạn có thể dùng Mobipocket Creator để tạo ebook prc.


Demo


Topics tagged under truyencv on Zzbaivong forumvi Truyen10
Tải truyện từ TruyenCV


Cài đặt


Dùng một trong các link sau:

  1. https://greasyfork.org/vi/scripts/17826-truyencv-downloader
  2. https://openuserjs.org/scripts/baivong/TruyenCV_downloader
  3. https://github.com/baivong/Userscript/raw/master/truyenCV_downloader/truyenCV_downloader.user.js


Mã nguồn


Code:
// ==UserScript==
// @id           truyencv-downloader@devs.forumvi.com
// @name         TruyenCV downloader
// @namespace    http://devs.forumvi.com/
// @description  Tải truyện từ truyencv.com định dạng html. Sau đó, bạn có thể dùng Mobipocket Creator để tạo ebook prc
// @version      1.1.7
// @icon         http://i.imgur.com/o5cmtkU.png
// @author       Zzbaivong
// @license      MIT
// @icon         http://truyencv.com/templates/truyencv/images/logo.png
// @match        http://truyencv.com/*/
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js
// @require      https://greasyfork.org/scripts/18532-filesaver/code/FileSaver.js?version=117790
// @noframes
// @connect      truyencv.com
// @supportURL   https://github.com/baivong/Userscript/issues
// @run-at       document-idle
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function ($, window, document, undefined) {

    'use strict';

    function downloadFail(url) {

        console.log('%cError: ' + url, 'color:red;');
        $download.text('Resume...').css('background', 'red');
        disableClick = false;

    }

    function downloadComplete() {

        var skipSize = skip.length,
            blob,
            fileName = path.slice(1, -1) + '_' + begin + '-' + end + '.htm';

        txt = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1><font color="red">' + $('h1').text() + '</font></h1><h3><font color="blue">' + $('#poster p:eq(3)').text() + '</font></h3><h3><font color="green">' + $('#poster p:eq(4)').text() + '</font></h3><h3><font color="gray">Tổng số chương: ' + (end - begin - skipSize + 1) + '</font></h3><br><br>' + credits + '<br><br><br>' + txt + '</body></html>';

        blob = new Blob([txt], {
            type: 'text/html'
        });

        $download.attr({
            href: window.URL.createObjectURL(blob),
            download: fileName
        }).text('Download Finished!').css('background', 'green').off('click');

        if (skipSize) {
            console.log('%cLinks skipped: ' + skip.join(','), 'color:orange;');
        }

        console.log('%cDownload Finished!', 'color:blue;');

        saveAs(blob, fileName);

    }

    function getChapter() {

        if (count > max) {

            if (complete) {
                downloadComplete();
            } else {

                enablePrompt = true;
                disableClick = false;
                $download.text('Nothing!').css('background', 'red');
                console.log('%cNothing!', 'color:red;');

            }

            $(window).off('beforeunload');

        } else {

            url = path + 'chuong-' + count;

            GM_xmlhttpRequest({
                method: 'GET',
                url: url,
                onload: function (response) {

                    var $data = $(response.responseText),
                        title = $data.find('h2.text-muted').html(),
                        $chapter = $data.find('.chapter');

                    if ($chapter.length) {

                        $download.text(count + '/' + max).css('background', 'orange');

                        if (response.finalUrl.slice(-8) === '/chuong/') {

                            $download.css('background', 'black');
                            console.log('%cSkip: ' + url, 'color:orange;');
                            skip.push(count);
                            ++count;
                            getChapter();
                            return;

                        }

                        console.log('%cComplete: ' + url, 'color:green;');
                        ++count;
                        ++complete;

                    } else {
                        downloadFail(url);
                    }

                    $chapter.find('font, p:last').remove();
                    txt += '<h2 class="title">' + title + '</h2>' + $chapter.html();

                    getChapter();

                },
                onerror: function (err) {

                    downloadFail(url);
                    console.error(err);

                }
            });

        }

    }


    var $download = $('[href="#dsc"]'),
        count = 1,
        max = parseInt($('.listchapter').eq($('.listchapter').length - 2).find('.latestchaper').eq(0).find('a').attr('href').match(/chuong-(\d+)/)[1], 10),
        begin,
        end,
        skip = [],
        txt = '',
        enablePrompt = true,
        disableClick = false,
        complete = 0,
        path = location.pathname,
        url,
        credits = '<p>Truyện được tải từ: TruyenCV - http://truyencv.com</p><p>Userscript được viết bởi: Zzbaivong - http://devs.forumvi.com</p>';

    window.URL = window.URL || window.webkitURL;

    $download.text('Download').css('background', 'orange').on('click', function (e) {

        e.preventDefault();

        if (disableClick) {
            return;
        }

        if (enablePrompt) {

            begin = prompt('Chọn Chương bắt đầu tải', count);
            end = prompt('Chọn Chương kết thúc tải', max);

            if (begin !== null && /^\d+$/.test(begin)) {
                begin = parseInt(begin, 10);
                count = begin;
            } else {
                begin = count;
            }

            if (end !== null && /^\d+$/.test(end)) {
                end = parseInt(end, 10);
                if (end > count) {
                    max = end;
                } else {
                    max = count;
                    end = count;
                }
            } else {
                end = max;
            }

            $(window).on('beforeunload', function () {
                return 'Truyện đang được tải xuống...';
            });

            enablePrompt = false;

        }

        getChapter();

        disableClick = true;

    });

})(jQuery, window, document);



Hướng dẫn


Tải truyện


Script hoạt động sẽ tạo ra nút Download tại trang giới thiệu truyện. Click vào để tải truyện xuống. Bạn cũng có thể theo dõi quá trình trong Console (F12 > console), nếu chương truyện lỗi sẽ hiện link màu đỏ.
Khi quá trình tải hoàn tất, định dạng file tải xuống là ten-truyen.htm.

Tạo Ebook


Tải phần mềm Mobipocket Creator.
Sau khi cài đặt, chạy Mobipocket Creator, trong mục Import From Exiting File, nhấp vào HTML document.

Tại trang Import from HTML document:

  1. Choose a file: Nhấn Browse..., chọn file truyện bạn vừa tải trước đó.
  2. Create publication in folder: Đây là vị trí chứa ebook sau khi tạo, nên để mặc định.
  3. Language: Chọn Vietnamese.
  4. Encoding: Chọn UTF-8.

Nhấn nút Import.

Để tạo mục lục cho các chương truyện, chọn mục Table of contents, nhấn nút Add a Table of contents.
Bạn điền vào 3 ô trên dòng First level lần lượt là:

  1. Tagname: h2
  2. Attribute: class
  3. Value: title

Nhấn nút Update.

Đến đây bạn đã hoàn thành những việc cần thiết để tạo Ebook, Nhấn menu Build(F7) ở phía trên, sau đó chọn nút Build ở trang hiện ra để tạo Ebook định dạng prc. File này sẽ được lưu ở thư mục bạn chọn ở Create publication in folder. Trong thư mục này còn chứa một số file cấu hình khác, bạn có thể xóa chúng đi.
Nếu muốn chỉnh Ebook chi tiết hơn, trước khi build, bạn có thể điều chỉnh 2 mục Conver ImageMetadata. Nhớ nhấn nút Update sau khi điều chỉnh.


Chú ý


Nếu cần chuyển đổi sang định dạng khác như .epub, .mobi, ... để đọc trên điện thoại, máy đọc sách, ... bạn có thể dùng công cụ trực tuyến như ToePub, Zamzar. Hoặc, dùng phần mềm Calibre, Hamster ebook converter.
Trang TruyenCV hầu hết là truyện convert do thành viên đóng góp, nhiều truyện hơi khó đọc nếu chưa quen. Bạn có thể tìm bên TruyenYY, dùng script TruyenYY downloader.


Credits


  1. Eligrey

Tags: #firefox #userscript #chromium #truyencv #download #ebook


Back to top