-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyabrr.user.js
394 lines (338 loc) · 14.3 KB
/
yabrr.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
(function() {
const adblocker = true;
const removePopup = false;
const updateCheck = true;
const debugMessages = true;
const fixTimestamps = true;
const updateModal = {
enable: true,
timer: 5000,
};
let currentUrl = window.location.href;
let isVideoPlayerModified = false;
let hasIgnoredUpdate = false;
log("Script started");
if (adblocker) removeAds();
if (removePopup) popupRemover();
if (updateCheck) checkForUpdate();
if (fixTimestamps) timestampFix();
function popupRemover() {
setInterval(() => {
const modalOverlay = document.querySelector("tp-yt-iron-overlay-backdrop");
const popup = document.querySelector(".style-scope ytd-enforcement-message-view-model");
const popupButton = document.getElementById("dismiss-button");
var video = document.querySelector('video');
const bodyStyle = document.body.style;
bodyStyle.setProperty('overflow-y', 'auto', 'important');
if (modalOverlay) {
modalOverlay.removeAttribute("opened");
modalOverlay.remove();
}
if (popup) {
log("Popup detected, removing...");
if(popupButton) popupButton.click();
popup.remove();
video.play();
setTimeout(() => {
video.play();
}, 500);
log("Popup removed");
}
if (!video.paused) return;
video.play();
}, 1000);
}
function removeAds() {
log("removeAds()");
setInterval(() => {
if (window.location.href !== currentUrl) {
currentUrl = window.location.href;
isVideoPlayerModified = false;
clearAllPlayers();
removePageAds();
}
if (window.location.href.includes("shorts")) {
log("Youtube shorts detected, ignoring...");
return;
}
if (isVideoPlayerModified){
removeAllDuplicateVideos();
return;
}
log("Video replacement started!");
var video = document.querySelector('video');
if (video) video.volume = 0;
if (video) video.pause();
if (video) video.remove();
if (!clearAllPlayers()) {
return;
}
let errorScreen = document.querySelector("#error-screen");
if (errorScreen) {
errorScreen.remove();
}
let videoID = '';
let playList = '';
let timeStamp = '';
const url = new URL(window.location.href);
const urlParams = new URLSearchParams(url.search);
if (urlParams.has('v')) {
videoID = urlParams.get('v');
} else {
const pathSegments = url.pathname.split('/');
const liveIndex = pathSegments.indexOf('live');
if (liveIndex !== -1 && liveIndex + 1 < pathSegments.length) {
videoID = pathSegments[liveIndex + 1];
}
}
if (urlParams.has('list')) {
playList = "&listType=playlist&list=" + urlParams.get('list');
}
if (urlParams.has('t')) {
timeStamp = "&start=" + urlParams.get('t').replace('s', '');
}
if (!videoID) {
log("YouTube video URL not found.", "e");
return null;
}
log("Video ID: " + videoID);
const startOfUrl = "https://www.youtube-nocookie.com/embed/";
const endOfUrl = "?autoplay=1&modestbranding=1&rel=0";
const finalUrl = startOfUrl + videoID + endOfUrl;
const iframe = document.createElement('iframe');
iframe.setAttribute('src', finalUrl);
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share');
iframe.setAttribute('allowfullscreen', true);
iframe.setAttribute('mozallowfullscreen', "mozallowfullscreen");
iframe.setAttribute('msallowfullscreen', "msallowfullscreen");
iframe.setAttribute('oallowfullscreen', "oallowfullscreen");
iframe.setAttribute('webkitallowfullscreen', "webkitallowfullscreen");
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.left = '0';
iframe.style.zIndex = '9999';
iframe.style.pointerEvents = 'all';
const videoPlayerElement = document.querySelector('.html5-video-player');
videoPlayerElement.appendChild(iframe);
log("Finished");
isVideoPlayerModified = true;
}, 500);
removePageAds();
}
function removeAllDuplicateVideos() {
const videos = document.querySelectorAll('video');
videos.forEach(video => {
if (video.src.includes('www.youtube.com')) {
video.muted = true;
video.pause();
video.addEventListener('volumechange', function() {
if (!video.muted) {
video.muted = true;
video.pause();
log("Video unmuted detected and remuted");
}
});
video.addEventListener('play', function() {
video.pause();
log("Video play detected and repaused");
});
log("Duplicate video found and muted");
}
});
}
function clearAllPlayers() {
const videoPlayerElements = document.querySelectorAll('.html5-video-player');
if (videoPlayerElements.length === 0) {
console.error("No elements with class 'html5-video-player' found.");
return false;
}
videoPlayerElements.forEach(videoPlayerElement => {
const iframes = videoPlayerElement.querySelectorAll('iframe');
iframes.forEach(iframe => {
iframe.remove();
});
});
console.log("Removed all current players!");
return true;
}
function removePageAds(){
const sponsor = document.querySelectorAll("div#player-ads.style-scope.ytd-watch-flexy, div#panels.style-scope.ytd-watch-flexy");
const style = document.createElement('style');
style.textContent = `
ytd-action-companion-ad-renderer,
ytd-display-ad-renderer,
ytd-video-masthead-ad-advertiser-info-renderer,
ytd-video-masthead-ad-primary-video-renderer,
ytd-in-feed-ad-layout-renderer,
ytd-ad-slot-renderer,
yt-about-this-ad-renderer,
yt-mealbar-promo-renderer,
ytd-statement-banner-renderer,
ytd-ad-slot-renderer,
ytd-in-feed-ad-layout-renderer,
ytd-banner-promo-renderer-background
statement-banner-style-type-compact,
.ytd-video-masthead-ad-v3-renderer,
div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint,
div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer,
div#main-container.style-scope.ytd-promoted-video-renderer,
div#player-ads.style-scope.ytd-watch-flexy,
ad-slot-renderer,
ytm-promoted-sparkles-web-renderer,
masthead-ad,
tp-yt-iron-overlay-backdrop,
#masthead-ad {
display: none !important;
}
`;
document.head.appendChild(style);
sponsor?.forEach((element) => {
if (element.getAttribute("id") === "rendering-content") {
element.childNodes?.forEach((childElement) => {
if (childElement?.data.targetId && childElement?.data.targetId !=="engagement-panel-macro-markers-description-chapters"){
element.style.display = 'none';
}
});
}
});
log("Removed page ads (✔️)");
}
function changeTimestamp(timestamp) {
const videoPlayerElements = document.querySelectorAll('.html5-video-player');
videoPlayerElements.forEach(videoPlayerElement => {
const iframes = videoPlayerElement.querySelectorAll('iframe');
iframes.forEach(iframe => {
if (iframe.src.includes("&start=")) {
iframe.src = iframe.src.replace(/&start=\d+/, "&start=" + timestamp);
} else {
iframe.src += "&start=" + timestamp;
}
});
});
}
function timestampFix() {
document.addEventListener('click', function(event) {
const target = event.target;
if (target.classList.contains('yt-core-attributed-string__link') && target.href.includes('&t=')) {
event.preventDefault();
const timestamp = target.href.split('&t=')[1].split('s')[0];
log(`Timestamp link clicked: ${timestamp} seconds`);
changeTimestamp(timestamp);
}
});
}
function observerCallback(mutations) {
let isVideoAdded = mutations.some(mutation =>
Array.from(mutation.addedNodes).some(node => node.tagName === 'VIDEO')
);
if (isVideoAdded) {
log("New video detected, checking for duplicates.");
if (window.location.href.includes("shorts")) {
log("Youtube shorts detected, ignoring...");
return;
}
removeAllDuplicateVideos();
}
}
const observer = new MutationObserver(observerCallback);
observer.observe(document.body, { childList: true, subtree: true });
function checkForUpdate(){
if (window.top !== window.self && !(window.location.href.includes("youtube.com"))){
return;
}
if (hasIgnoredUpdate){
return;
}
const scriptUrl = 'https://raw.githubusercontent.com/TheRealJoelmatic/RemoveAdblockThing/main/Youtube-Ad-blocker-Reminder-Remover.user.js';
fetch(scriptUrl)
.then(response => response.text())
.then(data => {
const match = data.match(/@version\s+(\d+\.\d+)/);
if (!match) {
log("Unable to extract version from the GitHub script.", "e")
return;
}
const githubVersion = parseFloat(match[1]);
const currentVersion = parseFloat(GM_info.script.version);
if (githubVersion <= currentVersion) {
log('You have the latest version of the script. ' + githubVersion + " : " + currentVersion);
return;
}
console.log('Remove Adblock Thing: A new version is available. Please update your script. ' + githubVersion + " : " + currentVersion);
if(updateModal.enable){
if (parseFloat(localStorage.getItem('skipRemoveAdblockThingVersion')) === githubVersion) {
return;
}
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/sweetalert2@11';
document.head.appendChild(script);
const style = document.createElement('style');
style.textContent = '.swal2-container { z-index: 2400; }';
document.head.appendChild(style);
script.onload = function () {
Swal.fire({
position: "top-end",
backdrop: false,
title: 'Remove Adblock Thing: New version is available.',
text: 'Do you want to update?',
showCancelButton: true,
showDenyButton: true,
confirmButtonText: 'Update',
denyButtonText:'Skip',
cancelButtonText: 'Close',
timer: updateModal.timer ?? 5000,
timerProgressBar: true,
didOpen: (modal) => {
modal.onmouseenter = Swal.stopTimer;
modal.onmouseleave = Swal.resumeTimer;
}
}).then((result) => {
if (result.isConfirmed) {
window.location.replace(scriptUrl);
} else if(result.isDenied) {
localStorage.setItem('skipRemoveAdblockThingVersion', githubVersion);
}
});
};
script.onerror = function () {
var result = window.confirm("Remove Adblock Thing: A new version is available. Please update your script.");
if (result) {
window.location.replace(scriptUrl);
}
}
} else {
var result = window.confirm("Remove Adblock Thing: A new version is available. Please update your script.");
if (result) {
window.location.replace(scriptUrl);
}
}
})
.catch(error => {
hasIgnoredUpdate = true;
log("Error checking for updates:", "e", error)
});
hasIgnoredUpdate = true;
}
function log(log, level, ...args) {
if(!debugMessages)
return;
const prefix = '🔧 Remove Adblock Thing:';
const message = `${prefix} ${log}`;
switch (level) {
case 'error':
console.error(`❌ ${message}`, ...args);
break;
case 'log':
console.log(`✅ ${message}`, ...args);
break;
case 'warning':
console.warn(`⚠️ ${message}`, ...args);
break;
default:
console.info(`ℹ️ ${message}`, ...args);
}
}
})();