CNMD B站短视频

CNMD B站短视频。B站有太多几秒的短视频了,本脚本帮你与<1分钟的短视频说再见。任何不想被短视频分散精力的都需要这个。

目前为 2022-09-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name CNMD B站短视频
  3. // @namespace tea.pm
  4. // @match https://*.bilibili.com/*
  5. // @license MIT
  6. // @grant none
  7. // @version 1.0
  8. // @author cljnnn
  9. // @description CNMD B站短视频。B站有太多几秒的短视频了,本脚本帮你与<1分钟的短视频说再见。任何不想被短视频分散精力的都需要这个。
  10. // ==/UserScript==
  11.  
  12. // https://stackoverflow.com/questions/9640266/convert-hhmmss-string-to-seconds-only-in-javascript
  13. function hmsToSecondsOnly(str) {
  14. var p = str.split(':'),
  15. s = 0, m = 1;
  16.  
  17. while (p.length > 0) {
  18. s += m * parseInt(p.pop(), 10);
  19. m *= 60;
  20. }
  21.  
  22. return s;
  23. }
  24.  
  25. function isVideoTooSmall(videoCard) {
  26. if (videoCard === null) return false;
  27. var duration = videoCard.querySelector("span.bili-video-card__stats__duration,span.duration")
  28. if (duration === null) return false;
  29. var seconds = hmsToSecondsOnly(duration.textContent);
  30. return seconds < 61;
  31. }
  32.  
  33. function hideUnwantedCard(node, selector, condition=null) {
  34. let cards = [];
  35. for(let card of node.querySelectorAll(selector)) {
  36. cards.push(card)
  37. }
  38. if (node.matches(selector)) {
  39. cards.push(node)
  40. }
  41. for(let card of cards) {
  42. if (condition === null || condition(card))
  43. // card.style.visibility = "hidden";
  44. card.style.display = 'none';
  45. }
  46. }
  47.  
  48. function handle(node) {
  49. if (node.nodeType !== Node.ELEMENT_NODE) return;
  50. hideUnwantedCard(node, "div.bili-live-card,div.video-page-special-card-small");
  51. hideUnwantedCard(node, "div.video-list>div,div.recommended-card,div.bili-video-card,div.video-page-card-small", card=>isVideoTooSmall(card));
  52. }
  53.  
  54. function action(changes, observer) {
  55. for (let mutation of changes) {
  56. handle(mutation.target);
  57. for (let node of mutation.addedNodes) {
  58. handle(node);
  59. }
  60. }
  61. }
  62.  
  63. var observer = new MutationObserver(action);
  64. observer.observe(document.body, { childList: true, subtree: true });
  65. handle(document.body);

QingJ © 2025

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