├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

contentCleaner.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * 小说内容清洗工具
  3. * 移除原始网站信息、广告、干扰元素
  4. */
  5. export const contentCleaner = {
  6. // 主清洗函数
  7. clean(content) {
  8. if (!content) return ''
  9. // 执行清洗流水线
  10. return this.pipeline(content, [
  11. this.removeWebsiteInfo,
  12. this.removeAds,
  13. this.removeHtmlTags,
  14. this.normalizeSpaces,
  15. this.fixParagraphs,
  16. this.removeSpecialChars
  17. ])
  18. },
  19. // 清洗流水线
  20. pipeline(content, processors) {
  21. return processors.reduce((result, processor) => {
  22. return processor(result)
  23. }, content)
  24. },
  25. // 移除网站信息
  26. removeWebsiteInfo(content) {
  27. const patterns = [
  28. /最新网址[::]?\s*[a-z0-9.-]+/gi,
  29. /www\.[a-z0-9]+\.[a-z]{2,}/gi,
  30. /请?收藏本站:https?:\/\/[^\s]+/gi,
  31. /请?记住本站域名:\w+\.\w+/gi,
  32. /(电脑版|手机版)?访问:m?\.\w+\.\w+/gi,
  33. /【[^】]{0,10}更新快[^】]{0,10}】/g
  34. ]
  35. return patterns.reduce((result, pattern) => {
  36. return result.replace(pattern, '')
  37. }, content)
  38. },
  39. // 移除广告文本
  40. removeAds(content) {
  41. const adKeywords = [
  42. '广告', '推广', '推荐票', '月票', 'QQ群', '微信号',
  43. 'VIP章节', '正版订阅', '盗版', '笔趣阁', '天才一秒记住',
  44. '本站地址', '手机用户'
  45. ]
  46. const adPattern = new RegExp(
  47. `[【((]?(${adKeywords.join('|')})[^))】]*[))】]?`,
  48. 'gi'
  49. )
  50. return content.replace(adPattern, '')
  51. },
  52. // 移除HTML标签
  53. removeHtmlTags(content) {
  54. return content
  55. .replace(/<br\s*\/?>/g, '\n') // 保留换行
  56. .replace(/&nbsp;|&#160;/g, ' ') // 替换空格实体
  57. .replace(/<[^>]+>/g, '') // 移除所有HTML标签
  58. },
  59. // 标准化空格
  60. normalizeSpaces(content) {
  61. return content
  62. .replace(/\s+/g, ' ') // 合并连续空格
  63. .replace(/^\s+|\s+$/g, '') // 移除首尾空格
  64. },
  65. // 修复段落格式
  66. fixParagraphs(content) {
  67. return content
  68. .split('\n')
  69. .map(line => line.trim())
  70. .filter(line => line.length > 0)
  71. .join('\n\n')
  72. },
  73. // 移除特殊字符
  74. removeSpecialChars(content) {
  75. const specialChars = [
  76. '\u200b', // 零宽空格
  77. '\ufeff', // BOM头
  78. '\u202a', '\u202b', '\u202c', '\u202d', '\u202e' // 方向控制符
  79. ]
  80. const pattern = new RegExp(`[${specialChars.join('')}]`, 'g')
  81. return content.replace(pattern, '')
  82. }
  83. }