parent
8533cb025a
commit
bfc9081a51
@ -20,8 +20,18 @@ const twitterDomains = [
|
|||||||
'video.twimg.com',
|
'video.twimg.com',
|
||||||
];
|
];
|
||||||
const bibliogramDefault = 'https://bibliogram.art';
|
const bibliogramDefault = 'https://bibliogram.art';
|
||||||
const instagramRegex = /((www|about|help)\.)?instagram\.com/;
|
const instagramDomains = [
|
||||||
const instagramPathsRegex = /\/(a|admin|api|favicon.ico|static|imageproxy|p|u|developer|about|legal|explore|director)/;
|
"instagram.com",
|
||||||
|
"www.instagram.com",
|
||||||
|
"help.instagram.com",
|
||||||
|
"about.instagram.com",
|
||||||
|
];
|
||||||
|
const instagramReservedPaths = /\/(p|favicon.ico|developer|legal|about|explore|support|press|api|privacy|safety|admin|help|terms|contact|blog|igtv)/;
|
||||||
|
const bibliogramBypassPaths = /\/(accounts\/|embeds?.js)/;
|
||||||
|
const bibliogramInstances = [
|
||||||
|
'https://bibliogram.art',
|
||||||
|
'https://bibliogram.snopyta.org'
|
||||||
|
];
|
||||||
const osmDefault = 'https://openstreetmap.org';
|
const osmDefault = 'https://openstreetmap.org';
|
||||||
const googleMapsRegex = /https?:\/\/(((www|maps)\.)?(google).*(\/maps)|maps\.(google).*)/;
|
const googleMapsRegex = /https?:\/\/(((www|maps)\.)?(google).*(\/maps)|maps\.(google).*)/;
|
||||||
const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
|
const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
|
||||||
@ -186,14 +196,19 @@ function redirectTwitter(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirectInstagram(url, initiator) {
|
function redirectInstagram(url, initiator, type) {
|
||||||
if (disableBibliogram) {
|
if (disableBibliogram) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (initiator && (initiator.origin === bibliogramInstance || initiator.host.match(instagramRegex))) {
|
// Do not redirect Bibliogram view on Instagram links
|
||||||
|
if (initiator && (initiator.origin === bibliogramInstance || instagramDomains.includes(initiator.host))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (url.pathname === '/' || url.pathname.match(instagramPathsRegex)) {
|
// Do not redirect /accounts, /embeds.js, or anything other than main_frame
|
||||||
|
if (url.pathname.match(bibliogramBypassPaths) || type !== 'main_frame') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (url.pathname === '/' || url.pathname.match(instagramReservedPaths)) {
|
||||||
return `${bibliogramInstance}${url.pathname}${url.search}`;
|
return `${bibliogramInstance}${url.pathname}${url.search}`;
|
||||||
} else {
|
} else {
|
||||||
// Redirect user profile requests to '/u/...'
|
// Redirect user profile requests to '/u/...'
|
||||||
@ -300,9 +315,9 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||||||
redirect = {
|
redirect = {
|
||||||
redirectUrl: redirectTwitter(url)
|
redirectUrl: redirectTwitter(url)
|
||||||
};
|
};
|
||||||
} else if (url.host.match(instagramRegex)) {
|
} else if (instagramDomains.includes(url.host)) {
|
||||||
redirect = {
|
redirect = {
|
||||||
redirectUrl: redirectInstagram(url, initiator)
|
redirectUrl: redirectInstagram(url, initiator, details.type)
|
||||||
};
|
};
|
||||||
} else if (url.href.match(googleMapsRegex)) {
|
} else if (url.href.match(googleMapsRegex)) {
|
||||||
redirect = {
|
redirect = {
|
||||||
@ -322,3 +337,13 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||||||
},
|
},
|
||||||
['blocking']
|
['blocking']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
browser.runtime.onInstalled.addListener(
|
||||||
|
details => {
|
||||||
|
if (details.reason === 'install') {
|
||||||
|
browser.storage.sync.set({
|
||||||
|
bibliogramInstance: bibliogramInstances[~~(bibliogramInstances.length * Math.random())]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -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.20",
|
"version": "1.1.21",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"scripts": [
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
<datalist id="bibliogram-instance-list">
|
<datalist id="bibliogram-instance-list">
|
||||||
<option value="https://bibliogram.art">
|
<option value="https://bibliogram.art">
|
||||||
<option value="https://bibliogram.snopyta.org">
|
<option value="https://bibliogram.snopyta.org">
|
||||||
<option value="https://bibliogram.dsrev.ru">
|
<option value="https://bibliogram.pussthecat.org">
|
||||||
</datalist>
|
</datalist>
|
||||||
<h1>OpenStreetMap Instance</h1>
|
<h1>OpenStreetMap Instance</h1>
|
||||||
<input id="osm-instance" list="osm-instance-list" type="url" placeholder="https://openstreetmap.org">
|
<input id="osm-instance" list="osm-instance-list" type="url" placeholder="https://openstreetmap.org">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user