YT auto comment

Auto-fills comment automatically on YT

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

Advertisement:

// ==UserScript==
// @name         YT auto comment
// @namespace    DK 
// @version      1.0.0
// @description  Auto-fills comment automatically on YT
// @author       DK
// @match        https://*.youtube.com/watch*
// @grant        GM_registerMenuCommand
// @run-at       document-idle
// ==/UserScript==

(() => {
  'use strict';

  const ALLOWED_CHANNELS = [
    "MRBREAST"
  ];

  const comments = [
    "Hello Human"
  ];

  const SELECTORS = {
    CHANNEL_NAME: '#text-container.ytd-channel-name',
    COMMENT_BOX: 'ytd-comment-simplebox-renderer div#placeholder-area',
    COMMENT_INPUT: '#contenteditable-root',
  };

  function getChannelName() {
    const el = document.querySelector(SELECTORS.CHANNEL_NAME);
    return el?.innerText?.trim() || null;
  }

  function scrollToComments() {
    document.querySelector('ytd-comments')?.scrollIntoView({ behavior: 'smooth' });
    return new Promise(resolve => setTimeout(resolve, 1500));
  }

  async function fillComment() {
    const commentBox = document.querySelector(SELECTORS.COMMENT_BOX);
    if (!commentBox) {
      alert(" Comment box not found.");
      return false;
    }

    commentBox.click();
    await new Promise(resolve => setTimeout(resolve, 1000));

    const commentInput = document.querySelector(SELECTORS.COMMENT_INPUT);
    if (commentInput) {
      const comment = comments[Math.floor(Math.random() * comments.length)];
      commentInput.focus();
      commentInput.innerText = comment;
      commentInput.dispatchEvent(new InputEvent("input", { bubbles: true }));
      console.log(` Auto-filled comment: "${comment}"`);
      return true;
    } else {
      alert(" Comment input area not found.");
      return false;
    }
  }

  async function autoFillIfAllowed() {
    const channelName = getChannelName();
    if (!channelName) return;

    if (ALLOWED_CHANNELS.includes(channelName)) {
      console.log(` Auto-filling comment on allowed channel: ${channelName}`);
      await scrollToComments();
      await fillComment();
    } else {
      console.log(` Channel not allowed for auto-fill: ${channelName}`);
    }
  }

  // Tampermonkey menu command for manual fill on any channel
  GM_registerMenuCommand(" Manually Auto-Fill Comment", async () => {
    const channelName = getChannelName() || 'Unknown Channel';
    console.log(` Manual fill requested on channel: ${channelName}`);
    await scrollToComments();
    await fillComment();
  });

  // Run auto-fill on page load
  setTimeout(autoFillIfAllowed, 3000);
})();