-
Notifications
You must be signed in to change notification settings - Fork 12
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
Comments
It's not perfect, but it works ;p Thanks @dennisfrijlink |
It's very useful, thank you!! |
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); |
function hideAds() {
const adTextElements = document.getElementsByClassName("ytp-ad-text");
if (adTextElements.length > 0) {
const videos = document.getElementsByClassName("video-stream html5-main-video");
if (videos.length > 0) {
const video = videos[0];
video.play();
video.pause();
video.currentTime = video.duration;
if (videos.length > 1) {
const video1 = videos[1];
video1.play();
video1.pause();
video1.currentTime = video1.duration;
}
}
}
const adOverlayCloseButtons = document.getElementsByClassName("ytp-ad-overlay-close-button");
if (adOverlayCloseButtons.length > 0) {
for (let i = 0; i < adOverlayCloseButtons.length; i++) {
adOverlayCloseButtons[i].click();
}
}
}
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.addedNodes.length > 0) {
hideAds();
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
hideAds(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote a simple script to just skip ads. It's not optimized but it works:
I use the plugin called Custom JavaScript for Websites 2 to execute this script every time I visit youtube.
The text was updated successfully, but these errors were encountered: