Add 'Always proxy video' as a settings & avoid youtube-dl.org redirects

This commit is contained in:
SimonBrazell 2020-03-10 16:03:28 +11:00
parent 850d25f3ec
commit 75e4b6a69c
5 changed files with 30 additions and 10 deletions

View File

@ -25,14 +25,15 @@ const layers = {
'bicycling': 'C' 'bicycling': 'C'
} }
let nitterInstance;
let invidiousInstance;
let bibliogramInstance;
let osmInstance;
let disableNitter; let disableNitter;
let disableInvidious; let disableInvidious;
let disableBibliogram; let disableBibliogram;
let disableOsm; let disableOsm;
let nitterInstance;
let invidiousInstance;
let bibliogramInstance;
let osmInstance;
let alwaysProxy;
window.browser = window.browser || window.chrome; window.browser = window.browser || window.chrome;
@ -56,6 +57,7 @@ browser.storage.sync.get(
invidiousInstance = result.invidiousInstance || invidiousDefault; invidiousInstance = result.invidiousInstance || invidiousDefault;
bibliogramInstance = result.bibliogramInstance || bibliogramDefault; bibliogramInstance = result.bibliogramInstance || bibliogramDefault;
osmInstance = result.osmInstance || osmDefault; osmInstance = result.osmInstance || osmDefault;
alwaysProxy = result.alwaysProxy;
} }
); );
@ -84,6 +86,9 @@ browser.storage.onChanged.addListener(changes => {
if ('disableOsm' in changes) { if ('disableOsm' in changes) {
disableOsm = changes.disableOsm.newValue; disableOsm = changes.disableOsm.newValue;
} }
if ('alwaysProxy' in changes) {
alwaysProxy = changes.alwaysProxy.newValue;
}
}); });
function addressToLatLng(address, callback) { function addressToLatLng(address, callback) {
@ -123,8 +128,10 @@ function redirectYouTube(url) {
// Redirect requests for YouTube Player API to local files instead // Redirect requests for YouTube Player API to local files instead
return browser.runtime.getURL('assets/www-widgetapi.js'); return browser.runtime.getURL('assets/www-widgetapi.js');
} else { } else {
// Proxy video through the server // Proxy video through the server if enabled by user
if (alwaysProxy) {
url.searchParams.append('local', true); url.searchParams.append('local', true);
}
return `${invidiousInstance}${url.pathname}${url.search}`; return `${invidiousInstance}${url.pathname}${url.search}`;
} }
} }
@ -217,7 +224,7 @@ browser.webRequest.onBeforeRequest.addListener(
details => { details => {
const url = new URL(details.url); const url = new URL(details.url);
let redirect; let redirect;
if (url.host.match(youtubeRegex)) { if (url.host.match(youtubeRegex) && !url.host.includes('youtube-dl.org')) {
if (!disableInvidious) { if (!disableInvidious) {
redirect = { redirect = {
redirectUrl: redirectYouTube(url) redirectUrl: redirectYouTube(url)

BIN
images/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
{ {
"name": "Privacy Redirect", "name": "Privacy Redirect",
"description": "Redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.", "description": "Redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.",
"version": "1.1.14", "version": "1.1.15",
"manifest_version": 2, "manifest_version": 2,
"background": { "background": {
"scripts": [ "scripts": [

View File

@ -83,6 +83,15 @@
</datalist> </datalist>
</section> </section>
<section class="options settings_block">
<div class="onoffswitch switch" aria-label="Always proxy videos through Invidious">
<h1>Always proxy videos through Invidious?</h1>
<input aria-hidden="true" id="always-proxy" type="checkbox" checked>&nbsp;
<label for="always-proxy" class="checkbox-label">
</label>
</div>
</section>
<footer> <footer>
<a class="button" id="save">Save</a> <a class="button" id="save">Save</a>
</footer> </footer>

View File

@ -8,6 +8,7 @@ let disableNitter = document.querySelector('#disable-nitter');
let disableInvidious = document.querySelector('#disable-invidious'); let disableInvidious = document.querySelector('#disable-invidious');
let disableBibliogram = document.querySelector('#disable-bibliogram'); let disableBibliogram = document.querySelector('#disable-bibliogram');
let disableOsm = document.querySelector('#disable-osm'); let disableOsm = document.querySelector('#disable-osm');
let alwaysProxy = document.querySelector('#always-proxy');
window.browser = window.browser || window.chrome; window.browser = window.browser || window.chrome;
@ -20,7 +21,8 @@ browser.storage.sync.get(
'disableNitter', 'disableNitter',
'disableInvidious', 'disableInvidious',
'disableBibliogram', 'disableBibliogram',
'disableOsm' 'disableOsm',
'alwaysProxy'
], ],
result => { result => {
nitterInstance.value = result.nitterInstance || ''; nitterInstance.value = result.nitterInstance || '';
@ -31,6 +33,7 @@ browser.storage.sync.get(
disableInvidious.checked = !result.disableInvidious; disableInvidious.checked = !result.disableInvidious;
disableBibliogram.checked = !result.disableBibliogram; disableBibliogram.checked = !result.disableBibliogram;
disableOsm.checked = !result.disableOsm; disableOsm.checked = !result.disableOsm;
alwaysProxy.checked = result.alwaysProxy;
} }
); );
@ -43,7 +46,8 @@ document.querySelector('#save').addEventListener('click', () => {
disableNitter: !disableNitter.checked, disableNitter: !disableNitter.checked,
disableInvidious: !disableInvidious.checked, disableInvidious: !disableInvidious.checked,
disableBibliogram: !disableBibliogram.checked, disableBibliogram: !disableBibliogram.checked,
disableOsm: !disableOsm.checked disableOsm: !disableOsm.checked,
alwaysProxy: alwaysProxy.checked
}); });
window.close(); window.close();
}); });