Chapter Downloader

Tự động lấy nội dung từ chương hiện tại đến hết tại truyen.tangthuvien.vn

当前为 2025-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Chapter Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.4
  5. // @description Tự động lấy nội dung từ chương hiện tại đến hết tại truyen.tangthuvien.vn
  6. // @author You
  7. // @match https://truyen.tangthuvien.vn/doc-truyen/*
  8. // @match https://truyen.tangthuvien.vn/doc-truyen/*/*
  9. // @grant none
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13. // ================= TẠO GIAO DIỆN =================
  14. const panel = document.createElement('div');
  15. panel.id = 'reader-panel';
  16. panel.style.cssText = `
  17. position: fixed;
  18. top: 10%;
  19. right: 10px;
  20. width: 300px;
  21. background-color: #f8f8f8;
  22. border: 1px solid #ccc;
  23. border-radius: 5px;
  24. padding: 10px;
  25. z-index: 9999;
  26. box-shadow: 0 0 10px rgba(0,0,0,0.2);
  27. font-family: Arial, sans-serif;
  28. `;
  29. const textarea = document.createElement('textarea');
  30. textarea.id = 'content-textarea';
  31. textarea.style.cssText = `
  32. width: 100%;
  33. height: 300px;
  34. margin-bottom: 10px;
  35. padding: 8px;
  36. border: 1px solid #ddd;
  37. border-radius: 4px;
  38. resize: vertical;
  39. `;
  40. const startButton = document.createElement('button');
  41. startButton.textContent = 'Bắt đầu';
  42. startButton.style.cssText = `
  43. width: 100%;
  44. padding: 8px;
  45. margin-bottom: 10px;
  46. background-color: #4CAF50;
  47. color: white;
  48. border: none;
  49. border-radius: 4px;
  50. cursor: pointer;
  51. `;
  52. const clearButton = document.createElement('button');
  53. clearButton.textContent = 'Xoá';
  54. clearButton.style.cssText = `
  55. width: 49%;
  56. padding: 8px;
  57. margin-right: 2%;
  58. background-color: #f44336;
  59. color: white;
  60. border: none;
  61. border-radius: 4px;
  62. cursor: pointer;
  63. `;
  64. const copyButton = document.createElement('button');
  65. copyButton.textContent = 'Sao Chép';
  66. copyButton.style.cssText = `
  67. width: 49%;
  68. padding: 8px;
  69. background-color: #9c27b0;
  70. color: white;
  71. border: none;
  72. border-radius: 4px;
  73. cursor: pointer;
  74. `;
  75. panel.appendChild(textarea);
  76. panel.appendChild(startButton);
  77. panel.appendChild(clearButton);
  78. panel.appendChild(copyButton);
  79. document.body.appendChild(panel);
  80. const saved = localStorage.getItem('chapterDownloaderContent');
  81. if (saved) textarea.value = saved;
  82. function saveContent() {
  83. localStorage.setItem('chapterDownloaderContent', textarea.value);
  84. }
  85. textarea.addEventListener('input', saveContent);
  86. function extractChapterContent() {
  87. const titleElement = document.querySelector('h2');
  88. const contentElement = document.querySelector('.box-chap');
  89. if (titleElement && contentElement) {
  90. const title = titleElement.innerText.trim();
  91. const content = contentElement.innerText.trim();
  92. if (textarea.value) {
  93. textarea.value += '\n\n\n\n' + title + '\n\n' + content;
  94. } else {
  95. textarea.value = title + '\n\n' + content;
  96. }
  97. saveContent();
  98. return true;
  99. }
  100. return false;
  101. }
  102. function goToNextChapter() {
  103. const next = document.querySelector('.bot-next_chap.bot-control') ||
  104. [...document.querySelectorAll('a[href*="chuong"]')].find(a =>
  105. /tiếp|sau|next/i.test(a.textContent));
  106. if (next) {
  107. next.click();
  108. return true;
  109. }
  110. return false;
  111. }
  112. let isAutoDownloading = false;
  113. startButton.addEventListener('click', () => {
  114. isAutoDownloading = !isAutoDownloading;
  115. if (isAutoDownloading) {
  116. localStorage.setItem('chapterDownloaderAuto', 'true');
  117. startButton.textContent = 'Dừng';
  118. startButton.style.backgroundColor = '#f44336';
  119. extractChapterContent();
  120. setTimeout(() => goToNextChapter(), 1000);
  121. } else {
  122. localStorage.setItem('chapterDownloaderAuto', 'false');
  123. startButton.textContent = 'Bắt đầu';
  124. startButton.style.backgroundColor = '#4CAF50';
  125. }
  126. });
  127. clearButton.addEventListener('click', () => {
  128. textarea.value = '';
  129. saveContent();
  130. });
  131. copyButton.addEventListener('click', () => {
  132. textarea.select();
  133. document.execCommand('copy');
  134. const notification = document.createElement('div');
  135. notification.textContent = 'Đã sao chép!';
  136. notification.style.cssText = `
  137. position: fixed;
  138. bottom: 20px;
  139. left: 50%;
  140. transform: translateX(-50%);
  141. background-color: rgba(0,0,0,0.8);
  142. color: white;
  143. padding: 10px 20px;
  144. border-radius: 4px;
  145. z-index: 10000;
  146. `;
  147. document.body.appendChild(notification);
  148. setTimeout(() => notification.remove(), 2000);
  149. });
  150. // Khôi phục trạng thái auto sau khi load trang mới
  151. window.addEventListener('load', () => {
  152. const shouldContinue = localStorage.getItem('chapterDownloaderAuto') === 'true';
  153. if (shouldContinue) {
  154. setTimeout(() => {
  155. extractChapterContent();
  156. setTimeout(() => goToNextChapter(), 1000);
  157. }, 1000);
  158. }
  159. });
  160. console.log('✅ Chapter Downloader Auto script loaded');
  161. })();