Skip to content

Instantly share code, notes, and snippets.

@bpceee
Last active October 28, 2023 07:14
Show Gist options
  • Save bpceee/e470b99a03f62030855517fdf334f43d to your computer and use it in GitHub Desktop.
Save bpceee/e470b99a03f62030855517fdf334f43d to your computer and use it in GitHub Desktop.
youtube iframe injector
// ==UserScript==
// @name youtube frame
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
if (window.top !== window.self){
console.log("wtf")
return
}
let called = false
const replace = () => {
const element = document.getElementById("full-bleed-container");
let params = new URL(document.location).searchParams;
let vid = params.get('v')
var parser = new DOMParser();
var newNode = parser.parseFromString(`<iframe width="100%" height="100%" src="https://www.youtube.com/embed/${vid}?&autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>`, "text/html");
element.textContent=''
element.appendChild(newNode.documentElement);
element.children[0].style.height = '100%'
element.children[0].style.width = '100%'
element.children[0].children[1].style.height = '100%'
element.children[0].children[1].style.width = '100%'
}
function checkForElement() {
const element = document.getElementById("full-bleed-container");
if (element) {
if(called)return
replace(element)
called = true
observer.disconnect()
}
}
const config = { childList: true, subtree: true };
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === "childList") {
checkForElement();
}
});
});
observer.observe(document.body, config);
// Your code here...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment