forked from TheRealJoelmatic/RemoveAdblockThing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouTube Adblock Warning Remover.user.js
More file actions
166 lines (145 loc) · 5.02 KB
/
YouTube Adblock Warning Remover.user.js
File metadata and controls
166 lines (145 loc) · 5.02 KB
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
156
157
158
159
160
161
162
163
164
165
166
// ==UserScript==
// @name Remove Adblock Thing
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Removes Adblock Thing
// @author JoelMatic
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
(function()
{
//
// Config
//
// Enable The Undetected Adblocker
const adblocker = true;
// Enable The Popup remover
const removePopup = true;
// Enable debug messages into the console
const debug = true;
//
// CODE
//
// Specify domains and JSON paths to remove
const domainsToRemove = [
'*.youtube-nocookie.com/*'
];
const jsonPathsToRemove = [
'playerResponse.adPlacements',
'playerResponse.playerAds',
'adPlacements',
'playerAds',
'playerConfig',
'auxiliaryUi.messageRenderers.enforcementMessageViewModel'
];
// Observe config
const observerConfig = {
childList: true,
subtree: true
};
//This is used to check if the video has been unpaused already
let unpausedAfterSkip = 0;
if (debug) console.log("Remove Adblock Thing: Remove Adblock Thing: Script started");
// Old variable but could work in some cases
window.__ytplayer_adblockDetected = false;
if(adblocker) addblocker();
if(removePopup) popupRemover();
if(removePopup) observer.observe(document.body, observerConfig);
// Remove Them pesski popups
function popupRemover() {
removeJsonPaths(domainsToRemove, jsonPathsToRemove);
setInterval(() => {
const popup = document.querySelector(".style-scope ytd-enforcement-message-view-model");
const video1 = document.querySelector("#movie_player > video.html5-main-video");
const video2 = document.querySelector("#movie_player > .html5-video-container > video");
const modalOverlay = document.querySelector("tp-yt-iron-overlay-backdrop");
if (popup) {
document.getElementById("dismiss-button").click();
document.getElementsByClassName("ytp-play-button ytp-button")[0].click();
if (debug) console.log("Remove Adblock Thing: Popup detected, removing...");
popup.remove();
if (modalOverlay) modalOverlay.removeAttribute("opened");
unpausedAfterSkip = 2;
if (debug) console.log("Remove Adblock Thing: Popup removed");
}
// Check if the video is paused after removing the popup
if (!unpausedAfterSkip > 0) return;
if (video1) {
// UnPause The Video
if (video1.paused) unPauseVideo();
else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}
if (video2) {
if (video2.paused) unPauseVideo();
else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}
}, 1000);
}
// undetected adblocker method
function addblocker()
{
setInterval(() =>
{
const skipBtn = document.querySelector('.videoAdUiSkipButton,.ytp-ad-skip-button');
const ad = [...document.querySelectorAll('.ad-showing')][0];
const sidAd = document.querySelector('ytd-action-companion-ad-renderer');
if (ad)
{
document.querySelector('video').playbackRate = 10;
if(skipBtn)
{
skipBtn.click();
}
}
if (sidAd)
{
sidAd.remove();
}
}, 50)
}
// Unpause the video Works most of the time
function unPauseVideo()
{
// Simulate pressing the "k" key to unpause the video
const keyEvent = new KeyboardEvent("keydown",{
key: "k",
code: "KeyK",
keyCode: 75,
which: 75,
bubbles: true,
cancelable: true,
view: window
});
document.dispatchEvent(keyEvent);
unpausedAfterSkip = 0;
if (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 =>{
const pathParts = jsonPath.split('.');
let obj = window;
for (const part of pathParts)
{
if (obj.hasOwnProperty(part))
{
obj = obj[part];
}
else
{
break;
}
}
obj = undefined;
});
}
// Observe and remove ads when new content is loaded dynamically
const observer = new MutationObserver(() =>
{
removeJsonPaths(domainsToRemove, jsonPathsToRemove);
});
})();