Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Last active August 25, 2020 08:17
Show Gist options
  • Save nathan130200/3d9e05bea724f9e67f1e584edc85ca29 to your computer and use it in GitHub Desktop.
Save nathan130200/3d9e05bea724f9e67f1e584edc85ca29 to your computer and use it in GitHub Desktop.
Automatic skip-ad and hide ad elements in youtube without use AD-Block, this script don't remove AD-Elements, just hide from page.
// ==UserScript==
// @name YoutubeSkipAd
// @version 1.6.3
// @description Automatic skip-ad and hide in youtube.
// @author FRNathan13
// @include /(http|https):\/\/www.youtube.com\/(.*)
// @grant none
// ==/UserScript==
(function() {
setInterval(function() {
var overlay_close_button = document.querySelector('.ytp-ad-overlay-close-button');
if(overlay_close_button != undefined){
overlay_close_button.click();
console.log("[YOUTUBE-AD] Element '.ytp-ad-overlay-close-button' hidden.");
}
var ad_skip_button = document.querySelector('.ytp-ad-skip-button.ytp-button');
if(ad_skip_button != undefined) {
ad_skip_button.click();
console.info("[YOUTUBE-AD] Ad button '.ytp-ad-skip-button.ytp-button' clicked.");
}
var google_companion_ad_div = document.querySelector('#google_companion_ad_div')
if(google_companion_ad_div != undefined && google_companion_ad_div.style.display != 'none') {
google_companion_ad_div.style.display = 'none';
console.info("[YOUTUBE-AD] Element '#google_companion_ad_div' hidden.");
}
var container_iframe = document.querySelector("#container > iframe");
if(container_iframe != undefined && container_iframe.style.display != 'none') {
container_iframe.style.display = 'none';
console.info("[YOUTUBE-AD] Container Element '#container > iframe' hidden.");
}
document.querySelectorAll('.style-scope.ytd-action-companion-ad-renderer')
.forEach(e => { e.style.display = 'none' });
var player_ads = document.querySelector('#player-ads');
if(player_ads != undefined && player_ads.style.display != 'none') {
player_ads.style.display = 'none';
console.info("[YOUTUBE-AD] Element '#player-ads' hidden.");
}
var ad_skip_text = document.querySelector('.ytp-ad-text.ytp-ad-skip-button-text');
if(ad_skip_text != undefined){
ad_skip_text.click();
console.log("[YOUTUBE-AD] Ad button '.ad_skip_text' clicked.");
}
}, 0.25);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment