-
-
Save Ravlissimo/b92983d370706b8a4f7ba7ff390a1e38 to your computer and use it in GitHub Desktop.
YouTube
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
| My youtube scripts/extensions |
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
| // Simple script that replaces youtube playback error with embedded video | |
| const delay = (ms) => { | |
| return new Promise(resolve => setTimeout(resolve, ms)); | |
| } | |
| async function start() { | |
| while (true) { | |
| if (!document.querySelector("#replace-success")) { | |
| await replacePlaybackError(); | |
| } | |
| else { | |
| await updateSrc(); | |
| } | |
| await delay(1000); | |
| } | |
| } | |
| async function replacePlaybackError() { | |
| const iframePartOne = "<iframe id='replace-success' width='100%' height='100%' src='https://www.youtube.com/embed/"; | |
| const iframePartTwo = "' title='YouTube video player' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share' allowfullscreen></iframe>"; | |
| while (!document.querySelector("yt-playability-error-supported-renderers")) { | |
| await delay(500); | |
| } | |
| let id = (new URL(document.location)).searchParams.get("v"); | |
| let iframe = iframePartOne + id + iframePartTwo; | |
| document.querySelector("yt-playability-error-supported-renderers").innerHTML = iframe; | |
| } | |
| async function updateSrc() { | |
| let id = (new URL(document.location)).searchParams.get("v"); | |
| let src = 'https://www.youtube.com/embed/' + id; | |
| let iframe = document.querySelector("#replace-success"); | |
| if (src === iframe.src) { | |
| await delay(5000); | |
| } | |
| else { | |
| iframe.src = src; | |
| } | |
| } | |
| start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment