-
Notifications
You must be signed in to change notification settings - Fork 4
/
Youtube-Ad-blocker-Remover.user.js
155 lines (130 loc) · 5.51 KB
/
Youtube-Ad-blocker-Remover.user.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// ==UserScript==
// @name Remove Adblock Thing
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Removes Adblock Thing
// @author chokiproai
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @updateURL https://github.com/chokiproai/RemoveAdblockYoutube/raw/main/Youtube-Ad-blocker-Remover.user.js
// @downloadURL https://github.com/chokiproai/RemoveAdblockYoutube/raw/main/Youtube-Ad-blocker-Remover.user.js
// @grant none
// ==/UserScript==
(function() {
const config = {
adblocker: true,
removePopup: true,
debug: true,
};
const domainsToRemove = ['*.youtube-nocookie.com/*'];
const jsonPathsToRemove = [
'playerResponse.adPlacements',
'playerResponse.playerAds',
'adPlacements',
'playerAds',
'playerConfig',
'auxiliaryUi.messageRenderers.enforcementMessageViewModel'
];
const observerConfig = {
childList: true,
subtree: true
};
const keyEvent = new KeyboardEvent("keydown", {
key: "k",
code: "KeyK",
keyCode: 75,
which: 75,
bubbles: true,
cancelable: true,
view: window
});
const mouseEvent = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
});
if (config.debug) console.log("Remove Adblock Thing: Script started");
window.__ytplayer_adblockDetected = false;
if (config.adblocker) removeAdblockerStuff();
if (config.removePopup) removePopups();
const observer = new MutationObserver(() => {
removeJsonPaths(domainsToRemove, jsonPathsToRemove);
});
observer.observe(document.body, observerConfig);
function removePopups() {
setInterval(() => {
const fullScreenButton = document.querySelector(".ytp-fullscreen-button");
const modalOverlay = document.querySelector("tp-yt-iron-overlay-backdrop");
const popup = document.querySelector(".style-scope ytd-enforcement-message-view-model");
const elementToRemove = document.querySelector('tp-yt-paper-dialog');
const popupButton = document.getElementById("dismiss-button");
const video1 = document.querySelector("#movie_player > video.html5-main-video");
const video2 = document.querySelector("#movie_player > .html5-video-container > video");
const bodyStyle = document.body.style;
bodyStyle.setProperty('overflow-y', 'scroll', 'important');
if (modalOverlay) {
modalOverlay.removeAttribute("opened");
modalOverlay.remove();
}
if (popup) {
if (config.debug) console.log("Remove Adblock Thing: Popup detected, removing...");
if (popupButton) popupButton.click();
popup.remove();
unpausedAfterSkip = 2;
fullScreenButton.dispatchEvent(mouseEvent);
setTimeout(() => {
fullScreenButton.dispatchEvent(mouseEvent);
}, 500);
if (config.debug) console.log("Remove Adblock Thing: Popup removed");
}
if (!unpausedAfterSkip > 0) return;
if (video1) {
if (video1.paused) unPauseVideo();
else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}
if (video2) {
if (video2.paused) unPauseVideo();
else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}
}, 1000);
}
function removeAdblockerStuff() {
setInterval(() => {
const skipBtn = document.querySelector('.videoAdUiSkipButton,.ytp-ad-skip-button');
const ad = document.querySelector('.ad-showing');
const sidAd = document.querySelector('ytd-action-companion-ad-renderer');
const displayAd = document.querySelector('div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint');
const sparklesContainer = document.querySelector('div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer');
const mainContainer = document.querySelector('div#main-container.style-scope.ytd-promoted-video-renderer');
const feedAd = document.querySelector('ytd-in-feed-ad-layout-renderer');
const mastheadAd = document.querySelector('.ytd-video-masthead-ad-v3-renderer');
if (ad) {
const video = document.querySelector('video');
video.playbackRate = 10;
video.volume = 0;
video.currentTime = video.duration;
skipBtn?.click();
}
[sidAd, displayAd, sparklesContainer, mainContainer, feedAd, mastheadAd].forEach(el => {
if (el) el.remove();
});
}, 50);
}
function unPauseVideo() {
document.dispatchEvent(keyEvent);
unpausedAfterSkip = 0;
if (config.debug) console.log("Remove Adblock Thing: Unpaused video using 'k' key");
}
function removeJsonPaths(domains, jsonPaths) {
const currentDomain = window.location.hostname;
if (!domains.includes(currentDomain)) return;
jsonPaths.forEach(jsonPath => {
let obj = window;
for (const part of jsonPath.split('.')) {
if (!obj.hasOwnProperty(part)) break;
obj = obj[part];
}
obj = undefined;
});
}
})();