YouTube Sticky Live Chat

Pin the latest message written by live owner or moderator to the top

目前为 2020-05-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Sticky Live Chat
  3. // @name:ja YouTube Sticky Live Chat
  4. // @namespace https://i544c.github.io
  5. // @version 0.3.5
  6. // @description Pin the latest message written by live owner or moderator to the top
  7. // @description:ja 生放送主とモデレータの最新のコメントを上に固定するユーザスクリプト
  8. // @author i544c
  9. // @match https://www.youtube.com/*
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (() => {
  15. const main = e => {
  16. console.log('Found LiveChat frame');
  17. const chatframe = e.target.contentDocument;
  18. const style = document.createElement('style');
  19. style.textContent = `
  20. yt-live-chat-app {
  21. /* Global variables */
  22. --ysl-line-length: 3;
  23. --ysl-message-height: calc(1em * var(--ysl-line-length) + 4px);
  24. }
  25.  
  26. #item-offset {
  27. overflow: visible !important;
  28. }
  29.  
  30. #items {
  31. transform: none !important;
  32. }
  33.  
  34. yt-live-chat-text-message-renderer[author-type="owner"],
  35. yt-live-chat-text-message-renderer[author-type="moderator"] {
  36. background: var(--yt-live-chat-message-highlight-background-color);
  37. position: sticky;
  38. top: -1px;
  39. z-index: 1;
  40. height: var(--ysl-message-height);
  41. min-height: var(--ysl-message-height);
  42. }
  43.  
  44. yt-live-chat-text-message-renderer[author-type="owner"]:hover,
  45. yt-live-chat-text-message-renderer[author-type="moderator"]:hover {
  46. height: 100% !important;
  47. }
  48.  
  49. yt-live-chat-text-message-renderer[author-type="owner"] #content,
  50. yt-live-chat-text-message-renderer[author-type="moderator"] #content {
  51. align-self: normal;
  52. /* String truncate */
  53. display: -webkit-box;
  54. -webkit-box-orient: vertical;
  55. -webkit-line-clamp: var(--ysl-line-length);
  56. overflow: hidden;
  57. }
  58.  
  59. yt-live-chat-text-message-renderer[author-type="owner"] #content:hover,
  60. yt-live-chat-text-message-renderer[author-type="moderator"] #content:hover {
  61. -webkit-box-orient: inline-axis;
  62. }
  63. `;
  64. chatframe.body.appendChild(style);
  65. };
  66.  
  67.  
  68. const findFrame = () => {
  69. const findInterval = window.setInterval(() => {
  70. const chatframe = document.querySelector('#chatframe');
  71. if (chatframe) {
  72. chatframe.addEventListener('load', main);
  73. window.clearInterval(findInterval);
  74. }
  75. }, 1000);
  76. };
  77.  
  78. findFrame();
  79. document.addEventListener('yt-navigate-finish', findFrame);
  80. })();

QingJ © 2025

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