网易CC复读弹幕禁止

移除网易CC复读弹幕

目前為 2023-05-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 网易CC复读弹幕禁止
  3. // @namespace https://github.com/AliubYiero/TemperScripts
  4. // @version 1.0.0
  5. // @description 移除网易CC复读弹幕
  6. // @author Yiero
  7. // @match https://cc.163.com/*
  8. // @icon https://cc.163.com/favicon.ico
  9. // @license GPL
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /* 用户配置:弹幕白名单 */
  14. // 添加新白名单,一对英文引号中间加白名单弹幕,引号后面加英文逗号
  15. const danmuBlackList = [
  16. '?',
  17. '?',
  18. '草',
  19. '笑了',
  20. ]
  21.  
  22. function sleep(delay=1) {
  23. return new Promise(resolve => {
  24. setTimeout(() => {
  25. resolve();
  26. }, delay * 1000);
  27. })
  28. }
  29.  
  30. window.onload = async () => {
  31. const liveAddress = location.pathname.split('/')[1];
  32. // 其他非直播间页面
  33. if (isNaN(liveAddress)) { // 其它界面
  34. return;
  35. }
  36. await sleep();
  37. removeRepeatDanmu();
  38. }
  39.  
  40. class RecordDanmu {
  41. constructor() {
  42. this.danmuList = [];
  43. this.expectDanmu = danmuBlackList;
  44. this.maxRecord = 50;
  45. this.counter = 0;
  46. }
  47. addCounter() {
  48. if (this.counter >= this.maxRecord) {
  49. this.counter = 0;
  50. } else {
  51. this.counter++;
  52. }
  53. }
  54. add(text) {
  55. this.danmuList[this.counter] = text;
  56. this.addCounter();
  57. }
  58. isRepeat(text) {
  59. // 拦截白名单
  60. if (this.expectDanmu.includes(text)) {
  61. return;
  62. }
  63. return this.danmuList.includes(text);
  64. }
  65. }
  66.  
  67. function removerObserver(observeNode, danmuType) {
  68. const recordDanmu = new RecordDanmu();
  69. const danmuList = observeNode; // 右侧文本弹幕栏
  70. const danmuObserver = new MutationObserver(
  71. e => {
  72. e.forEach(record => {
  73. const Node = record.addedNodes[0];
  74. if (!Node) {
  75. return;
  76. }
  77. let fullDanmu = Node.innerText;
  78. let danmu;
  79. if (danmuType === 'float') {
  80. danmu = fullDanmu;
  81. } else {
  82. danmu = fullDanmu.slice(fullDanmu.indexOf(':') + 1);
  83. }
  84. if (recordDanmu.isRepeat(danmu)) {
  85. // 删除复读弹幕
  86. // console.log('删除复读弹幕\t' + danmu);
  87. Node.style.display = 'none';
  88. return;
  89. }
  90. recordDanmu.add(danmu);
  91. })
  92. }
  93. );
  94. danmuObserver.observe(danmuList, {
  95. childList: true,
  96. });
  97. }
  98. function removeRepeatDanmu() {
  99. removerObserver(document.querySelector('#js-chat-list-ul'), 'text');
  100. removerObserver(document.querySelector('.comment-canvas'), 'float');
  101. }