diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..13a8dbe --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +fx-build: + web-ext -a . build + rename -f "s/\.zip$$/.xpi/" youtubecinema-*.zip diff --git a/background.js b/background.js new file mode 100644 index 0000000..948510c --- /dev/null +++ b/background.js @@ -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'] +); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..fe0a5eb --- /dev/null +++ b/manifest.json @@ -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 +}