YouTube Embedded Video Link

Adds a shortcut to open the embedded video page on YouTube video pages

  1. // ==UserScript==
  2. // @name YouTube Embedded Video Link
  3. // @namespace https://kennedn.com
  4. // @license MIT
  5. // @version 1.0
  6. // @description Adds a shortcut to open the embedded video page on YouTube video pages
  7. // @author Your Name
  8. // @match https://www.youtube.com/watch?v=*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to extract video ID from YouTube video URL
  16. function getVideoId() {
  17. const urlParams = new URLSearchParams(window.location.search);
  18. return urlParams.get('v');
  19. }
  20.  
  21. // Function to navigate to the embedded video page
  22. function navigateToEmbeddedPage(videoId) {
  23. const embeddedUrl = `https://www.youtube-nocookie.com/embed/${videoId}`;
  24. //window.location.href = embeddedUrl;
  25. window.open(embeddedUrl, '_blank');
  26. }
  27.  
  28. // Keyboard shortcut handler
  29. function handleKeyPress(event) {
  30. // Check if the key pressed is 'E' (can be customized)
  31. if (event.ctrlKey && event.key === 'e') {
  32. const videoId = getVideoId();
  33. if (videoId) {
  34. navigateToEmbeddedPage(videoId);
  35. }
  36. }
  37. }
  38.  
  39. // Event listener for key press
  40. document.addEventListener('keydown', handleKeyPress);
  41. })();