Better Bilibili

更好的 Bilibili

  1. // ==UserScript==
  2. // @name Better Bilibili
  3. // @namespace jerryshell
  4. // @version 0.2
  5. // @description 更好的 Bilibili
  6. // @author github.com/jerryshell
  7. // @match *://*.bilibili.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
  9. // @grant none
  10. // @license GNU Affero General Public License v3.0
  11. // ==/UserScript==
  12.  
  13. /* jshint esversion: 6 */
  14.  
  15. (() => {
  16. 'use strict';
  17. new MutationObserver(() => {
  18. // 删除视频评论区
  19. const videoCommentElement = document.querySelector('div.bili-comment');
  20. if (videoCommentElement) {
  21. videoCommentElement.remove();
  22. }
  23. // 删除视频弹幕列表
  24. const danmakuBoxElement = document.querySelector('div#danmukuBox');
  25. if (danmakuBoxElement) {
  26. danmakuBoxElement.childNodes.forEach(node => node.remove());
  27. }
  28. // 删除视频弹幕
  29. const videoDanmakuElement = document.querySelector('div.b-danmaku');
  30. if (videoDanmakuElement) {
  31. videoDanmakuElement.remove();
  32. }
  33. // 删除视频弹幕发送
  34. const videoDanmakuSendElement = document.querySelector('div.bpx-player-sending-area');
  35. if (videoDanmakuSendElement) {
  36. videoDanmakuSendElement.remove();
  37. }
  38. // 删除首页分区导航
  39. const biliChannel = document.querySelector('div.bili-header__channel');
  40. if (biliChannel) {
  41. biliChannel.childNodes.forEach(node => node.remove());
  42. }
  43. // 删除首页左导航栏
  44. const leftEntryElement = document.querySelector('ul.left-entry');
  45. if (leftEntryElement) {
  46. leftEntryElement.childNodes.forEach(node => node.remove());
  47. }
  48. // 删除首页搜索栏的占位文字
  49. const navSearchInputElement = document.querySelector('input.nav-search-input');
  50. if (navSearchInputElement) {
  51. navSearchInputElement.removeAttribute('placeholder');
  52. navSearchInputElement.removeAttribute('title');
  53. }
  54. // 首页只保留【科技】和【纪录片】分区
  55. const biliGridList = document.querySelectorAll('section.bili-grid');
  56. if (biliGridList) {
  57. biliGridList.forEach(biliGrid => {
  58. const titleElement = biliGrid.querySelector('a.title');
  59. if (titleElement) {
  60. const title = titleElement.textContent;
  61. if (title.indexOf('科技') === -1 && title.indexOf('纪录片') === -1) {
  62. biliGrid.remove();
  63. }
  64. } else {
  65. biliGrid.remove();
  66. }
  67. });
  68. }
  69. // 删除动态评论区
  70. const biliDynActionCommentElement = document.querySelector('div.bili-dyn-action.comment');
  71. if (biliDynActionCommentElement) {
  72. biliDynActionCommentElement.remove();
  73. }
  74. const biliDynItemInteractionElement = document.querySelector('div.bili-dyn-item__interaction');
  75. if (biliDynItemInteractionElement) {
  76. biliDynItemInteractionElement.remove();
  77. }
  78. // 删除动态左导航栏
  79. const navLinkItemElementList = document.querySelectorAll('li.nav-link-item');
  80. if (navLinkItemElementList) {
  81. navLinkItemElementList.forEach(node => {
  82. node.remove();
  83. });
  84. }
  85. // 删除动态话题
  86. const topicPanelElement = document.querySelector('div.topic-panel');
  87. if (topicPanelElement) {
  88. topicPanelElement.remove();
  89. }
  90. // 删除动态搜索栏的占位文字
  91. const navSearchKeywordElement = document.querySelector('input.nav-search-keyword')
  92. if (navSearchKeywordElement) {
  93. navSearchKeywordElement.removeAttribute('placeholder');
  94. navSearchKeywordElement.removeAttribute('title');
  95. }
  96. // 删除搜索栏的热搜面板
  97. const trendingElement = document.querySelector('div.trending');
  98. if (trendingElement) {
  99. trendingElement.remove();
  100. }
  101. }).observe(document.querySelector('body'), {
  102. childList: true,
  103. attributes: true,
  104. subtree: true,
  105. });
  106. })();