Last active
November 3, 2023 10:01
-
-
Save fsantini/1eea5306d0c84dcc37d325f57d464b46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Youtube workaround | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Work around the youtube adblock limitation | |
// @author You | |
// @match http*://*.youtube.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
// @require https://code.jquery.com/jquery-3.7.1.min.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function embedVideo() | |
{ | |
//console.log("*********************** embedding video"); | |
function do_embed(jNd) | |
{ | |
//console.log("****************************** ytd-enforcement appeared"); | |
const url = new URL(window.location.href); | |
const params = new URLSearchParams(url.search); | |
const video = params.get("v"); | |
//console.log("****************************** " + video); | |
jNd.empty(); | |
jNd.append('<iframe width="100%" height="100%" src="https://www.youtube.com/embed/' + video + '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>') | |
} | |
const elm = $('ytd-enforcement-message-view-model') | |
if (elm.length) | |
{ | |
do_embed(elm); | |
} else | |
{ | |
//console.log('***************** waiting for element'); | |
waitForKeyElements("ytd-enforcement-message-view-model", do_embed); | |
} | |
} | |
let currentHref = ''; | |
setInterval(function() { | |
if (window.location.href !== currentHref) { | |
//console.log('**************** Location changed!', window.location.href); | |
currentHref = window.location.href; | |
if (currentHref.includes('/watch')) | |
{ | |
embedVideo(); | |
} | |
} | |
}, 100); // Check every 100ms | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment