-
Notifications
You must be signed in to change notification settings - Fork 2
/
youtube_adblock.js
51 lines (50 loc) · 1.84 KB
/
youtube_adblock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// ==UserScript==
// @name Skip youtube ads
// @version 1.0.0
// @description Skips YouTube ads automatically
// @author afreakk
// @match *://*.youtube.com/*
// @exclude *://*.youtube.com/subscribe_embed?*
// ==/UserScript==
const skipAd = () => {
document
.querySelectorAll(
'.videoAdUiSkipButton,.ytp-ad-skip-button,.ytp-ad-skip-button-modern'
)
.forEach((b) => b.click());
if (document.querySelector('.ad-showing')) {
document.querySelectorAll('video').forEach((v) => {
Number.isNaN(v.duration) || (v.currentTime = v.duration);
});
}
// this is the interspersed ads around the recommended/related videos
for (const el of document.getElementsByTagName('ytd-ad-slot-renderer')) {
if (
el?.parentElement?.parentElement?.tagName ===
'YTD-RICH-ITEM-RENDERER'
) {
el?.parentElement?.parentElement?.remove();
} else {
el?.remove();
}
}
// in youtube-shorts we get some ads, try remove them
// (this ain't working, freezes the whole thing)
// for (const el of document.getElementsByClassName('ad-created')) {
// if (
// el?.parentElement?.parentElement?.parentElement?.parentElement
// ?.parentElement?.parentElement?.tagName ===
// 'YTD-REEL-VIDEO-RENDERER'
// ) {
// el?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.remove();
// }
// }
// in related videos, this is the ad on top
document.getElementById('player-ads')?.remove();
document
.querySelectorAll('.ytd-mealbar-promo-renderer#dismiss-button')
.forEach((el) => el.click());
};
if (!window.skipAdIntervalID) {
window.skipAdIntervalID = setInterval(skipAd, 333);
}