Redirect YouTube to Grayjay

Redirect video clicks from m.youtube.com to Grayjay

当前为 2024-12-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Redirect YouTube to Grayjay
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @author Reed Hiland (https://hiland.dev/)
  6. // @description Redirect video clicks from m.youtube.com to Grayjay
  7. // @match https://m.youtube.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. document.addEventListener('click', function(e) {
  16. let target = e.target;
  17. while (target && target.tagName !== 'A') {
  18. target = target.parentNode;
  19. }
  20.  
  21. if (target && target.href && target.href.includes('watch')) {
  22. e.preventDefault();
  23. e.stopPropagation();
  24.  
  25. let fullURL = target.href.replace('m.youtube.com', 'www.youtube.com');
  26. const grayjayURL = "grayjay://video/" + fullURL;
  27. // Navigate to app URL
  28. window.location.href = grayjayURL;
  29.  
  30. // Try returning false as well
  31. return false;
  32. }
  33. }, true);
  34. })();