YouTube Shorts Redirect

Redirects /shorts/{videoId} -> /watch?v={videoId}

  1. // ==UserScript==
  2. // @name YouTube Shorts Redirect
  3. // @version 2.0
  4. // @description Redirects /shorts/{videoId} -> /watch?v={videoId}
  5. // @author aubymori
  6. // @match www.youtube.com/*
  7. // @namespace aubymori.github.io
  8. // @icon https://www.youtube.com/favicon.ico
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function(){
  14.  
  15. // Softload
  16.  
  17. function redirectShorts(e) {
  18. if (e.detail.pageData.page == 'shorts') {
  19. var videoId = e.detail.pageData.endpoint.reelWatchEndpoint.videoId;
  20. document.querySelector('ytd-navigation-manager').dispatchEvent(
  21. new CustomEvent('yt-navigate', {
  22. 'bubbles': true,
  23. 'detail': {
  24. 'endpoint': {
  25. 'commandMetadata': {
  26. 'webCommandMetadata': {
  27. 'pageType': 'WEB_PAGE_TYPE_WATCH',
  28. 'url': '/watch?v=' + videoId
  29. },
  30. },
  31. 'watchEndpoint': {
  32. 'videoId': videoId
  33. }
  34. }
  35. }
  36. })
  37. );
  38. // Player dies for some reason
  39. document.getElementById('movie_player').loadVideoById(videoId);
  40. }
  41. }
  42.  
  43. document.addEventListener('yt-page-data-fetched', redirectShorts);
  44.  
  45. // On initial load
  46.  
  47. if (window.location.pathname.search('/shorts/') > -1) {
  48. window.location.replace('https://www.youtube.com/watch?v=' + /[^/]*$/.exec(location.href));
  49. }
  50.  
  51. })();