0% found this document useful (0 votes)
10 views2 pages

YouTube Adblock Bypass Script

Uploaded by

autoduckrt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

YouTube Adblock Bypass Script

Uploaded by

autoduckrt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Name: YouTube Anti Anti-Adblock

// Version: 0.9.1
// Author: Wojciech Warpechowski ([Link]
// Source: [Link]
// License: MIT
// Description:
// Simple Chrome Extension to remove anti-adblock on YouTube.
// Currently (16/10/2023) if YouTube finds an adblock, it shows a popup and pauses
the video.
// This script removes the popup and resumes the video.

const isDebug = true; // print logs to console or not

const doc = document;


if (!doc) throw new Error('Document not found');

// Set up a MutationObserver to detect changes


const observer = new MutationObserver(() => {
// detect visible popup container
const popupContainer = [Link]('ytd-popup-container');
if (popupContainer && [Link] !== 'none') {
if (isAdblockPopup(popupContainer)) {
log('Adblock popup found, removing it');
removePopup(popupContainer);
tryToResumeVideo();
} else {
log('Popup found, but it is not Adblock popup');
}
}
});

// Observe changes to the document


[Link](doc, {
childList: true,
subtree: true
});

function isAdblockPopup(popupContainer) {
return popupContainer?.[Link]('ytd-app') &&
[Link]('style-scope') &&
!!([Link]('ytd-enforcement-message-view-model'));
}

function removePopup(popupContainer) {
[Link]();
log('Removed popup container');
}

async function tryToResumeVideo() {


await resumeVideo(); // try to resume video immediately
// Every 50ms until 500ms check if video is paused and try to resume it
let loops = 0;
const interval = 50;
const timer = setInterval(async () => {
log(`Is video paused? (${++loops})`);
const video = [Link]('video');
if (!video) {
log('No video found!');
} else if ([Link]) {
log(`Video is paused, trying resuming again...`);
await resumeVideo();
} else {
log('Video is not paused');
}
if (loops >= 10) {
clearInterval(timer);
}
}, interval);

async function resumeVideo() {


const video = [Link]('video');
try {
if (video?.paused) {
await [Link]();
log('Video resumed');
return video;
} else {
log('No paused video found');
}
} catch (err) {
log('Error resuming video');
log([Link]);
[Link](err);
}
return null;
}
}

function log(message) {
if (isDebug) [Link](`[YouTube Anti Anti-Adblock] ${message}`);
}

You might also like