Browser extension to watch YouTube videos without the distracting cruft around it, in the full window.

youtubecinema/ background.js
29 lines
867 B

  1. // Be compatible with Chrome|ium. We do not need the full webextension-polyfill.
  2. if (typeof browser === 'undefined') {
  3. this.browser = chrome
  4. };
  5. var urlPattern = /^(https?):\/\/(?:.+\.)youtube\.com\/watch\?.*v=([^&#]+)/;
  6. function onBeforeRequestListener(details) {
  7. var match = details.url.match(urlPattern);
  8. var scheme = match[1];
  9. var videoId = match[2];
  10. if (scheme && videoId) {
  11. // Watch the embedded version instead. And without related video suggestions!
  12. var newUrl = scheme + '://www.youtube.com/embed/' + videoId + '?rel=0&autoplay=1';
  13. // From the embed, one should be able to follow the "watch on YouTube" link
  14. if (newUrl === details.originUrl)
  15. return
  16. return {redirectUrl: newUrl};
  17. }
  18. }
  19. browser.webRequest.onBeforeRequest.addListener(
  20. onBeforeRequestListener,
  21. {urls: ["*://*.youtube.com/watch*"]},
  22. ['blocking']
  23. );