Skip to content

Instantly share code, notes, and snippets.

@yani
Last active October 19, 2023 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yani/dc0239dfc0d3969c8876beebaf595b38 to your computer and use it in GitHub Desktop.
Save yani/dc0239dfc0d3969c8876beebaf595b38 to your computer and use it in GitHub Desktop.
Youtube AdBlock ban bypass
// ==UserScript==
// @name Youtube AdBlock ban bypass
// @namespace http://tampermonkey.net/
// @version 0.32b
// @description Bypass youtubes new ad block restrictions
// @author Obelous
// @author Yani
// @match https://www.youtube.com/*
// @match https://www.youtube-nocookie.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// @license MIT
// ==/UserScript==
let currentPageUrl = window.location.href;
window.addEventListener('beforeunload', function () {
currentPageUrl = window.location.href;
});
document.addEventListener('yt-navigate-finish', function () {
const newUrl = window.location.href;
if (newUrl !== currentPageUrl) {
location.reload();
}
});
function splitUrl(str) {
return str.split('=')[1];
}
function run() {
console.log("Loaded");
const block = document.querySelector('.yt-playability-error-supported-renderers');
block.parentNode.removeChild(block);
const url = "https://youtube.com/embed/" + splitUrl(window.location.href) + "?autoplay=1";
const oldplayer = document.getElementById("error-screen");
const player = document.createElement('iframe');
player.setAttribute('src', url);
player.style = "height:100%;width:100%;border-radius:12px;";
player.id = "youtube-iframe";
oldplayer.appendChild(player);
console.log('Finished');
}
function waitForElementToLoad(elementSelector, callback) {
var checkInterval = setInterval(function() {
var element = document.querySelector(elementSelector);
if (element) {
clearInterval(checkInterval); // Stop checking
callback(element);
}
}, 100); // Check every 100 milliseconds
}
(function() {
waitForElementToLoad("#error-screen", function(element) {
run();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment