Last active
May 14, 2026 05:28
-
-
Save GasparVardanyan/b19b7c0a351482e3a098c2cf4c5bb6e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ytlocal | |
| // @version 1.0 | |
| // @description ytlocal | |
| // @match *://*.youtube.com/watch?* | |
| // @grant none | |
| // @run-at document-end | |
| // ==/UserScript== | |
| (function () { | |
| let h = ''; | |
| function removeAds() { | |
| let container = document.querySelector("#ytd-player #container"); | |
| let hc = encodeURIComponent (window.location.href); | |
| if (container && hc != h) { | |
| h = hc; | |
| container.replaceChildren(); | |
| let iframe = document.createElement("iframe"); | |
| iframe.src = "http://127.0.0.1:5000/watch?url=" + hc + "&quality=720"; | |
| iframe.style.width = "100%"; | |
| iframe.style.height = "100%"; | |
| container.appendChild(iframe); | |
| // observer.disconnect (); | |
| } | |
| document.querySelectorAll("video").forEach(v => v.remove()); | |
| } | |
| let observer; | |
| let alive = false; | |
| function startObserving () { | |
| if (observer) observer.disconnect (); | |
| h = ''; | |
| removeAds (); | |
| observer = new MutationObserver(mutationsList => { | |
| alive = true; | |
| for(let mutation of mutationsList) { | |
| if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { | |
| removeAds(); | |
| } else if (mutation.type === 'attributes' && mutation.attributeName === 'style') { | |
| removeAds(); | |
| } | |
| } | |
| }); | |
| observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true }); | |
| } | |
| startObserving (); | |
| // window.addEventListener('load', removeAds); | |
| setTimeout(function () { | |
| setInterval(function () { | |
| alive = false; | |
| // trigger mutation | |
| const x = document.createElement("div"); | |
| document.body.appendChild(x); | |
| x.remove(); | |
| setTimeout(function () { | |
| if (false == alive) { | |
| startObserving(); | |
| console.log ("OBSERVING"); | |
| } | |
| }, 0); | |
| }, 1000); | |
| }, 1000); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment