mirror of
https://github.com/SimonBrazell/privacy-redirect
synced 2025-01-10 15:56:18 +01:00
parent
3f01569099
commit
b21610202f
@ -20,6 +20,10 @@ function redirectTwitter(url) {
|
|||||||
browser.storage.sync.get(
|
browser.storage.sync.get(
|
||||||
['nitterInstance', 'disableNitter', 'removeTwitterSW', 'redirectBypassFlag'],
|
['nitterInstance', 'disableNitter', 'removeTwitterSW', 'redirectBypassFlag'],
|
||||||
(result) => {
|
(result) => {
|
||||||
|
const redirectBypassFlag = result.redirectBypassFlag;
|
||||||
|
browser.storage.sync.set({
|
||||||
|
redirectBypassFlag: false
|
||||||
|
});
|
||||||
if (!result.removeTwitterSW) {
|
if (!result.removeTwitterSW) {
|
||||||
disableNitter = result.disableNitter;
|
disableNitter = result.disableNitter;
|
||||||
nitterInstance = result.nitterInstance || nitterDefault;
|
nitterInstance = result.nitterInstance || nitterDefault;
|
||||||
@ -32,11 +36,7 @@ browser.storage.sync.get(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const url = new URL(window.location);
|
const url = new URL(window.location);
|
||||||
const redirectBypassFlag = result.redirectBypassFlag;
|
if (!redirectBypassFlag && !disableNitter && url.host !== nitterInstance && !url.pathname.includes('/home')) {
|
||||||
browser.storage.sync.set({
|
|
||||||
redirectBypassFlag: false
|
|
||||||
});
|
|
||||||
if (!redirectBypassFlag && !disableNitter && url.host !== nitterInstance) {
|
|
||||||
const redirect = redirectTwitter(url);
|
const redirect = redirectTwitter(url);
|
||||||
console.info(
|
console.info(
|
||||||
'Redirecting', `"${url.href}"`, '=>', `"${redirect}"`
|
'Redirecting', `"${url.href}"`, '=>', `"${redirect}"`
|
||||||
|
@ -10,6 +10,7 @@ const youtubeDomains = [
|
|||||||
'www.youtube-nocookie.com',
|
'www.youtube-nocookie.com',
|
||||||
'youtu.be',
|
'youtu.be',
|
||||||
's.ytimg.com',
|
's.ytimg.com',
|
||||||
|
'music.youtube.com'
|
||||||
];
|
];
|
||||||
const nitterDefault = 'https://nitter.net';
|
const nitterDefault = 'https://nitter.net';
|
||||||
const twitterDomains = [
|
const twitterDomains = [
|
||||||
@ -85,6 +86,7 @@ let onlyEmbeddedVideo;
|
|||||||
let videoQuality;
|
let videoQuality;
|
||||||
let invidiousDarkMode;
|
let invidiousDarkMode;
|
||||||
let whitelist;
|
let whitelist;
|
||||||
|
let redirectBypassFlag;
|
||||||
|
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
@ -161,6 +163,9 @@ browser.storage.onChanged.addListener(changes => {
|
|||||||
if ('whitelist' in changes) {
|
if ('whitelist' in changes) {
|
||||||
whitelist = changes.whitelist.newValue.map(e => new RegExp(e));
|
whitelist = changes.whitelist.newValue.map(e => new RegExp(e));
|
||||||
}
|
}
|
||||||
|
if ('redirectBypassFlag' in changes) {
|
||||||
|
redirectBypassFlag = changes.redirectBypassFlag.newValue;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function addressToLatLng(address, callback) {
|
function addressToLatLng(address, callback) {
|
||||||
@ -193,6 +198,10 @@ function isWhitelisted(initiator) {
|
|||||||
return initiator && whitelist.some(regex => (regex.test(initiator.href)));
|
return initiator && whitelist.some(regex => (regex.test(initiator.href)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isFirefox() {
|
||||||
|
return typeof InstallTrigger !== 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
function redirectYouTube(url, initiator, type) {
|
function redirectYouTube(url, initiator, type) {
|
||||||
if (disableInvidious || isWhitelisted(initiator)) {
|
if (disableInvidious || isWhitelisted(initiator)) {
|
||||||
return null;
|
return null;
|
||||||
@ -208,16 +217,16 @@ function redirectYouTube(url, initiator, type) {
|
|||||||
// Avoid redirecting `studio.youtube.com`
|
// Avoid redirecting `studio.youtube.com`
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Proxy video through the server if enabled by user
|
if (onlyEmbeddedVideo && type !== 'sub_frame') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Apply settings
|
||||||
if (alwaysProxy) {
|
if (alwaysProxy) {
|
||||||
url.searchParams.append('local', true);
|
url.searchParams.append('local', true);
|
||||||
}
|
}
|
||||||
if (videoQuality) {
|
if (videoQuality) {
|
||||||
url.searchParams.append('quality', videoQuality);
|
url.searchParams.append('quality', videoQuality);
|
||||||
}
|
}
|
||||||
if (onlyEmbeddedVideo && type !== 'sub_frame') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (invidiousDarkMode) {
|
if (invidiousDarkMode) {
|
||||||
url.searchParams.append('dark_mode', invidiousDarkMode);
|
url.searchParams.append('dark_mode', invidiousDarkMode);
|
||||||
}
|
}
|
||||||
@ -228,7 +237,10 @@ function redirectTwitter(url, initiator) {
|
|||||||
if (disableNitter || isWhitelisted(initiator)) {
|
if (disableNitter || isWhitelisted(initiator)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (initiator && (initiator.origin === nitterInstance || twitterDomains.includes(initiator.host))) {
|
if (url.pathname.includes('/home')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isFirefox() && initiator && (initiator.origin === nitterInstance || twitterDomains.includes(initiator.host))) {
|
||||||
browser.storage.sync.set({
|
browser.storage.sync.set({
|
||||||
redirectBypassFlag: true
|
redirectBypassFlag: true
|
||||||
});
|
});
|
||||||
|
@ -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.32",
|
"version": "1.1.33",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"scripts": [
|
||||||
|
Loading…
Reference in New Issue
Block a user