YouTube no shorts player

Redirects YouTube shorts videos to proper YouTube player.

  1. // ==UserScript==
  2. // @name YouTube no shorts player
  3. // @description Redirects YouTube shorts videos to proper YouTube player.
  4. // @author Can Kurt
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.1
  7. // @match *://www.youtube.com/*
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11.  
  12. function matchShorts(url) {
  13. const pattern = /^(.*)\/shorts\/([^/?#]+)([/?#].*)?$/;
  14. return url.match(pattern);
  15. }
  16.  
  17. function overrideUrl(url) {
  18. const match = matchShorts(url)
  19. if (match) {
  20. const base = match[1];
  21. const id = match[2];
  22. const tail = match[3] || '';
  23. return `${base}/watch?v=${id}${tail}`;
  24. }
  25. return url;
  26. }
  27.  
  28. let isRedirecting = false;
  29.  
  30. setInterval(() => {
  31. if(!isRedirecting && matchShorts(window.location.pathname)) {
  32. const newUrl = overrideUrl(window.location.pathname);
  33. isRedirecting = true;
  34. window.location = newUrl;
  35. }
  36. }, 300);