Youtube: expand description and replies

Video description and long comments are expanded automatically

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          Youtube: expand description and replies
// @description   Video description and long comments are expanded automatically
// @author        MK
// @namespace     max44
// @homepage      https://greasyfork.org/en/users/309172-max44
// @match         *://*.youtube.com/*
// @match         *://*.youtu.be/*
// @icon          https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png
// @version       1.0.1
// @license       MIT
// @grant         none
// @run-at        document-idle
// ==/UserScript==

//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

(function () {
  'use strict';

  var urlAtLastCheck = "";
  var nameAtLastCheck = "";
  var btnClick = null;
  var i;

  setInterval(function() { //Check page content constantly
    //Check whether URL and channel name have changed. If yes, clear the attribute clicked-by-script, because it survives change of the page
    if (urlAtLastCheck != window.location.href && nameAtLastCheck != document.title) {
      urlAtLastCheck = window.location.href;
      nameAtLastCheck = document.title;
      btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button'][clicked-by-script='true']" );
      if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
      btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more[clicked-by-script='true']" );
      if (btnClick != null && btnClick.length > 0) btnClick[0].removeAttribute("clicked-by-script");
    }

    //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
    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
    if (btnClick != null && btnClick.length > 0) {
      btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
    }

    //Expand description
    btnClick = $( "div#description ytd-text-inline-expander tp-yt-paper-button#expand[role='button']:not([clicked-by-script='true']):not([hidden=''])" );
    if (btnClick != null && btnClick.length > 0) {
      btnClick[0].click();
      btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
    }

    //Expand description for 7ktTube | 2016 REDUX script
    btnClick = $( "div#meta-contents ytd-video-secondary-info-renderer div ytd-expander tp-yt-paper-button#more:not([clicked-by-script='true'])" );
    if (btnClick != null && btnClick.length > 0) {
      btnClick[0].click();
      btnClick[0].setAttribute("clicked-by-script", "true"); //Do not click it again
    }

    //Expand replies and hide "show less" button
    btnClick = $( "#columns #primary tp-yt-paper-button#more:not([hidden='']) > span.more-button[slot='more-button']:not([clicked-by-script='true'])" );
    if (btnClick != null) {
      for (i = 0; i < btnClick.length; i++) {
        btnClick[i].click();
        btnClick[i].setAttribute("clicked-by-script", "true"); //Do not click it again
        btnClick[i].parentNode.previousElementSibling.setAttribute("style", "display:none;"); //Hide "Show less" button
      }
    }

  }, 250); //Interval to check page content

})();