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

1-hour MVP.

tags/v1.0
Gerben 7 years ago
parent
commit
f642b19038
3 changed files with 47 additions and 0 deletions
  1. +3
    -0
      Makefile
  2. +28
    -0
      background.js
  3. +16
    -0
      manifest.json

+ 3
- 0
Makefile View File

@@ -0,0 +1,3 @@
fx-build:
web-ext -a . build
rename -f "s/\.zip$$/.xpi/" youtubecinema-*.zip

+ 28
- 0
background.js View File

@@ -0,0 +1,28 @@
// Be compatible with Chrome|ium. We do not need the full webextension-polyfill.
if (typeof browser === 'undefined') {
this.browser = chrome
};

var urlPattern = /^(https?):\/\/(?:.+\.)youtube\.com\/watch\?.*v=([^&#]+)/;

function onBeforeRequestListener(details) {
var match = details.url.match(urlPattern);
var scheme = match[1];
var videoId = match[2];
if (scheme && videoId) {
// Watch the embedded version instead. And without related video suggestions!
var newUrl = scheme + '://www.youtube.com/embed/' + videoId + '?rel=0&autoplay=1';

// From the embed, one should be able to follow the "watch on YouTube" link
if (newUrl === details.originUrl)
return

return {redirectUrl: newUrl};
}
}

browser.webRequest.onBeforeRequest.addListener(
onBeforeRequestListener,
{urls: ["*://*.youtube.com/watch*"]},
['blocking']
);

+ 16
- 0
manifest.json View File

@@ -0,0 +1,16 @@
{
"name": "YoutubeCinema",
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"*://*.youtube.com/*",
"webRequest",
"webRequestBlocking"
],
"applications": {
"gecko": {"id": "youtubecinema@youtubecinema"}
},
"manifest_version": 2
}

Loading…
Cancel
Save