Youtube: expand description and replies

Video description and long comments are expanded automatically

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

  1. // ==UserScript==
  2. // @name Youtube: expand description and replies
  3. // @description Video description and long comments are expanded automatically
  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.4
  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. //TO DO: when you select "View all N replies" you will get all of them without necessity to click "view more comments" all the time
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. var urlAtLastCheck = "";
  23. var nameAtLastCheck = "";
  24. var btnClick = null;
  25. var i;
  26.  
  27. setInterval(function() { //Check page content constantly
  28. //Check whether URL and channel name have changed. If yes, clear the attribute clicked-by-script, because it survives change of the page
  29. if (urlAtLastCheck != window.location.href && nameAtLastCheck != document.title) {
  30. urlAtLastCheck = window.location.href;
  31. nameAtLastCheck = document.title;
  32. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button'][clicked-by-script='true']" );
  33. if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
  34. btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more[clicked-by-script='true']" );
  35. if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
  36. }
  37.  
  38. //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
  39. 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
  40. if (btnClick != null && btnClick.length > 0) {
  41. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  42. }
  43.  
  44. //Expand description
  45. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button']:not([clicked-by-script='true']):not([hidden=''])" );
  46. if (btnClick != null && btnClick.length > 0) {
  47. btnClick[0].click();
  48. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  49. }
  50.  
  51. //Expand description for 7ktTube | 2016 REDUX script
  52. btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more:not([clicked-by-script='true'])" );
  53. if (btnClick != null && btnClick.length > 0) {
  54. btnClick[0].click();
  55. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  56. }
  57.  
  58. //Expand replies and hide "show less" button
  59. 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'])" );
  60. if (btnClick != null) {
  61. for (i = 0; i < btnClick.length; i++) {
  62. btnClick[i].click();
  63. btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
  64. btnClick[i].parentNode.previousElementSibling.setAttribute("style", "display:none;"); //Hide "Show less" button
  65. }
  66. }
  67.  
  68. //Expand post in community section
  69. btnClick = $( "div#post ytd-expander#contentTextExpander tp-yt-paper-button#more[role='button']:not([clicked-by-script='true']):not([hidden=''])" );
  70. if (btnClick != null && btnClick.length > 0) {
  71. btnClick[0].click();
  72. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  73. }
  74.  
  75. }, 250); //Interval to check page content
  76.  
  77. })();