下载番茄小说

下载番茄小说章节内容,仅支持章节

  1. // ==UserScript==
  2. // @name 下载番茄小说
  3. // @namespace http://yourwebsite.com
  4. // @version 1.1.4
  5. // @license MIT
  6. // @description 下载番茄小说章节内容,仅支持章节
  7. // @author 鸡景行
  8. // @connect novel.snssdk.com
  9. // @match *://*.fanqienovel.com/reader/*
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_xmlhttpRequest
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15.  
  16. function downloadNovelContent() {
  17. // 获取当前页面的URL
  18. let currentUrl = window.location.href;
  19.  
  20. // 提取URL中的ID,假设ID位于URL的最后一个斜杠之后
  21. let id = currentUrl.substring(currentUrl.lastIndexOf('/') + 1);
  22. id = id.split('?')[0];
  23. // 构建新的API URL
  24. let apiUrl = `https://novel.snssdk.com/api/novel/book/reader/full/v1/?device_platform=android&parent_enterfrom=novel_channel_search.tab.&aid=2329&platform_id=1&group_id=0&item_id=${id}`;
  25.  
  26. // 发送HTTP请求获取数据
  27. GM_xmlhttpRequest({
  28. method: 'GET',
  29. url: apiUrl,
  30. onload: function(response) {
  31. let jsonData = JSON.parse(response.responseText);
  32. let content = jsonData.data.content;
  33.  
  34. // 创建一个虚拟DOM以解析HTML内容
  35. let parser = new DOMParser();
  36. let htmlDoc = parser.parseFromString(content, 'text/html');
  37.  
  38. // 获取章节标题
  39. let titleElement = htmlDoc.querySelector('.tt-title');
  40. let chapterTitle = titleElement ? titleElement.textContent.trim() : 'Untitled';
  41.  
  42. // 获取文章内容
  43. let articleElement = htmlDoc.querySelector('article');
  44. let articleContent = articleElement ? articleElement.textContent : '';
  45.  
  46. // 替换不需要的元素为换行符
  47. articleContent = articleContent.replace(/<\/div>|<\/p>/g, '\n');
  48. articleContent = chapterTitle + " " + articleContent
  49. // 创建一个 Blob 对象
  50. let blob = new Blob([articleContent], { type: 'text/plain' });
  51.  
  52. // 创建下载链接
  53. let url = URL.createObjectURL(blob);
  54.  
  55. // 创建下载按钮并触发点击
  56. let downloadLink = document.createElement('a');
  57. downloadLink.href = url;
  58. downloadLink.download = `${chapterTitle}.txt`; // 使用章节标题作为文件名
  59. downloadLink.style.display = 'none';
  60. document.body.appendChild(downloadLink);
  61. downloadLink.click();
  62.  
  63. // 释放 Blob 对象的URL
  64. URL.revokeObjectURL(url);
  65. },
  66. onerror: function(error) {
  67. console.error('发生错误:', error);
  68. }
  69. });
  70. }
  71.  
  72. // 添加齿轮菜单
  73. GM_registerMenuCommand("下载小说内容", downloadNovelContent);
  74. })();

QingJ © 2025

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