YouTube Auto Comments Using Js

Automatically posts comments on YouTube videos and refreshes other videos to post comments automatically.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

// ==UserScript==
// @name           YouTube Auto Comments Using Js
// @namespace      https://github.com/yashu1wwww 
// @version        1.1.8
// @description    Automatically posts comments on YouTube videos and refreshes other videos to post comments automatically.
// @author         Yashawanth R 
// @license        MIT
// @match          https://*.youtube.com/watch*
// @grant          none
// @run-at         document-idle
// ==/UserScript==

(() => {
  'use strict';

  // List of comments
  const comments = [
    "Super!",
    "Amazing one!",
    "What an acting!",
    "Great video!",
    "Have a nice day!",
    "Keep going!",
    "Keep rocking!",
    "All the best buddy!",
    "Next video please!",
    "One of the best videos I've ever seen!",
    "Wonderful day!",
    "Great one seen today!",
    "Superb!",
    "Magnifying!",
    "Shared with my friends!",
    "Best thing on the internet!",
    "Sensational video!",
    "Dashing!",
    "Marvelous!",
    "Next big video on the internet!",
    "Always good content!",
    "People will really like this video!",
    "Good food makes humans happy!",
    "All the best, dude!",
  ];

  // Prompt the user for the number of comments to post
  const MAX_COMMENTS = parseInt(prompt("How many comments would you like to post?", 10)) || 10;
  let commentCount = 0; // Counter for comments

  // Selectors
  const SELECTORS = {
    COMMENT_BOX: 'ytd-comments ytd-comment-simplebox-renderer div#placeholder-area',
    COMMENT_INPUT: '#contenteditable-root',
    COMMENT_SUBMIT_BUTTON: '#submit-button',
  };

  // Scroll to the comment section
  function scrollToComments() {
    console.log('Scrolling to comments...');
    window.scrollTo(0, 600); // Adjust scrolling position if needed
    return new Promise((resolve) => setTimeout(resolve, 2000)); // Wait for comments to load
  }

  // Post a comment
  async function postComment() {
    try {
      const commentBox = document.querySelector(SELECTORS.COMMENT_BOX);
      if (commentBox) {
        console.log('Opening comment box...');
        commentBox.click();
        await new Promise((resolve) => setTimeout(resolve, 1000));

        const commentInput = document.querySelector(SELECTORS.COMMENT_INPUT);
        if (commentInput) {
          const comment = comments[commentCount % comments.length]; // Get a comment from the list
          console.log(`Adding comment: ${comment}`);
          commentInput.innerText = comment;

          const submitButton = document.querySelector(SELECTORS.COMMENT_SUBMIT_BUTTON);
          if (submitButton) {
            console.log('Submitting comment...');
            submitButton.click();
            commentCount++;
            return true;
          }
        }
      }
      console.log('Comment box or input not found.');
      return false;
    } catch (error) {
      console.error('Error posting comment:', error);
      return false;
    }
  }

  // Main function
  async function autoComment() {
    console.log('Starting YouTube Auto-Commenter...');
    while (commentCount < MAX_COMMENTS) {
      await scrollToComments();
      const success = await postComment();
      if (!success) break;
      await new Promise((resolve) => setTimeout(resolve, 3000)); // Delay after each comment for video to load
    }
    console.log('Finished posting comments.');
  }

  // Add a delay of 2 seconds before running the main comment process
  setTimeout(() => {
    // Run script on video pages
    if (window.location.href.includes('youtube.com/watch')) {
      setTimeout(autoComment, 3000); // Delay to allow the page to load
    }
  }, 2000); // Wait 2 seconds before starting
})();