YAAS (YouTube Ads Auto Skip)

Automatically closes the banner ad or clicks the "Skip ad" button and likes video if you subscribe to the channel.

目前為 2021-04-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name           YAAS (YouTube Ads Auto Skip)
// @description    Automatically closes the banner ad or clicks the "Skip ad" button and likes video if you subscribe to the channel.
// @name:uk        YAAS (Автоматичний пропуск реклами на YouTube)
// @description:uk Автоматично закриває рекламний банер чи клікає по кнопці "Пропустити рекламу" та ставить лайк, якщо є підписка на канал.
// @version        2.0.1
// @namespace      https://gf.qytechs.cn/uk/users/741855
// @author         boboha
// @match          https://www.youtube.com/*
// ==/UserScript==

(function() {
    'use strict';

    let skiped = true;
    const SEC = 1000,
          TO_VIDEO = 1 * SEC,
          TO_BANER = 0 * SEC,
          TO_VIDEO_SUBSCIBED = 40 * SEC,
          TO_BANER_SUBSCIBED = 15 * SEC,
          log = (msg) => {console.log('[YAAS]', msg);},
          toggleSkiped = () => {skiped = !skiped;},
          isSubscribed = () => document.querySelector('#subscribe-button [subscribed]') ? true : false,
          checkLike = () => {
              const like = document.querySelector('#info #menu ytd-toggle-button-renderer');
              if (isSubscribed() && !like.className.endsWith('style-default-active')) {
                  like.click();
                  log('👍 Ok!');
             }
          },
          skipVideo = (btn) => {
              const timeout = (isSubscribed()) ? TO_VIDEO_SUBSCIBED : TO_VIDEO;
              setTimeout(() => {
                  skip(btn);
              }, timeout);
              log('Video skip timeout: ' + timeout/SEC + 'sec');
          },
          skip = (btn) => {
              toggleSkiped();
              if (btn.nodeType === 1 && getComputedStyle(btn).display === 'inline-block') {
                  btn.click();
                  log('Video skiped!');
              }
              setTimeout(toggleSkiped, 5000);
          },
          closeBaner = (btn) => {
              const timeout = (isSubscribed()) ? TO_BANER_SUBSCIBED : TO_BANER;
              setTimeout(() => {
                  btn.click();
                  log('Baner closed!');
              }, timeout);
              log('Baner close timeout: ' + timeout/SEC + 'sec');
          },
          observer = new MutationObserver(mutations => {
              if (location.pathname == '/watch') {
                  checkLike();
                  for (const mutation of mutations) {
                      if (skiped) {
                          try {
                              if (mutation.target.className === 'video-ads ytp-ad-module' && mutation.addedNodes.length) {
                                  // Video loading
                                  if (mutation.addedNodes[0].className === 'ytp-ad-player-overlay') {
                                      log('Video loaded...');
                                  }
                                  // Baner loading
                                  else if (mutation.addedNodes[0].className === 'ytp-ad-overlay-slot') {
                                      log('Baner loaded...');
                                      // Baner closing
                                      const close_button = mutation.addedNodes[0].querySelector('.ytp-ad-overlay-close-container > .ytp-ad-overlay-close-button');
                                      close_button && closeBaner(close_button);
                                  }
                              }

                              // Video skiping
                              if (mutation.target.className === 'ytp-ad-skip-button-slot') {
                                  const skip_button = mutation.target.querySelector('.ytp-ad-skip-button-container > .ytp-ad-skip-button');
                                  skip_button && skipVideo(skip_button);
                              }
                          } catch (e) {
                              console.groupCollapsed(e.message, mutation.target);
                              console.log(mutation);
                              console.groupEnd();
                          }
                      }
                  }
              }
          }),
          init = () => {
              const player = document.querySelector('#movie_player');
              if (player) {
                  observer.observe(player, {childList: true, attributes: true, subtree: true});
                  log('Init');
              } else {
                  setTimeout(init, 100);
              }
          }

    init();

})();

QingJ © 2025

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