youtube Automatic like

Watch the video for 2 minutes and like it to support the video you like

// ==UserScript==
// @name         youtube Automatic like
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Watch the video for 2 minutes and like it to support the video you like
// @author       You
// @match        https://www.youtube.com/watch?v=*
// @match        https://www.youtube.com/shorts/rBG1NSBajpw
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {
  function isVideoPlaying(video) {
    return !!(video && !video.paused && !video.ended && video.readyState > 2);
  }

  setTimeout(() => {
    const video = document.querySelector('video.html5-main-video');
    if (isVideoPlaying(video)) {
      

      if (video.hasAttribute('data-no-fullscreen')) {
        const ytLikeBtn = document.querySelector('button.yt-spec-button-shape-next');
        if (ytLikeBtn) {
          ytLikeBtn.click();
          showMsg('已按讚 (YT)');
        }
      } else {
        // 一般影片
        const likeButton = document.querySelector('button[title="我喜歡"]');
        if (likeButton) {
          likeButton.click();
          showMsg('已按讚');
        }
      }
    }

  }, 120000);

  function showMsg(text) {
    const msg = document.createElement('div');
    msg.textContent = text;
    Object.assign(msg.style, {
      position: 'fixed',
      left: '50%',
      transform: 'translateX(-50%)',
      top: '30%',
      padding: '10px 20px',
      background: 'rgba(0,0,0,0.8)',
      color: '#fff',
      borderRadius: '8px',
      zIndex: 9999,
      fontSize: '16px',
      opacity: '0',
      transition: 'opacity 0.3s'
    });
    document.body.appendChild(msg);

    setTimeout(() => { msg.style.opacity = '1'; }, 10);
    setTimeout(() => {
      msg.style.opacity = '0';
      setTimeout(() => {
        document.body.removeChild(msg);
      }, 300);
    }, 2500);
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址