TangThuVien downloader

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

  1. // ==UserScript==
  2. // @name TangThuVien downloader
  3. // @namespace https://nntoan.com/
  4. // @description Tải truyện từ truyen.tangthuvien.vn định dạng epub.
  5. // @version 1.1.2
  6. // @icon https://i.imgur.com/rt1QT6z.png
  7. // @author Toan Nguyen
  8. // @oujs:author nntoan
  9. // @license MIT; https://nntoan.mit-license.org/
  10. // @supportURL https://github.com/nntoan/UserScripts/issues
  11. // @match http://truyen.tangthuvien.vn/doc-truyen/*
  12. // @match https://truyen.tangthuvien.vn/doc-truyen/*
  13. // @require https://unpkg.com/jszip@3.2.1/dist/jszip.min.js
  14. // @require https://unpkg.com/ejs@2.6.1/ejs.min.js
  15. // @require https://unpkg.com/jepub@2.1.0/dist/jepub.min.js
  16. // @require https://unpkg.com/file-saver@2.0.2/dist/FileSaver.min.js
  17. // @connect self
  18. // @run-at document-idle
  19. // @noframes
  20. // ==/UserScript==
  21. /*global console, location*/
  22. (function ($, window, document) { // eslint-disable-line
  23. 'use strict';
  24. $(document).ready(function() {
  25. $.widget('nntoan.mbDownloader', $.nntoan.mbDownloader, {
  26. _create: function () {
  27. var self = this;
  28. this._super();
  29. // Extending options
  30. this.options.processing.ebookFileName = this.options.general.pathname.slice(12);
  31. this.options.xhr.chapter.data = $.extend(this.options.xhr.chapter.data, {
  32. story_id: self.elements.$novelId.val()
  33. });
  34. this.options.xhr.content.url = this.options.general.pathname + this.options.chapters.chapId + '/';
  35. this.elements.$downloadBtn.css('margin-top', '10px');
  36. console.time('downloadAndGenerateEpub');
  37. }
  38. });
  39. $(this).mbDownloader({
  40. readyToInit: true,
  41. processing: {
  42. ebookFileExt: '.epub'
  43. },
  44. classNames: {
  45. novelId: '#story_id_hidden',
  46. infoBlock: '.book-detail-wrap',
  47. chapterContent: '.box-chap:not(.hidden)',
  48. chapterNotContent: 'iframe, script, style, a, div, p:has(a[href*="truyen.tangthuvien.vn"])',
  49. chapterVip: '#btnChapterVip',
  50. chapterTitle: 'h2',
  51. ebookTitle: 'h1',
  52. ebookAuthor: '#authorId',
  53. ebookCover: '#bookImg',
  54. ebookDesc: '.book-intro',
  55. ebookType: '.tag-wrap a',
  56. downloadBtnStatus: 'btn-primary btn-success btn-info btn-warning btn-danger blue success warning info danger error',
  57. downloadAppendTo: '.book-info p:last-child',
  58. },
  59. ebook: {
  60. fallbackCover: 'https://truyen.tangthuvien.vn/images/default-book.png'
  61. },
  62. chapters: {
  63. chapListSlice: [6, -1],
  64. },
  65. xhr: {
  66. chapter: {
  67. type: 'GET',
  68. url: '/story/chapters',
  69. },
  70. content: {
  71. type: 'GET',
  72. xhrFields: {
  73. withCredentials: true
  74. }
  75. }
  76. },
  77. bookInfoUpdated: function (event, data) {
  78. console.log('Book information updated...', data.epubInfo);
  79. },
  80. chapTitleUpdated: function(event, data) {
  81. console.log('Chapter: ' + data.chapNum + ' downloaded...');
  82. },
  83. beforeCreateEpub: function(event, that) {
  84. console.log('Prepare generate epub...');
  85. },
  86. complete: function(event, that) {
  87. console.log('Epub downloaded successfully. Please check your Downloads folder.');
  88. console.timeEnd('downloadAndGenerateEpub');
  89. }
  90. });
  91. });
  92. })(jQuery, window, document); // eslint-disable-line