Show YouTube comments while watching 2025

Moves comments to the right side and adds a button to toggle between comments and recommended videos

当前为 2025-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show YouTube comments while watching 2025
  3. // @description Moves comments to the right side and adds a button to toggle between comments and recommended videos
  4. // @version 3.2
  5. // @author barn852 & Eloren1
  6. // @license MIT
  7. // @match *://*.youtube.com/*
  8. // @include *://*.youtube.com/watch*
  9. // @grant none
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
  11. // @run-at document-end
  12. // @noframes
  13. // @namespace https://greasyfork.org/users/572660
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. let showComments = true; // Show comments by default
  20.  
  21. const moveComments = () => {
  22. let comments = document.getElementById('comments');
  23. let sidebar = document.querySelector('#secondary-inner');
  24.  
  25. if (comments && sidebar && !sidebar.contains(comments)) {
  26. sidebar.appendChild(comments);
  27. console.log('Moved comments to the right side');
  28. }
  29. };
  30.  
  31. const updateView = () => {
  32. let comments = document.getElementById('comments');
  33. let related = document.getElementById('related');
  34.  
  35. if (comments && related) {
  36. comments.style.display = 'block';
  37. related.style.display = 'none';
  38. }
  39. };
  40.  
  41. const toggleView = () => {
  42. let comments = document.getElementById('comments');
  43. let related = document.getElementById('related');
  44.  
  45. if (comments && related) {
  46. showComments = !showComments;
  47. comments.style.display = showComments ? 'block' : 'none';
  48. related.style.display = showComments ? 'none' : 'block';
  49. }
  50. };
  51.  
  52. const observer = new MutationObserver(() => {
  53. moveComments();
  54. updateView();
  55. });
  56.  
  57. observer.observe(document.body, { childList: true, subtree: true });
  58.  
  59. let button = document.createElement('button');
  60. button.innerHTML = '<svg width="24" height="24" viewBox="0 0 22 22"><g fill="currentColor"><path d="M4 14h4v-4H4v4zm0 5h4v-4H4v4zM4 9h4V5H4v4zm5 5h12v-4H9v4zm0 5h12v-4H9v4zM9 5v4h12V5H9z"/></g></svg>';
  61. button.style = 'background: transparent; border: 0; color: rgb(96,96,96); outline: 0; cursor: pointer; padding: 5px 10px;';
  62.  
  63. button.onclick = toggleView;
  64.  
  65. let waitButton = setInterval(() => {
  66. let menu = document.getElementById('end');
  67. if (menu) {
  68. clearInterval(waitButton);
  69. menu.insertBefore(button, menu.lastElementChild);
  70. updateView();
  71. }
  72. }, 500);
  73.  
  74. console.log('Script loaded');
  75.  
  76. })();