Skip to content

Instantly share code, notes, and snippets.

@keesiemeijer
Last active October 19, 2022 20:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keesiemeijer/b12191e2ea55eb60df867d56a7ae0578 to your computer and use it in GitHub Desktop.
Save keesiemeijer/b12191e2ea55eb60df867d56a7ae0578 to your computer and use it in GitHub Desktop.
Youtube skip ads and remove overlay ads after 3 seconds
// ==UserScript==
// @name Youtube SkipAd
// @namespace keesiemeijer
// @version 0.1
// @description Automatically skips ads after 5 seconds
// @author keesiemeijer
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
addGlobalStyle('.ytp-ad-overlay-slot { display: none !important; }');
addGlobalStyle('.ytp-ad-image-overlay { display: none !important; }');
addGlobalStyle('.ytp-ad-overlay-image { display: none !important; }');
addGlobalStyle('.ytp-ad-overlay-container { display: none !important; }');
window.setInterval(
function () {
var elmButton = document.querySelector('.ytp-ad-skip-button');
if (elmButton) {
elmButton.click();
}
},
3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment