austencm / youtube-auto-like

Chrome extension that automatically likes videos from your subscribed channels.
MIT License
161 stars 53 forks source link

Fixed the script #145

Open SethWiiPlaza opened 7 months ago

SethWiiPlaza commented 7 months ago

https://github.com/SethWiiPlaza/YT-AutoLike/releases/tag/Release

5 second delay before like (Google Chrome only)

use the 'Run Javascript' Chrome Extension to execute script (copy + paste script)

or 'Custom JavaScript for Websites 2' to inject

// code by Seth@WiiPlaza
function clickLikeButton() {
  const likeButtonSelector =
    '#top-level-buttons-computed > segmented-like-dislike-button-view-model > yt-smartimation > div > div > like-button-view-model > toggle-button-view-model > button > yt-touch-feedback-shape > div';

  // Function to click the like button
  function performClick() {
    const likeButton = document.querySelector(likeButtonSelector);

    if (likeButton) {
      likeButton.click();
      console.log('Like button clicked');
    } else {
      console.log('Like button not found');
    }
  }

  // Wait for 5 seconds before executing the rest of the code
  setTimeout(performClick, 5000); // 5000 milliseconds = 5 seconds

  // Monitor changes in the video title
  let currentTitle = getTitle();

  function getTitle() {
    const titleElement = document.querySelector("#title > h1 > yt-formatted-string");
    return titleElement ? titleElement.textContent : null;
  }

  function checkTitleChange() {
    const newTitle = getTitle();

    if (newTitle !== currentTitle) {
      // Video title has changed, re-run the script
      console.log('Video title has changed, re-running the script...');
      performClick();
      // Update the current title
      currentTitle = newTitle;
    }

    // Check for title changes every 1 second
    setTimeout(checkTitleChange, 1000); // 1000 milliseconds = 1 second
  }

  checkTitleChange();
}

// Call the function to click the like button
clickLikeButton();

image

Nicodemus111 commented 7 months ago

yours was liking twice and i wanted it in a userscript so i changed it a bit for myself:


// @name         youtube auto like
// @version      1.1
// @description  šŸ‘
// @author       Seth@WiiPlaza
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==
function clickLikeButton() {
  const likeButtonSelector =
    '#top-level-buttons-computed > segmented-like-dislike-button-view-model > yt-smartimation > div > div > like-button-view-model > toggle-button-view-model > button > yt-touch-feedback-shape > div';

  // Function to click the like button
  function performClick() {
    const likeButton = document.querySelector(likeButtonSelector);

    if (likeButton) {
      likeButton.click();
      console.log('Like button clicked');
    } else {
      console.log('Like button not found');
    }
  }

  // Wait for 5 seconds before executing the rest of the code
  setTimeout(performClick, 10000); // 5000 milliseconds = 5 seconds

  // Monitor changes in the video title
  let currentTitle = getTitle();

  function getTitle() {
    const titleElement = document.querySelector("#title > h1 > yt-formatted-string");
    return titleElement ? titleElement.textContent : null;
  }

  function checkTitleChange() {
    const newTitle = getTitle();

    if (newTitle !== currentTitle) {
      // Video title has changed, re-run the script
      console.log('Video title has changed, re-running the script...');
      // Update the current title
      currentTitle = newTitle;
    }

    // Check for title changes every 1 second
    setTimeout(checkTitleChange, 1000); // 1000 milliseconds = 1 second
  }

  checkTitleChange();
}

// Call the function to click the like button
clickLikeButton();```
Hom3r86 commented 7 months ago

yours was liking twice and i wanted it in a userscript so i changed it a bit for myself:

// @name         youtube auto like
// @version      1.1
// @description  šŸ‘
// @author       Seth@WiiPlaza
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==
function clickLikeButton() {
  const likeButtonSelector =
    '#top-level-buttons-computed > segmented-like-dislike-button-view-model > yt-smartimation > div > div > like-button-view-model > toggle-button-view-model > button > yt-touch-feedback-shape > div';

  // Function to click the like button
  function performClick() {
    const likeButton = document.querySelector(likeButtonSelector);

    if (likeButton) {
      likeButton.click();
      console.log('Like button clicked');
    } else {
      console.log('Like button not found');
    }
  }

  // Wait for 5 seconds before executing the rest of the code
  setTimeout(performClick, 10000); // 5000 milliseconds = 5 seconds

  // Monitor changes in the video title
  let currentTitle = getTitle();

  function getTitle() {
    const titleElement = document.querySelector("#title > h1 > yt-formatted-string");
    return titleElement ? titleElement.textContent : null;
  }

  function checkTitleChange() {
    const newTitle = getTitle();

    if (newTitle !== currentTitle) {
      // Video title has changed, re-run the script
      console.log('Video title has changed, re-running the script...');
      // Update the current title
      currentTitle = newTitle;
    }

    // Check for title changes every 1 second
    setTimeout(checkTitleChange, 1000); // 1000 milliseconds = 1 second
  }

  checkTitleChange();
}

// Call the function to click the like button
clickLikeButton();```

tried to install it in tampermonkey but i get an error

Enixmage commented 7 months ago

Remove the lines

// Wait for 5 seconds before executing the rest of the code setTimeout(performClick, 5000); // 5000 milliseconds = 5 seconds

and it seems to work till a proper fix at least.