Skip to content

Instantly share code, notes, and snippets.

@jonschr
Created July 25, 2023 20:10
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 jonschr/9120118eb3097b3d413f9019d04b7ae6 to your computer and use it in GitHub Desktop.
Save jonschr/9120118eb3097b3d413f9019d04b7ae6 to your computer and use it in GitHub Desktop.
Force oembed to not show related videos
// Get all the iframes present on the page
const iframes = document.querySelectorAll('iframe');
// Loop through each iframe to check if it contains "youtube.com" in its src
for (const iframe of iframes) {
const src = iframe.getAttribute('src');
if (src.includes('youtube.com')) {
// Append ?rel=0 to the existing src
const modifiedSrc = src + '?rel=0';
iframe.setAttribute('src', modifiedSrc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment