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

BIN
images/.DS_Store vendored Normal file

Binary file not shown.

View File

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

View File

@ -83,6 +83,15 @@
</datalist>
</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>
<a class="button" id="save">Save</a>
</footer>

View File

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