diff options
author | SimonBrazell <simon@brazell.com.au> | 2020-02-09 11:08:04 +1100 |
---|---|---|
committer | SimonBrazell <simon@brazell.com.au> | 2020-02-09 11:08:04 +1100 |
commit | eb99449f726565764dac26ee1baa4e9e4689f078 (patch) | |
tree | 121ccb543ea3bd64999b5735198351eca3e60923 /background.js | |
parent | Fix missing query strings in redirects (diff) | |
download | libredirect-eb99449f726565764dac26ee1baa4e9e4689f078.zip |
Avoid redirecting `studio.youtube.com` & basic instance validation
Diffstat (limited to 'background.js')
-rw-r--r-- | background.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/background.js b/background.js index bf068416..5790eb5a 100644 --- a/background.js +++ b/background.js @@ -55,9 +55,22 @@ chrome.storage.onChanged.addListener(changes => { } }); -function redirectBibliogram(url) { +function redirectYouTube(url) { + if (url.host.split('.')[0] === 'studio') { + // Avoid redirecting `studio.youtube.com` + return null; + } else { + return `${invidiousInstance}${url.pathname}${url.search}`; + } +} + +function redirectTwitter(url) { + return `${nitterInstance}${url.pathname}${url.search}` +} + +function redirectInstagram(url) { if (url.pathname === '/' || url.pathname.match(instagramPathsRegex)) { - return bibliogramInstance + url.pathname + url.search; + return `${bibliogramInstance}${url.pathname}${url.search}`; } else { // Redirect user profile requests to '/u/...' return `${bibliogramInstance}/u${url.pathname}${url.search}`; @@ -71,23 +84,23 @@ chrome.webRequest.onBeforeRequest.addListener( if (url.host.match(youtubeRegex)) { if (!disableInvidious) { redirect = { - redirectUrl: invidiousInstance + url.pathname + url.search + redirectUrl: redirectYouTube(url) }; } } else if (url.host.match(twitterRegex)) { if (!disableNitter) { redirect = { - redirectUrl: nitterInstance + url.pathname + url.search + redirectUrl: redirectTwitter(url) }; } } else if (url.host.match(instagramRegex)) { if (!disableBibliogram) { redirect = { - redirectUrl: redirectBibliogram(url) + redirectUrl: redirectInstagram(url) }; } } - if (redirect) { + if (redirect && redirect.redirectUrl) { console.log( 'Redirecting', `"${url.toString()}"`, '=>', `"${redirect.redirectUrl}"` ); |