Youtube: expand description and long comments; show all the replies

Video description, long comments and list of subscriptions are expanded automatically; all the replies are shown after pressing "View all N replies" button

当前为 2022-10-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube: expand description and long comments; show all the replies
  3. // @description Video description, long comments and list of subscriptions are expanded automatically; all the replies are shown after pressing "View all N replies" button
  4. // @author MK
  5. // @namespace max44
  6. // @homepage https://greasyfork.org/en/users/309172-max44
  7. // @match *://*.youtube.com/*
  8. // @match *://*.youtu.be/*
  9. // @icon https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png
  10. // @version 1.0.7
  11. // @license MIT
  12. // @grant none
  13. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  14. // @run-at document-idle
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19.  
  20. var urlAtLastCheck = "";
  21. var nameAtLastCheck = "";
  22. var btnClick = null;
  23. var i;
  24.  
  25. setInterval(function() { //Check page content constantly
  26. //Check whether URL and channel name have changed. If yes, clear the attribute clicked-by-script, because it survives change of the page
  27. if (urlAtLastCheck != window.location.href && nameAtLastCheck != document.title) {
  28. urlAtLastCheck = window.location.href;
  29. nameAtLastCheck = document.title;
  30. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button'][clicked-by-script='true']" );
  31. if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
  32. btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more[clicked-by-script='true']" );
  33. if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
  34. }
  35.  
  36. //Check whether description has been expanded by another script or addon. If yes, mark it as if it was expanded by the script to avoid double processing
  37. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button']:not([clicked-by-script='true'])[hidden='']" ); //Description was expanded by another script or addon
  38. if (btnClick != null && btnClick.length > 0) {
  39. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  40. }
  41.  
  42. //Expand description
  43. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button']:not([clicked-by-script='true']):not([hidden=''])" );
  44. if (btnClick != null && btnClick.length > 0) {
  45. btnClick[0].click();
  46. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  47. }
  48.  
  49. //Expand description for 7ktTube | 2016 REDUX script
  50. btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more:not([clicked-by-script='true'])" );
  51. if (btnClick != null && btnClick.length > 0) {
  52. btnClick[0].click();
  53. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  54. }
  55.  
  56. //Expand long comments and hide "show less" button in comments section
  57. btnClick = $( "#primary ytd-comment-renderer #comment-content tp-yt-paper-button#more:not([hidden='']) > span.more-button[slot='more-button']:not([clicked-by-script='true'])" );
  58. if (btnClick != null) {
  59. for (i = 0; i < btnClick.length; i++) {
  60. btnClick[i].click();
  61. btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
  62. btnClick[i].parentNode.previousElementSibling.setAttribute("style", "display:none;"); //Hide "Show less" button
  63. }
  64. }
  65.  
  66. //Expand long comments and hide "show less" button in notification submenu
  67. btnClick = $( "#submenu ytd-comment-renderer #comment-content tp-yt-paper-button#more:not([hidden='']) > span.more-button[slot='more-button']:not([clicked-by-script='true'])" );
  68. if (btnClick != null) {
  69. for (i = 0; i < btnClick.length; i++) {
  70. btnClick[i].click();
  71. btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
  72. btnClick[i].parentNode.previousElementSibling.setAttribute("style", "display:none;"); //Hide "Show less" button
  73. }
  74. }
  75.  
  76. //Expand post in community section
  77. btnClick = $( "div#post ytd-expander#contentTextExpander tp-yt-paper-button#more[role='button']:not([clicked-by-script='true']):not([hidden=''])" );
  78. if (btnClick != null && btnClick.length > 0) {
  79. btnClick[0].click();
  80. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  81. }
  82.  
  83. //Show all replies upon pressing "View all N replies" button
  84. btnClick = $( "div#replies div#expander div#button.ytd-continuation-item-renderer ytd-button-renderer tp-yt-paper-button#button[role='button']:not([clicked-by-script='true'])" );
  85. if (btnClick != null) {
  86. for (i = 0; i < btnClick.length; i++) {
  87. btnClick[i].click();
  88. btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
  89. }
  90. }
  91.  
  92. //Show all subscriptions
  93. btnClick = $( "#guide div#sections div#items ytd-guide-collapsible-entry-renderer.ytd-guide-section-renderer[can-show-more=''] #expander-item:not([clicked-by-script='true'])" );
  94. if (btnClick != null) {
  95. for (i = 0; i < btnClick.length; i++) {
  96. btnClick[i].click();
  97. btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
  98. }
  99. }
  100.  
  101. }, 250); //Interval to check page content
  102.  
  103. })();