Youtube: expand description and replies

Video description and long comments are expanded automatically

当前为 2022-07-27 提交的版本,查看 最新版本

  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.2
  11. // @license MIT
  12. // @grant none
  13. // @run-at document-idle
  14. // ==/UserScript==
  15.  
  16. //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
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. var urlAtLastCheck = "";
  22. var nameAtLastCheck = "";
  23. var btnClick = null;
  24. var i;
  25.  
  26. setInterval(function() { //Check page content constantly
  27. //Check whether URL and channel name have changed. If yes, clear the attribute clicked-by-script, because it survives change of the page
  28. if (urlAtLastCheck != window.location.href && nameAtLastCheck != document.title) {
  29. urlAtLastCheck = window.location.href;
  30. nameAtLastCheck = document.title;
  31. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button'][clicked-by-script='true']" );
  32. if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
  33. btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more[clicked-by-script='true']" );
  34. if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
  35. }
  36.  
  37. //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
  38. 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
  39. if (btnClick != null && btnClick.length > 0) {
  40. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  41. }
  42.  
  43. //Expand description
  44. btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button']:not([clicked-by-script='true']):not([hidden=''])" );
  45. if (btnClick != null && btnClick.length > 0) {
  46. btnClick[0].click();
  47. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  48. }
  49.  
  50. //Expand description for 7ktTube | 2016 REDUX script
  51. btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more:not([clicked-by-script='true'])" );
  52. if (btnClick != null && btnClick.length > 0) {
  53. btnClick[0].click();
  54. btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
  55. }
  56.  
  57. //Expand replies and hide "show less" button
  58. 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'])" );
  59. if (btnClick != null) {
  60. for (i = 0; i < btnClick.length; i++) {
  61. btnClick[i].click();
  62. btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
  63. btnClick[i].parentNode.previousElementSibling.setAttribute("style", "display:none;"); //Hide "Show less" button
  64. }
  65. }
  66.  
  67. }, 250); //Interval to check page content
  68.  
  69. })();