From f642b190389c8b9d604373dbf5c545c6e274e8e0 Mon Sep 17 00:00:00 2001 From: Gerben Date: Mon, 20 Mar 2017 23:36:48 +0100 Subject: [PATCH] 1-hour MVP. --- Makefile | 3 +++ background.js | 28 ++++++++++++++++++++++++++++ manifest.json | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 Makefile create mode 100644 background.js create mode 100644 manifest.json 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 +}