diff options
author | SimonBrazell <simon@brazell.com.au> | 2020-02-19 23:25:33 +1100 |
---|---|---|
committer | SimonBrazell <simon@brazell.com.au> | 2020-02-19 23:25:33 +1100 |
commit | 33bd56368317f653bb30fc40059495a0c07b05dc (patch) | |
tree | 943b14fe1f65e5d3c6e25ffb8de8a8e53a74bf52 /background.js | |
parent | Avoid redirecting `tweetdeck.twitter.com` & list instances (diff) | |
download | libredirect-33bd56368317f653bb30fc40059495a0c07b05dc.zip |
Redirect requests for 'YouTube Player API' assets to local files instead.
Diffstat (limited to 'background.js')
-rw-r--r-- | background.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/background.js b/background.js index 6e7eb3b5..adbdb400 100644 --- a/background.js +++ b/background.js @@ -1,7 +1,7 @@ 'use strict'; const invidiousDefault = 'https://invidio.us'; -const youtubeRegex = /((www|m)\.)?youtube(-nocookie)?\.com/; +const youtubeRegex = /((www|m)\.)?youtube|ytimg(-nocookie)?\.com/; const nitterDefault = 'https://nitter.net'; const twitterRegex = /((www|mobile)\.)?twitter\.com/; const bibliogramDefault = 'https://bibliogram.art'; @@ -59,6 +59,12 @@ function redirectYouTube(url) { if (url.host.split('.')[0] === 'studio') { // Avoid redirecting `studio.youtube.com` return null; + } else if (url.pathname.match(/iframe_api/)) { + // Redirect requests for YouTube Player API to local files instead + return chrome.runtime.getURL('assets/iframe_api.js'); + } else if (url.pathname.match(/www-widgetapi/)) { + // Redirect requests for YouTube Player API to local files instead + return chrome.runtime.getURL('assets/www-widgetapi.js'); } else { return `${invidiousInstance}${url.pathname}${url.search}`; } @@ -115,7 +121,11 @@ chrome.webRequest.onBeforeRequest.addListener( }, { urls: ["<all_urls>"], - types: ['main_frame', 'sub_frame',] + types: [ + "main_frame", + "sub_frame", + "script" + ] }, ['blocking'] ); |