BachNgocSach downloader

Tải truyện từ bachngocsach.com định dạng epub

  1. // ==UserScript==
  2. // @name BachNgocSach downloader
  3. // @namespace https://nntoan.com/
  4. // @description Tải truyện từ bachngocsach.com định dạng epub
  5. // @version 1.0.1
  6. // @icon http://i.imgur.com/3lomxTC.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://bachngocsach.com/reader/*
  12. // @match https://bachngocsach.com/reader/*
  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. // @require https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js
  18. // @require https://cdn.jsdelivr.net/npm/mbdownloader@0.2.4/src/mbDownloader.js
  19. // @connect self
  20. // @run-at document-idle
  21. // @noframes
  22. // ==/UserScript==
  23. /*global console, location*/
  24. (function ($, window, document) {
  25. 'use strict';
  26.  
  27. $(document).ready(function () {
  28. $.widget('nntoan.mbDownloader', $.nntoan.mbDownloader, {
  29. _create: function () {
  30. this._super();
  31.  
  32. // Extending options
  33. this.options.processing.ebookFileName = this.options.general.pathname.slice(8);
  34. this.options.xhr.chapter.url = this.options.xhr.chapter.url + $(this.options.classNames.chapterList).attr('href');
  35. this.options.xhr.chapter.data = $.extend(this.options.xhr.chapter.data, {
  36. page: 'all'
  37. });
  38.  
  39. // Styling download button for current site
  40. this.elements.$downloadBtn.attr('class', 'truyen-button');
  41. this.elements.$downloadBtn.css({ 'background': '#f4b759', 'border-color': '#eb813d' });
  42.  
  43. console.time('downloadAndGenerateEpub');
  44. },
  45.  
  46. /**
  47. * Update CSS of download button.
  48. *
  49. * @param {String} status Download status
  50. * @returns void
  51. */
  52. downloadStatus: function (status) {
  53. this._super(status);
  54. this.elements.$downloadBtn.css({ 'background': '#e05d59', 'color': '#ffffff !important', 'border-color': '#c83e35' });
  55. },
  56.  
  57. /**
  58. * Callback function to handle chap list values.
  59. *
  60. * @param {Object} options
  61. * @param {String} val
  62. * @returns {String}
  63. */
  64. chapListValueFilter: function (options, val) {
  65. val = this._super(options, val);
  66. val = val.replace(location.protocol + '//' + location.host, '');
  67. if (val.indexOf(location.pathname) === -1) {
  68. val = '';
  69. }
  70.  
  71. if (val === location.pathname) {
  72. val = '';
  73. }
  74.  
  75. return val.trim();
  76. },
  77. });
  78.  
  79. $(this).mbDownloader({
  80. readyToInit: true,
  81. processing: {
  82. ebookFileExt: '.epub'
  83. },
  84. regularExp: {
  85. chapter: null
  86. },
  87. classNames: {
  88. novelId: '#login-user',
  89. infoBlock: '.node-truyen',
  90. chapterContent: '#noi-dung',
  91. chapterNotContent: 'iframe, script, style, a, div, p:has(a[href*="bachngocsach.com"])',
  92. chapterVip: '#btnChapterVip',
  93. chapterList: '#chuong-list-more',
  94. chapterTitle: 'h1#chuong-title',
  95. ebookTitle: 'h1#truyen-title',
  96. ebookAuthor: 'div#tacgia > a',
  97. ebookCover: '#anhbia',
  98. ebookDesc: '#gioithieu',
  99. ebookType: 'div#theloai a',
  100. downloadBtnStatus: 'btn-primary btn-success btn-info btn-warning btn-danger blue success warning info danger error',
  101. downloadAppendTo: 'nav#truyen-nav:last',
  102. },
  103. ebook: {
  104. corsAnywhere: '',
  105. fallbackCover: 'https://bachngocsach.com/reader/sites/default/files/logo.png'
  106. },
  107. chapters: {
  108. chapListSlice: [6],
  109. },
  110. xhr: {
  111. chapter: {
  112. type: 'GET',
  113. url: '',
  114. },
  115. content: {
  116. type: 'GET',
  117. xhrFields: {
  118. withCredentials: true
  119. }
  120. }
  121. },
  122. bookInfoUpdated: function (event, data) {
  123. var that = data.that,
  124. options = that.options,
  125. $infoBlock = that.elements.$infoBlock;
  126.  
  127. options.ebook = $.extend(options.ebook, {
  128. title: $infoBlock.find(options.classNames.ebookTitle).text().trim(),
  129. author: $infoBlock.find(options.classNames.ebookAuthor).text().trim(),
  130. cover: $infoBlock.find(options.classNames.ebookCover).find('img').attr('src'),
  131. description: $infoBlock.find(options.classNames.ebookDesc).html(),
  132. });
  133.  
  134. data.epubInfo = $.extend(data.epubInfo, options.ebook);
  135.  
  136. console.log('Book information updated...', data.epubInfo);
  137. },
  138. chapIdUpdated: function (event, that) {
  139. var options = that.options;
  140. options.xhr.content.url = location.protocol + '//' + options.general.host + options.chapters.chapId;
  141. },
  142. beforeCreateEpub: function (event, that) {
  143. console.log('Prepare generate epub...');
  144. },
  145. complete: function (event, that) {
  146. console.log('Epub downloaded successfully. Please check your Downloads folder.');
  147. console.timeEnd('downloadAndGenerateEpub');
  148. }
  149. });
  150. });
  151. })(jQuery, window, document); // eslint-disable-line

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址