Greasy Fork 还支持 简体中文。

TTV Auto Upload

Tự động điền form đăng chương trên tangthuvien.net với tính năng nâng cao

目前為 2025-03-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name TTV Auto Upload
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Tự động điền form đăng chương trên tangthuvien.net với tính năng nâng cao
  6. // @author Your name
  7. // @match https://tangthuvien.net/dang-chuong/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Thêm CSS cho thông báo
  15. const style = document.createElement('style');
  16. style.textContent = `
  17. .ttv-notification {
  18. position: fixed;
  19. top: 20px;
  20. right: 20px;
  21. padding: 10px 20px;
  22. background: #4CAF50;
  23. color: white;
  24. border-radius: 4px;
  25. z-index: 9999;
  26. display: none;
  27. }
  28. .ttv-error {
  29. background: #f44336;
  30. }
  31. .ttv-button-group {
  32. margin-top: 10px;
  33. display: flex;
  34. gap: 10px;
  35. }
  36. `;
  37. document.head.appendChild(style);
  38.  
  39. // Tạo div thông báo
  40. const notification = document.createElement('div');
  41. notification.className = 'ttv-notification';
  42. document.body.appendChild(notification);
  43.  
  44. // Hiển thị thông báo
  45. function showNotification(message, isError = false) {
  46. notification.textContent = message;
  47. notification.className = 'ttv-notification' + (isError ? ' ttv-error' : '');
  48. notification.style.display = 'block';
  49. setTimeout(() => {
  50. notification.style.display = 'none';
  51. }, 3000);
  52. }
  53.  
  54. // Thêm các nút điều khiển
  55. function addControlButtons() {
  56. const actionDiv = document.getElementById('action-btns');
  57. if (!actionDiv) {
  58. showNotification('Không tìm thấy vị trí để thêm nút!', true);
  59. return;
  60. }
  61.  
  62. const buttonGroup = document.createElement('div');
  63. buttonGroup.className = 'ttv-button-group col-sm-8 col-sm-offset-2';
  64.  
  65. // Nút tự động điền
  66. const autoFillBtn = document.createElement('button');
  67. autoFillBtn.type = 'button';
  68. autoFillBtn.className = 'btn btn-primary';
  69. autoFillBtn.innerHTML = '<span>Tự động điền</span>';
  70. autoFillBtn.onclick = autoFillForm;
  71.  
  72. // Nút lưu cấu hình
  73. const saveConfigBtn = document.createElement('button');
  74. saveConfigBtn.type = 'button';
  75. saveConfigBtn.className = 'btn btn-success';
  76. saveConfigBtn.innerHTML = '<span>Lưu cấu hình</span>';
  77. saveConfigBtn.onclick = saveChapterConfig;
  78.  
  79. // Nút tải cấu hình
  80. const loadConfigBtn = document.createElement('button');
  81. loadConfigBtn.type = 'button';
  82. loadConfigBtn.className = 'btn btn-info';
  83. loadConfigBtn.innerHTML = '<span>Tải cấu hình</span>';
  84. loadConfigBtn.onclick = loadChapterConfig;
  85.  
  86. buttonGroup.appendChild(autoFillBtn);
  87. buttonGroup.appendChild(saveConfigBtn);
  88. buttonGroup.appendChild(loadConfigBtn);
  89.  
  90. actionDiv.appendChild(buttonGroup);
  91. }
  92.  
  93. // Tự động điền form
  94. function autoFillForm() {
  95. try {
  96. // Kiểm tra CSRF token
  97. const tokenInput = document.querySelector('input[name="_token"]');
  98. if (!tokenInput) {
  99. showNotification('Không tìm thấy token!', true);
  100. return;
  101. }
  102.  
  103. // Lấy thông tin chương hiện tại
  104. const chap_stt = document.querySelector('.chap_stt1')?.value;
  105. const chap_serial = document.querySelector('.chap_serial')?.value;
  106. const chap_vol = document.querySelector('.chap_vol')?.value;
  107. const chap_vol_name = document.querySelector('.chap_vol_name')?.value;
  108.  
  109. if (!chap_stt || !chap_serial) {
  110. showNotification('Không tìm thấy thông tin chương!', true);
  111. return;
  112. }
  113.  
  114. // Điền các trường
  115. const fields = {
  116. 'chap_stt[1]': chap_stt,
  117. 'chap_number[1]': chap_serial,
  118. 'vol[1]': chap_vol || '1',
  119. 'vol_name[1]': chap_vol_name || '',
  120. 'chap_name[1]': `Chương ${chap_serial}`
  121. };
  122.  
  123. for (const [name, value] of Object.entries(fields)) {
  124. const input = document.querySelector(`input[name="${name}"]`);
  125. if (input) {
  126. input.value = value;
  127. }
  128. }
  129.  
  130. // Focus vào ô nội dung
  131. const contentInput = document.querySelector('textarea[name="introduce[1]"]');
  132. if (contentInput) {
  133. contentInput.focus();
  134. showNotification('Đã điền form thành công!');
  135. } else {
  136. showNotification('Không tìm thấy ô nhập nội dung!', true);
  137. }
  138. } catch (error) {
  139. console.error('Lỗi khi tự động điền form:', error);
  140. showNotification('Có lỗi xảy ra khi điền form!', true);
  141. }
  142. }
  143.  
  144. // Lưu cấu hình chương
  145. function saveChapterConfig() {
  146. try {
  147. const config = {
  148. chap_stt: document.querySelector('.chap_stt1')?.value,
  149. chap_serial: document.querySelector('.chap_serial')?.value,
  150. chap_vol: document.querySelector('.chap_vol')?.value,
  151. chap_vol_name: document.querySelector('.chap_vol_name')?.value
  152. };
  153.  
  154. localStorage.setItem('ttv_chapter_config', JSON.stringify(config));
  155. showNotification('Đã lưu cấu hình thành công!');
  156. } catch (error) {
  157. console.error('Lỗi khi lưu cấu hình:', error);
  158. showNotification('Có lỗi xảy ra khi lưu cấu hình!', true);
  159. }
  160. }
  161.  
  162. // Tải cấu hình chương
  163. function loadChapterConfig() {
  164. try {
  165. const savedConfig = localStorage.getItem('ttv_chapter_config');
  166. if (!savedConfig) {
  167. showNotification('Không tìm thấy cấu hình đã lưu!', true);
  168. return;
  169. }
  170.  
  171. const config = JSON.parse(savedConfig);
  172.  
  173. // Cập nhật các trường
  174. const fields = {
  175. '.chap_stt1': config.chap_stt,
  176. '.chap_serial': config.chap_serial,
  177. '.chap_vol': config.chap_vol,
  178. '.chap_vol_name': config.chap_vol_name
  179. };
  180.  
  181. for (const [selector, value] of Object.entries(fields)) {
  182. const input = document.querySelector(selector);
  183. if (input && value) {
  184. input.value = value;
  185. }
  186. }
  187.  
  188. showNotification('Đã tải cấu hình thành công!');
  189. } catch (error) {
  190. console.error('Lỗi khi tải cấu hình:', error);
  191. showNotification('Có lỗi xảy ra khi tải cấu hình!', true);
  192. }
  193. }
  194.  
  195. // Thêm các nút điều khiển khi trang đã load
  196. window.addEventListener('load', function() {
  197. addControlButtons();
  198. });
  199. })();