Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution: simple script #5

Open
dennisfrijlink opened this issue Dec 1, 2022 · 3 comments
Open

Solution: simple script #5

dennisfrijlink opened this issue Dec 1, 2022 · 3 comments

Comments

@dennisfrijlink
Copy link

dennisfrijlink commented Dec 1, 2022

I wrote a simple script to just skip ads. It's not optimized but it works:

setInterval(() => {
  if(document.getElementsByClassName("ytp-ad-text").length > 0) {
    const video = document.getElementsByClassName("video-stream html5-main-video")[0];
    video.play();
    video.pause();
    video.currentTime = video.duration;
  }
}, 500);

I use the plugin called Custom JavaScript for Websites 2 to execute this script every time I visit youtube.

@Jonovono
Copy link

It's not perfect, but it works ;p Thanks @dennisfrijlink

@anguschiu1
Copy link

It's very useful, thank you!!

@dennisfrijlink
Copy link
Author

Some issues fixed and added automatic click on overlay close button with this:

function hideAds() {
  if(document.getElementsByClassName("ytp-ad-text").length > 0) {
    const video = document.getElementsByClassName("video-stream html5-main-video")[0];
    video.play();
      video.pause();
      video.currentTime = video.duration;
      const video1 = document.getElementsByClassName("video-stream html5-main-video")[1];
      video1.play();
      video1.pause();
      video1.currentTime = video1.duration;
  }

  if(document.getElementsByClassName("ytp-ad-overlay-close-button").length > 0) {
    document.getElementsByClassName("ytp-ad-overlay-close-button")[0].click();
    document.getElementsByClassName("ytp-ad-overlay-close-button")[1].click();
  }
}

window.setInterval(hideAds, 500);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants