B站评论区剧透折叠

折叠评论中包含"剧透"的楼层

  1. // ==UserScript==
  2. // @name Bilibili Comment Spoiler Folder
  3. // @name:zh-CN B站评论区剧透折叠
  4. // @name:zh-HK B站評論區劇透摺疊
  5. // @name:zh-TW B站評論區劇透摺疊
  6. // @namespace https://github.com/ipcjs
  7. // @version 1.0.3
  8. // @description 折叠评论中包含"剧透"的楼层
  9. // @description:zh-CN 折叠评论中包含"剧透"的楼层
  10. // @description:zh-HK 摺疊評論中包含“劇透”的樓層
  11. // @description:zh-TW 摺疊評論中包含“劇透”的樓層
  12. // @author ipcjs
  13. // @include *://www.bilibili.com/video/av*
  14. // @include *://bangumi.bilibili.com/anime/*
  15. // @include *://bangumi.bilibili.com/movie/*
  16. // @include *://www.bilibili.com/bangumi/play/ep*
  17. // @require https://code.jquery.com/jquery-2.2.4.min.js
  18. // @require https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
  19. // @grant GM_addStyle
  20. // ==/UserScript==
  21.  
  22. 'use strict'
  23. GM_addStyle("a.ep_spoiler_fold_toggle {display:block;color:#bbb;margin-top:5px}")
  24. const regex = /(剧透|劇透|R\.?I\.?P|走好)/i
  25. const message = '可能有剧透!单击此处显示 / 隐藏'
  26. $('.comm').arrive('.list-item.reply-wrap', ele => {
  27. // 处理剧透
  28. const processSpoiler = (replyCount) => {
  29. if ($('.ep_spoiler_fold_toggle', ele).length > 0) return // 已经添加了剧透警告, 着不需要再处理了
  30.  
  31. const $content = $('.con', ele).find('>.text, >.reply-box, >.paging-box')
  32. $content.hide()
  33. $($content[0]).before(`<a class="ep_spoiler_fold_toggle" href="javascript:">(+${replyCount}) ${message}</a>`)
  34. $('.ep_spoiler_fold_toggle', ele).on('click', (event) => {
  35. $content.slideToggle()
  36. })
  37. }
  38. // 检测已有的文本
  39. $text = $('.text, .text-con', ele)
  40. if ($text.text().match(regex)) {
  41. processSpoiler($text.length - 1)
  42. }
  43. // 检测将来增加的文本
  44. ele.arrive('.text, .text-con', text => {
  45. if ($(text).text().match(regex)) {
  46. processSpoiler('x')
  47. }
  48. })
  49.  
  50. })

QingJ © 2025

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