mirror of
https://codeberg.org/LibRedirect/libredirect.git
synced 2025-01-31 19:44:54 +01:00
Added support for chromium. Fixed redirect off offline #276
This commit is contained in:
parent
3b64689020
commit
29729a01cf
@ -2,46 +2,49 @@
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
function isException(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
'exceptions',
|
||||
r => {
|
||||
for (const item of r.exceptions.url)
|
||||
if (item == `${url.protocol}//${url.host}`) { resolve(true); return; }
|
||||
for (const item of r.exceptions.regex)
|
||||
if (new RegExp(item).test(url.href)) { resolve(true); return; }
|
||||
resolve(false); return;
|
||||
}
|
||||
)
|
||||
})
|
||||
for (const item of exceptions.url)
|
||||
if (item == `${url.protocol}//${url.host}`) return true;
|
||||
for (const item of exceptions.regex)
|
||||
if (new RegExp(item).test(url.href)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function initDefaults() {
|
||||
return new Promise(async resolve => {
|
||||
await browser.storage.local.set({
|
||||
exceptions: {
|
||||
"url": [],
|
||||
"regex": [],
|
||||
},
|
||||
theme: "DEFAULT",
|
||||
popupFrontends: [
|
||||
"youtube",
|
||||
"twitter",
|
||||
"instagram",
|
||||
"tikTok",
|
||||
"imgur",
|
||||
"reddit",
|
||||
"search",
|
||||
"medium",
|
||||
"translate",
|
||||
"maps",
|
||||
],
|
||||
autoRedirect: false,
|
||||
})
|
||||
resolve();
|
||||
})
|
||||
let exceptions;
|
||||
|
||||
function init() {
|
||||
browser.storage.local.get(
|
||||
'exceptions',
|
||||
r => {
|
||||
exceptions = r.exceptions;
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
async function initDefaults() {
|
||||
await browser.storage.local.set({
|
||||
exceptions: {
|
||||
"url": [],
|
||||
"regex": [],
|
||||
},
|
||||
theme: "DEFAULT",
|
||||
popupFrontends: [
|
||||
"youtube",
|
||||
"twitter",
|
||||
"instagram",
|
||||
"tikTok",
|
||||
"imgur",
|
||||
"reddit",
|
||||
"search",
|
||||
"medium",
|
||||
"translate",
|
||||
"maps",
|
||||
],
|
||||
autoRedirect: false,
|
||||
})
|
||||
}
|
||||
|
||||
const allPopupFrontends = [
|
||||
"youtube",
|
||||
@ -61,7 +64,6 @@ const allPopupFrontends = [
|
||||
"sendTargets"
|
||||
];
|
||||
|
||||
|
||||
export default {
|
||||
isException,
|
||||
initDefaults,
|
||||
|
@ -11,50 +11,57 @@ let redirects = {
|
||||
"i2p": []
|
||||
}
|
||||
}
|
||||
function setRedirects(val) {
|
||||
redirects.rimgo = val;
|
||||
browser.storage.local.set({ imgurRedirects: redirects })
|
||||
console.log("imgurRedirects: ", val)
|
||||
for (const item of rimgoNormalRedirectsChecks)
|
||||
if (!redirects.rimgo.normal.includes(item)) {
|
||||
var index = rimgoNormalRedirectsChecks.indexOf(item);
|
||||
if (index !== -1) rimgoNormalRedirectsChecks.splice(index, 1);
|
||||
}
|
||||
browser.storage.local.set({ rimgoNormalRedirectsChecks });
|
||||
function setRedirects() {
|
||||
return new Promise(resolve => {
|
||||
fetch('/instances/data.json').then(response => response.text()).then(async data => {
|
||||
let dataJson = JSON.parse(data);
|
||||
redirects.rimgo = dataJson.rimgo;
|
||||
|
||||
for (const item of rimgoTorRedirectsChecks)
|
||||
if (!redirects.rimgo.tor.includes(item)) {
|
||||
var index = rimgoTorRedirectsChecks.indexOf(item);
|
||||
if (index !== -1) rimgoTorRedirectsChecks.splice(index, 1);
|
||||
}
|
||||
browser.storage.local.set({ rimgoTorRedirectsChecks });
|
||||
rimgoNormalRedirectsChecks = [...redirects.rimgo.normal];
|
||||
rimgoTorRedirectsChecks = [...redirects.rimgo.tor];
|
||||
rimgoI2pRedirectsChecks = [...redirects.rimgo.i2p];
|
||||
|
||||
for (const item of rimgoI2pRedirectsChecks)
|
||||
if (!redirects.rimgo.i2p.includes(item)) {
|
||||
var index = rimgoI2pRedirectsChecks.indexOf(item);
|
||||
if (index !== -1) rimgoI2pRedirectsChecks.splice(index, 1);
|
||||
}
|
||||
browser.storage.local.set({ rimgoI2pRedirectsChecks });
|
||||
for (const instance of r.cloudflareList) {
|
||||
const a = rimgoNormalRedirectsChecks.indexOf(instance);
|
||||
if (a > -1) rimgoNormalRedirectsChecks.splice(a, 1);
|
||||
|
||||
const b = rimgoTorRedirectsChecks.indexOf(instance);
|
||||
if (b > -1) rimgoTorRedirectsChecks.splice(b, 1);
|
||||
|
||||
const c = rimgoI2pRedirectsChecks.indexOf(instance);
|
||||
if (c > -1) rimgoI2pRedirectsChecks.splice(c, 1);
|
||||
}
|
||||
|
||||
await browser.storage.local.set({
|
||||
imgurRedirects: redirects,
|
||||
rimgoNormalRedirectsChecks,
|
||||
rimgoTorRedirectsChecks,
|
||||
rimgoI2pRedirectsChecks,
|
||||
});
|
||||
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
let
|
||||
disable,
|
||||
protocol;
|
||||
|
||||
let
|
||||
disableImgur,
|
||||
imgurRedirects,
|
||||
imgurProtocol,
|
||||
rimgoNormalRedirectsChecks,
|
||||
rimgoNormalCustomRedirects,
|
||||
rimgoTorRedirectsChecks,
|
||||
rimgoI2pRedirectsChecks;
|
||||
rimgoTorCustomRedirects,
|
||||
rimgoI2pRedirectsChecks,
|
||||
rimgoI2pCustomRedirects;
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
return new Promise(resolve => {
|
||||
function init() {
|
||||
return new Promise(async resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableImgur",
|
||||
"imgurRedirects",
|
||||
"imgurProtocol",
|
||||
|
||||
"rimgoNormalRedirectsChecks",
|
||||
"rimgoNormalCustomRedirects",
|
||||
"rimgoTorRedirectsChecks",
|
||||
@ -63,107 +70,84 @@ function redirect(url, type, initiator) {
|
||||
"rimgoI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableImgur) { resolve(); return; }
|
||||
if (url.pathname == "/") { resolve(); return; }
|
||||
if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media",].includes(type)) { resolve(); return; }
|
||||
if (
|
||||
initiator &&
|
||||
(
|
||||
[
|
||||
...r.imgurRedirects.rimgo.normal,
|
||||
...r.rimgoNormalCustomRedirects,
|
||||
...r.rimgoTorCustomRedirects,
|
||||
...r.rimgoI2pCustomRedirects,
|
||||
].includes(initiator.origin) || targets.test(initiator.host))
|
||||
) { resolve(); return; }
|
||||
if (!targets.test(url.href)) { resolve(); return; }
|
||||
if (url.pathname.includes("delete/")) { resolve(); return; }
|
||||
// https://imgur.com/gallery/s4WXQmn
|
||||
// https://imgur.com/a/H8M4rcp
|
||||
// https://imgur.com/gallery/gYiQLWy
|
||||
// https://imgur.com/gallery/cTRwaJU
|
||||
// https://i.imgur.com/CFSQArP.jpeg
|
||||
let instancesList;
|
||||
if (r.imgurProtocol == 'normal') instancesList = [...r.rimgoNormalRedirectsChecks, ...r.rimgoNormalCustomRedirects];
|
||||
if (r.imgurProtocol == 'tor') instancesList = [...r.rimgoTorRedirectsChecks, ...r.rimgoTorCustomRedirects];
|
||||
if (r.imgurProtocol == 'i2p') instancesList = [...r.rimgoI2pRedirectsChecks, ...r.rimgoI2pCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
disableImgur = r.disableImgur;
|
||||
imgurRedirects = r.imgurRedirects;
|
||||
imgurProtocol = r.imgurProtocol;
|
||||
rimgoNormalRedirectsChecks = r.rimgoNormalRedirectsChecks;
|
||||
rimgoNormalCustomRedirects = r.rimgoNormalCustomRedirects;
|
||||
rimgoTorRedirectsChecks = r.rimgoTorRedirectsChecks;
|
||||
rimgoTorCustomRedirects = r.rimgoTorCustomRedirects;
|
||||
rimgoI2pRedirectsChecks = r.rimgoI2pRedirectsChecks;
|
||||
rimgoI2pCustomRedirects = r.rimgoI2pCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function reverse(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"imgurRedirects",
|
||||
"rimgoNormalCustomRedirects",
|
||||
"rimgoTorCustomRedirects",
|
||||
"rimgoI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.imgurRedirects.rimgo.normal,
|
||||
...r.imgurRedirects.rimgo.tor,
|
||||
...r.imgurRedirects.rimgo.i2p,
|
||||
...r.rimgoNormalCustomRedirects,
|
||||
...r.rimgoTorCustomRedirects,
|
||||
...r.rimgoI2pCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
resolve(`https://imgur.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
// https://imgur.com/gallery/s4WXQmn
|
||||
// https://imgur.com/a/H8M4rcp
|
||||
// https://imgur.com/gallery/gYiQLWy
|
||||
// https://imgur.com/gallery/cTRwaJU
|
||||
// https://i.imgur.com/CFSQArP.jpeg
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...imgurRedirects.rimgo.normal,
|
||||
...imgurRedirects.rimgo.tor,
|
||||
...imgurRedirects.rimgo.i2p,
|
||||
...rimgoNormalCustomRedirects,
|
||||
...rimgoTorCustomRedirects,
|
||||
...rimgoI2pCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
if (disableImgur) return;
|
||||
if (url.pathname == "/") return;
|
||||
if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media",].includes(type)) return;
|
||||
if (initiator && (all().includes(initiator.origin) || targets.test(initiator.host))) return;
|
||||
if (!targets.test(url.href)) return;
|
||||
if (url.pathname.includes("delete/")) return;
|
||||
|
||||
let instancesList;
|
||||
if (imgurProtocol == 'normal') instancesList = [...rimgoNormalRedirectsChecks, ...rimgoNormalCustomRedirects];
|
||||
if (imgurProtocol == 'tor') instancesList = [...rimgoTorRedirectsChecks, ...rimgoTorCustomRedirects];
|
||||
if (imgurProtocol == 'i2p') instancesList = [...rimgoI2pRedirectsChecks, ...rimgoI2pCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function reverse(url) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
resolve(`https://imgur.com${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"imgurRedirects",
|
||||
"imgurProtocol",
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
let instancesList;
|
||||
if (imgurProtocol == 'normal') instancesList = [...rimgoNormalCustomRedirects, ...rimgoNormalRedirectsChecks];
|
||||
else if (imgurProtocol == 'tor') instancesList = [...rimgoTorCustomRedirects, ...rimgoTorRedirectsChecks];
|
||||
else if (imgurProtocol == 'i2p') instancesList = [...rimgoI2pCustomRedirects, ...rimgoI2pRedirectsChecks];
|
||||
|
||||
"rimgoNormalRedirectsChecks",
|
||||
"rimgoNormalCustomRedirects",
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
"rimgoTorRedirectsChecks",
|
||||
"rimgoTorCustomRedirects",
|
||||
|
||||
"rimgoI2pRedirectsChecks",
|
||||
"rimgoI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.imgurRedirects.rimgo.normal,
|
||||
...r.imgurRedirects.rimgo.tor,
|
||||
...r.imgurRedirects.rimgo.i2p,
|
||||
|
||||
...r.rimgoNormalCustomRedirects,
|
||||
...r.rimgoTorCustomRedirects,
|
||||
...r.rimgoI2pCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
let instancesList;
|
||||
if (r.imgurProtocol == 'normal') instancesList = [...r.rimgoNormalCustomRedirects, ...r.rimgoNormalRedirectsChecks];
|
||||
else if (r.imgurProtocol == 'tor') instancesList = [...r.rimgoTorCustomRedirects, ...r.rimgoTorRedirectsChecks];
|
||||
else if (r.imgurProtocol == 'i2p') instancesList = [...r.rimgoI2pCustomRedirects, ...r.rimgoI2pRedirectsChecks];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) resolve();
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
@ -175,7 +159,7 @@ function initDefaults() {
|
||||
browser.storage.local.get('cloudflareList', async r => {
|
||||
rimgoNormalRedirectsChecks = [...redirects.rimgo.normal];
|
||||
for (const instance of r.cloudflareList) {
|
||||
let i = rimgoNormalRedirectsChecks.indexOf(instance);
|
||||
const i = rimgoNormalRedirectsChecks.indexOf(instance);
|
||||
if (i > -1) rimgoNormalRedirectsChecks.splice(i, 1);
|
||||
}
|
||||
await browser.storage.local.set({
|
||||
@ -200,7 +184,6 @@ function initDefaults() {
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
reverse,
|
||||
initDefaults,
|
||||
|
@ -26,126 +26,105 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
let bibliogramNormalRedirectsChecks;
|
||||
let
|
||||
disableInstagram,
|
||||
instagramProtocol,
|
||||
instagramRedirects,
|
||||
bibliogramNormalRedirectsChecks,
|
||||
bibliogramTorRedirectsChecks,
|
||||
bibliogramNormalCustomRedirects,
|
||||
bibliogramTorCustomRedirects;
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
return new Promise(resolve => {
|
||||
function init() {
|
||||
return new Promise(async resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableInstagram",
|
||||
"instagramProtocol",
|
||||
|
||||
"instagramRedirects",
|
||||
|
||||
"bibliogramNormalRedirectsChecks",
|
||||
"bibliogramTorRedirectsChecks",
|
||||
|
||||
"bibliogramNormalCustomRedirects",
|
||||
"bibliogramTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableInstagram) { resolve(); return; }
|
||||
if (
|
||||
initiator &&
|
||||
([
|
||||
...r.instagramRedirects.bibliogram.normal,
|
||||
...r.instagramRedirects.bibliogram.tor,
|
||||
...r.bibliogramNormalCustomRedirects,
|
||||
...r.bibliogramTorCustomRedirects,
|
||||
].includes(initiator.origin))
|
||||
) { resolve('BYPASSTAB'); return; }
|
||||
|
||||
if (!targets.includes(url.host)) { resolve(); return; }
|
||||
if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media"].includes(type)) { resolve(); return; }
|
||||
|
||||
const bypassPaths = [/about/, /explore/, /support/, /press/, /api/, /privacy/, /safety/, /admin/, /\/(accounts\/|embeds?.js)/];
|
||||
if (bypassPaths.some(rx => rx.test(url.pathname))) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.instagramProtocol == 'normal') instancesList = [...r.bibliogramNormalRedirectsChecks, ...r.bibliogramNormalCustomRedirects];
|
||||
else if (r.instagramProtocol == 'tor') instancesList = [...r.bibliogramTorRedirectsChecks, ...r.bibliogramTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
|
||||
const reservedPaths = ["u", "p", "privacy",];
|
||||
if (url.pathname === "/" || reservedPaths.includes(url.pathname.split("/")[1]))
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
if (url.pathname.startsWith("/reel") || url.pathname.startsWith("/tv"))
|
||||
resolve(`${randomInstance}/p${url.pathname.replace(/\/reel|\/tv/i, '')}${url.search}`);
|
||||
else
|
||||
resolve(`${randomInstance}/u${url.pathname}${url.search}`); // Likely a user profile, redirect to '/u/...'
|
||||
disableInstagram = r.disableInstagram;
|
||||
instagramProtocol = r.instagramProtocol;
|
||||
instagramRedirects = r.instagramRedirects;
|
||||
bibliogramNormalRedirectsChecks = r.bibliogramNormalRedirectsChecks;
|
||||
bibliogramTorRedirectsChecks = r.bibliogramTorRedirectsChecks;
|
||||
bibliogramNormalCustomRedirects = r.bibliogramNormalCustomRedirects;
|
||||
bibliogramTorCustomRedirects = r.bibliogramTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...instagramRedirects.bibliogram.normal,
|
||||
...instagramRedirects.bibliogram.tor,
|
||||
...bibliogramNormalCustomRedirects,
|
||||
...bibliogramTorCustomRedirects,
|
||||
]
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
if (disableInstagram) return;
|
||||
if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB';
|
||||
if (!targets.includes(url.host)) return;
|
||||
if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media"].includes(type)) return;
|
||||
|
||||
const bypassPaths = [/about/, /explore/, /support/, /press/, /api/, /privacy/, /safety/, /admin/, /\/(accounts\/|embeds?.js)/];
|
||||
if (bypassPaths.some(rx => rx.test(url.pathname))) return;
|
||||
|
||||
let instancesList;
|
||||
if (instagramProtocol == 'normal') instancesList = [...bibliogramNormalRedirectsChecks, ...bibliogramNormalCustomRedirects];
|
||||
else if (instagramProtocol == 'tor') instancesList = [...bibliogramTorRedirectsChecks, ...bibliogramTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
|
||||
const reservedPaths = ["u", "p", "privacy",];
|
||||
if (url.pathname === "/" || reservedPaths.includes(url.pathname.split("/")[1]))
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
if (url.pathname.startsWith("/reel") || url.pathname.startsWith("/tv"))
|
||||
return `${randomInstance}/p${url.pathname.replace(/\/reel|\/tv/i, '')}${url.search}`;
|
||||
else
|
||||
return `${randomInstance}/u${url.pathname}${url.search}`; // Likely a user profile, redirect to '/u/...'
|
||||
}
|
||||
|
||||
function reverse(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"instagramRedirects",
|
||||
"bibliogramNormalCustomRedirects",
|
||||
"bibliogramTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.instagramRedirects.bibliogram.normal,
|
||||
...r.instagramRedirects.bibliogram.tor,
|
||||
...r.bibliogramNormalCustomRedirects,
|
||||
...r.bibliogramTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (url.pathname.startsWith('/p')) {
|
||||
resolve(`https://instagram.com${url.pathname.replace('/p', '')}${url.search}`); return;
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith('/u')) {
|
||||
resolve(`https://instagram.com${url.pathname.replace('/u', '')}${url.search}`); return;
|
||||
}
|
||||
|
||||
resolve(`https://instagram.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
if (url.pathname.startsWith('/p')) resolve(`https://instagram.com${url.pathname.replace('/p', '')}${url.search}`);
|
||||
if (url.pathname.startsWith('/u')) resolve(`https://instagram.com${url.pathname.replace('/u', '')}${url.search}`);
|
||||
resolve(`https://instagram.com${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"instagramRedirects",
|
||||
"instagramProtocol",
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
"bibliogramNormalRedirectsChecks",
|
||||
"bibliogramTorRedirectsChecks",
|
||||
let instancesList;
|
||||
if (instagramProtocol == 'normal') instancesList = [...bibliogramNormalCustomRedirects, ...bibliogramNormalRedirectsChecks];
|
||||
else if (instagramProtocol == 'tor') instancesList = [...bibliogramTorCustomRedirects, ...bibliogramTorRedirectsChecks];
|
||||
|
||||
"bibliogramNormalCustomRedirects",
|
||||
"bibliogramTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
if (![
|
||||
...r.instagramRedirects.bibliogram.normal,
|
||||
...r.instagramRedirects.bibliogram.tor,
|
||||
...r.bibliogramNormalCustomRedirects,
|
||||
...r.bibliogramTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.instagramProtocol == 'normal') instancesList = [...r.bibliogramNormalCustomRedirects, ...r.bibliogramNormalRedirectsChecks];
|
||||
else if (r.instagramProtocol == 'tor') instancesList = [...r.bibliogramTorCustomRedirects, ...r.bibliogramTorRedirectsChecks];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
@ -157,7 +136,7 @@ function initDefaults() {
|
||||
browser.storage.local.get('cloudflareList', r => {
|
||||
bibliogramNormalRedirectsChecks = [...redirects.bibliogram.normal];
|
||||
for (const instance of r.cloudflareList) {
|
||||
let i = bibliogramNormalRedirectsChecks.indexOf(instance);
|
||||
const i = bibliogramNormalRedirectsChecks.indexOf(instance);
|
||||
if (i > -1) bibliogramNormalRedirectsChecks.splice(i, 1);
|
||||
}
|
||||
browser.storage.local.set({
|
||||
@ -180,9 +159,7 @@ function initDefaults() {
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
|
||||
reverse,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
switchInstance,
|
||||
|
@ -24,7 +24,6 @@ let redirects = {
|
||||
function setRedirects(val) {
|
||||
redirects.librarian = val;
|
||||
browser.storage.local.set({ lbryTargetsRedirects: redirects })
|
||||
console.log("lbryTargetsRedirects: ", val)
|
||||
for (const item of librarianNormalRedirectsChecks)
|
||||
if (!redirects.librarian.normal.includes(item)) {
|
||||
var index = librarianNormalRedirectsChecks.indexOf(item);
|
||||
@ -40,85 +39,85 @@ function setRedirects(val) {
|
||||
browser.storage.local.set(librarianTorRedirectsChecks)
|
||||
}
|
||||
|
||||
let librarianNormalRedirectsChecks;
|
||||
let librarianTorRedirectsChecks;
|
||||
let
|
||||
disableLbryTargets,
|
||||
lbryTargetsProtocol,
|
||||
lbryTargetsRedirects,
|
||||
librarianNormalRedirectsChecks,
|
||||
librarianNormalCustomRedirects,
|
||||
librarianTorRedirectsChecks,
|
||||
librarianTorCustomRedirects;
|
||||
|
||||
async function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"lbryTargetsRedirects",
|
||||
"lbryTargetsProtocol",
|
||||
|
||||
"librarianNormalRedirectsChecks",
|
||||
"librarianNormalCustomRedirects",
|
||||
|
||||
"librarianTorRedirectsChecks",
|
||||
"librarianTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...redirects.librarian.normal,
|
||||
...redirects.librarian.tor,
|
||||
...r.librarianNormalCustomRedirects,
|
||||
...r.librarianTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
let instancesList;
|
||||
if (r.lbryTargetsProtocol == 'normal') instancesList = [...r.librarianNormalRedirectsChecks, ...r.librarianNormalCustomRedirects];
|
||||
else if (r.lbryTargetsProtocol == 'tor') instancesList = [...r.librarianTorRedirectsChecks, ...r.librarianTorCustomRedirects];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) resolve();
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableLbryTargets",
|
||||
"lbryTargetsProtocol",
|
||||
|
||||
"lbryTargetsRedirects",
|
||||
|
||||
"librarianNormalRedirectsChecks",
|
||||
"librarianNormalCustomRedirects",
|
||||
|
||||
"librarianTorRedirectsChecks",
|
||||
"librarianTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableLbryTargets) { resolve(); return; }
|
||||
if (initiator && (
|
||||
[
|
||||
...r.lbryTargetsRedirects.librarian.normal,
|
||||
...r.librarianNormalCustomRedirects,
|
||||
...r.librarianTorCustomRedirects,
|
||||
].includes(initiator.origin) ||
|
||||
targets.includes(initiator.host))
|
||||
) { resolve(); return; }
|
||||
if (!targets.includes(url.host)) { resolve(); return; }
|
||||
if (type != "main_frame") { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.lbryTargetsProtocol == 'normal') instancesList = [...r.librarianNormalRedirectsChecks, ...r.librarianNormalCustomRedirects];
|
||||
if (r.lbryTargetsProtocol == 'tor') instancesList = [...r.librarianTorRedirectsChecks, ...r.librarianTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
disableLbryTargets = r.disableLbryTargets;
|
||||
lbryTargetsProtocol = r.lbryTargetsProtocol;
|
||||
lbryTargetsRedirects = r.lbryTargetsRedirects;
|
||||
librarianNormalRedirectsChecks = r.librarianNormalRedirectsChecks;
|
||||
librarianNormalCustomRedirects = r.librarianNormalCustomRedirects;
|
||||
librarianTorRedirectsChecks = r.librarianTorRedirectsChecks;
|
||||
librarianTorCustomRedirects = r.librarianTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...redirects.librarian.normal,
|
||||
...redirects.librarian.tor,
|
||||
...librarianNormalCustomRedirects,
|
||||
...librarianTorCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (lbryTargetsProtocol == 'normal') instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects];
|
||||
else if (lbryTargetsProtocol == 'tor') instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects];
|
||||
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
if (disableLbryTargets) return;
|
||||
if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return;
|
||||
if (!targets.includes(url.host)) return;
|
||||
if (type != "main_frame") return;
|
||||
|
||||
let instancesList;
|
||||
if (lbryTargetsProtocol == 'normal') instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects];
|
||||
if (lbryTargetsProtocol == 'tor') instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function initDefaults() {
|
||||
return new Promise(resolve => {
|
||||
@ -152,7 +151,6 @@ function initDefaults() {
|
||||
export default {
|
||||
setRedirects,
|
||||
switchInstance,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
};
|
||||
|
@ -18,189 +18,189 @@ let redirects = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let
|
||||
disableMaps,
|
||||
mapsFrontend,
|
||||
facilNormalRedirectsChecks,
|
||||
facilNormalCustomRedirects;
|
||||
|
||||
function init() {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableMaps",
|
||||
"mapsFrontend",
|
||||
"facilNormalRedirectsChecks",
|
||||
"facilNormalCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
disableMaps = r.disableMaps;
|
||||
mapsFrontend = r.mapsFrontend;
|
||||
facilNormalRedirectsChecks = r.facilNormalRedirectsChecks;
|
||||
facilNormalCustomRedirects = r.facilNormalCustomRedirects;
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function redirect(url, initiator) {
|
||||
return new Promise(
|
||||
resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableMaps",
|
||||
"mapsFrontend",
|
||||
const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
|
||||
const dataLatLngRegex = /!3d(-?[0-9]{1,}.[0-9]{1,})!4d(-?[0-9]{1,}.[0-9]{1,})/;
|
||||
const placeRegex = /\/place\/(.*)\//;
|
||||
const travelModes = {
|
||||
driving: "fossgis_osrm_car",
|
||||
walking: "fossgis_osrm_foot",
|
||||
bicycling: "fossgis_osrm_bike",
|
||||
transit: "fossgis_osrm_car", // not implemented on OSM, default to car.
|
||||
};
|
||||
const travelModesFacil = {
|
||||
driving: "car",
|
||||
walking: "pedestrian",
|
||||
bicycling: "bicycle",
|
||||
transit: "car", // not implemented on Facil, default to car.
|
||||
};
|
||||
const osmLayers = {
|
||||
none: "S",
|
||||
transit: "T",
|
||||
traffic: "S", // not implemented on OSM, default to standard.
|
||||
bicycling: "C",
|
||||
};
|
||||
|
||||
"facilNormalRedirectsChecks",
|
||||
"facilNormalCustomRedirects",
|
||||
],
|
||||
async r => {
|
||||
const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
|
||||
const dataLatLngRegex = /!3d(-?[0-9]{1,}.[0-9]{1,})!4d(-?[0-9]{1,}.[0-9]{1,})/;
|
||||
const placeRegex = /\/place\/(.*)\//;
|
||||
const travelModes = {
|
||||
driving: "fossgis_osrm_car",
|
||||
walking: "fossgis_osrm_foot",
|
||||
bicycling: "fossgis_osrm_bike",
|
||||
transit: "fossgis_osrm_car", // not implemented on OSM, default to car.
|
||||
};
|
||||
const travelModesFacil = {
|
||||
driving: "car",
|
||||
walking: "pedestrian",
|
||||
bicycling: "bicycle",
|
||||
transit: "car", // not implemented on Facil, default to car.
|
||||
};
|
||||
const osmLayers = {
|
||||
none: "S",
|
||||
transit: "T",
|
||||
traffic: "S", // not implemented on OSM, default to standard.
|
||||
bicycling: "C",
|
||||
};
|
||||
function addressToLatLng(address) {
|
||||
const xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false);
|
||||
xmlhttp.send();
|
||||
if (xmlhttp.status === 200) {
|
||||
const json = JSON.parse(xmlhttp.responseText)[0];
|
||||
if (json) {
|
||||
console.log('json', json)
|
||||
return [
|
||||
`${json.lat},${json.lon}`,
|
||||
`${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`,
|
||||
];
|
||||
}
|
||||
}
|
||||
console.info("Error: Status is " + xmlhttp.status);
|
||||
}
|
||||
|
||||
async function addressToLatLng(address) {
|
||||
return new Promise(async resolve => {
|
||||
const xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = () => {
|
||||
if (xmlhttp.readyState === XMLHttpRequest.DONE) {
|
||||
if (xmlhttp.status === 200) {
|
||||
const json = JSON.parse(xmlhttp.responseText)[0];
|
||||
if (disableMaps) return;
|
||||
if (initiator && initiator.host === "earth.google.com") return;
|
||||
if (!url.href.match(targets)) return;
|
||||
|
||||
if (json) {
|
||||
console.log('json', json)
|
||||
resolve([
|
||||
`${json.lat},${json.lon}`,
|
||||
`${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`,
|
||||
]);
|
||||
}
|
||||
} else
|
||||
console.info("Error: Status is " + xmlhttp.status);
|
||||
}
|
||||
};
|
||||
xmlhttp.open(
|
||||
"GET",
|
||||
`https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`,
|
||||
true
|
||||
);
|
||||
xmlhttp.send();
|
||||
})
|
||||
}
|
||||
let randomInstance;
|
||||
if (mapsFrontend == 'osm') randomInstance = utils.getRandomInstance(redirects.osm.normal);
|
||||
if (mapsFrontend == 'facil') randomInstance = utils.getRandomInstance([...facilNormalRedirectsChecks, ...facilNormalCustomRedirects]);
|
||||
|
||||
if (r.disableMaps) { resolve(); return; }
|
||||
if (initiator && initiator.host === "earth.google.com") { resolve(); return; }
|
||||
if (!url.href.match(targets)) { resolve(); return; }
|
||||
let mapCentre = "#";
|
||||
let prefs = {};
|
||||
|
||||
let randomInstance;
|
||||
if (r.mapsFrontend == 'osm') randomInstance = utils.getRandomInstance(redirects.osm.normal);
|
||||
if (r.mapsFrontend == 'facil') randomInstance = utils.getRandomInstance([...r.facilNormalRedirectsChecks, ...r.facilNormalCustomRedirects]);
|
||||
if (url.pathname.match(mapCentreRegex)) { // Set map centre if present
|
||||
var [, lat, lon, zoom] = url.pathname.match(mapCentreRegex);
|
||||
} else if (url.searchParams.has("center")) {
|
||||
var [lat, lon] = url.searchParams.get("center").split(",");
|
||||
var zoom = url.searchParams.get("zoom") ?? "17";
|
||||
}
|
||||
|
||||
let mapCentre = "#";
|
||||
let prefs = {};
|
||||
if (lat && lon && zoom) {
|
||||
if (mapsFrontend == 'osm') mapCentre = `#map=${zoom}/${lat}/${lon}`;
|
||||
if (mapsFrontend == 'facil') mapCentre = `#${zoom}/${lat}/${lon}`;
|
||||
}
|
||||
|
||||
if (url.pathname.match(mapCentreRegex)) { // Set map centre if present
|
||||
var [, lat, lon, zoom] = url.pathname.match(mapCentreRegex);
|
||||
} else if (url.searchParams.has("center")) {
|
||||
var [lat, lon] = url.searchParams.get("center").split(",");
|
||||
var zoom = url.searchParams.get("zoom") ?? "17";
|
||||
}
|
||||
if (url.searchParams.get("layer")) prefs.layers = osmLayers[url.searchParams.get("layer")];
|
||||
|
||||
if (lat && lon && zoom) {
|
||||
if (r.mapsFrontend == 'osm') mapCentre = `#map=${zoom}/${lat}/${lon}`;
|
||||
if (r.mapsFrontend == 'facil') mapCentre = `#${zoom}/${lat}/${lon}`;
|
||||
}
|
||||
if (url.pathname.includes("/embed")) { // Handle Google Maps Embed API
|
||||
// https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Eiffel+Tower,Paris+France
|
||||
console.log("embed life");
|
||||
|
||||
if (url.searchParams.get("layer")) prefs.layers = osmLayers[url.searchParams.get("layer")];
|
||||
let query = "";
|
||||
if (url.searchParams.has("q")) query = url.searchParams.get("q");
|
||||
else if (url.searchParams.has("query")) query = url.searchParams.has("query");
|
||||
|
||||
if (url.pathname.includes("/embed")) { // Handle Google Maps Embed API
|
||||
// https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Eiffel+Tower,Paris+France
|
||||
console.log("embed life");
|
||||
else if (url.searchParams.has("pb"))
|
||||
try { query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1]; }
|
||||
catch (error) { console.error(error); } // Unable to find map marker in URL.
|
||||
|
||||
let query = "";
|
||||
if (url.searchParams.has("q")) query = url.searchParams.get("q");
|
||||
else if (url.searchParams.has("query")) query = url.searchParams.has("query");
|
||||
let [coords, boundingbox] = addressToLatLng(query);
|
||||
prefs.bbox = boundingbox;
|
||||
prefs.marker = coords;
|
||||
prefs.layer = "mapnik";
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/export/embed.html?${prefsEncoded}`); return; }
|
||||
|
||||
else if (url.searchParams.has("pb"))
|
||||
try { query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1]; }
|
||||
catch (error) { console.error(error); } // Unable to find map marker in URL.
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${query}`); return; }
|
||||
|
||||
let [coords, boundingbox] = await addressToLatLng(query);
|
||||
prefs.bbox = boundingbox;
|
||||
prefs.marker = coords;
|
||||
prefs.layer = "mapnik";
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/export/embed.html?${prefsEncoded}`); return; }
|
||||
} else if (url.pathname.includes("/dir")) { // Handle Google Maps Directions
|
||||
// https://www.google.com/maps/dir/?api=1&origin=Space+Needle+Seattle+WA&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling
|
||||
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${query}`); return; }
|
||||
let travMod = url.searchParams.get("travelmode");
|
||||
if (url.searchParams.has("travelmode")) prefs.engine = travelModes[travMod];
|
||||
|
||||
} else if (url.pathname.includes("/dir")) { // Handle Google Maps Directions
|
||||
// https://www.google.com/maps/dir/?api=1&origin=Space+Needle+Seattle+WA&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling
|
||||
let orgVal = url.searchParams.get("origin");
|
||||
let destVal = url.searchParams.get("destination");
|
||||
|
||||
let travMod = url.searchParams.get("travelmode");
|
||||
if (url.searchParams.has("travelmode")) prefs.engine = travelModes[travMod];
|
||||
let org; addressToLatLng(orgVal, a => org = a);
|
||||
let dest; addressToLatLng(destVal, a => dest = a);
|
||||
prefs.route = `${org};${dest}`;
|
||||
|
||||
let orgVal = url.searchParams.get("origin");
|
||||
let destVal = url.searchParams.get("destination");
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/directions?${prefsEncoded}${mapCentre}`); return; }
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${orgVal}%20to%20${destVal}%20by%20${travelModesFacil[travMod]}`); return; }
|
||||
|
||||
let org; addressToLatLng(orgVal, a => org = a);
|
||||
let dest; addressToLatLng(destVal, a => dest = a);
|
||||
prefs.route = `${org};${dest}`;
|
||||
} else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { // Get marker from data attribute
|
||||
// https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948
|
||||
console.log("data life");
|
||||
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/directions?${prefsEncoded}${mapCentre}`); return; }
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${orgVal}%20to%20${destVal}%20by%20${travelModesFacil[travMod]}`); return; }
|
||||
let [, mlat, mlon] = url.pathname.match(dataLatLngRegex);
|
||||
|
||||
} else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { // Get marker from data attribute
|
||||
// https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948
|
||||
console.log("data life");
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
|
||||
|
||||
let [, mlat, mlon] = url.pathname.match(dataLatLngRegex);
|
||||
} else if (url.searchParams.has("ll")) { // Get marker from ll param
|
||||
// https://maps.google.com/?ll=38.882147,-76.99017
|
||||
console.log("ll life");
|
||||
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
|
||||
const [mlat, mlon] = url.searchParams.get("ll").split(",");
|
||||
|
||||
} else if (url.searchParams.has("ll")) { // Get marker from ll param
|
||||
// https://maps.google.com/?ll=38.882147,-76.99017
|
||||
console.log("ll life");
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
|
||||
} else if (url.searchParams.has("viewpoint")) { // Get marker from viewpoint param.
|
||||
// https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80
|
||||
console.log("viewpoint life");
|
||||
|
||||
const [mlat, mlon] = url.searchParams.get("ll").split(",");
|
||||
const [mlat, mlon] = url.searchParams.get("viewpoint").split(",");
|
||||
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
|
||||
} else if (url.searchParams.has("viewpoint")) { // Get marker from viewpoint param.
|
||||
// https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80
|
||||
console.log("viewpoint life");
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
|
||||
} else { // Use query as search if present.
|
||||
console.log("normal life");
|
||||
|
||||
const [mlat, mlon] = url.searchParams.get("viewpoint").split(",");
|
||||
let query;
|
||||
if (url.searchParams.has("q")) query = url.searchParams.get("q");
|
||||
else if (url.searchParams.has("query")) query = url.searchParams.get("query");
|
||||
else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1];
|
||||
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
|
||||
} else { // Use query as search if present.
|
||||
console.log("normal life");
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
if (query) {
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query="${query}${mapCentre}&${prefsEncoded}`); return; }
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk/${query}`); return; }
|
||||
}
|
||||
}
|
||||
|
||||
let query;
|
||||
if (url.searchParams.has("q")) query = url.searchParams.get("q");
|
||||
else if (url.searchParams.has("query")) query = url.searchParams.get("query");
|
||||
else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1];
|
||||
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
if (query) {
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query="${query}${mapCentre}&${prefsEncoded}`); return; }
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk/${query}`); return; }
|
||||
}
|
||||
}
|
||||
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
console.log("mapCentre", mapCentre);
|
||||
console.log("prefs", prefs);
|
||||
console.log("prefsEncoded", prefsEncoded);
|
||||
if (r.mapsFrontend == 'osm') { resolve(`${randomInstance}/${mapCentre}&${prefsEncoded}`); return; }
|
||||
if (r.mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk`); return; }
|
||||
}
|
||||
)
|
||||
})
|
||||
let prefsEncoded = new URLSearchParams(prefs).toString();
|
||||
console.log("mapCentre", mapCentre);
|
||||
console.log("prefs", prefs);
|
||||
console.log("prefsEncoded", prefsEncoded);
|
||||
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/${mapCentre}&${prefsEncoded}`); return; }
|
||||
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk`); return; }
|
||||
}
|
||||
|
||||
async function initDefaults() {
|
||||
await browser.storage.local.set({
|
||||
disableMaps: false,
|
||||
mapsFrontend: 'osm',
|
||||
|
||||
mapsRedirects: redirects,
|
||||
|
||||
facilNormalRedirectsChecks: [...redirects.facil.normal],
|
||||
facilNormalCustomRedirects: [],
|
||||
})
|
||||
|
@ -49,10 +49,16 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
let scribeNormalRedirectsChecks;
|
||||
let scribeTorRedirectsChecks;
|
||||
let
|
||||
disableMedium,
|
||||
mediumRedirects,
|
||||
scribeNormalRedirectsChecks,
|
||||
scribeNormalCustomRedirects,
|
||||
scribeTorRedirectsChecks,
|
||||
scribeTorCustomRedirects,
|
||||
mediumProtocol;
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
@ -65,63 +71,67 @@ function redirect(url, type, initiator) {
|
||||
"mediumProtocol"
|
||||
],
|
||||
r => {
|
||||
if (r.disableMedium) { resolve(); return; }
|
||||
if (type != "main_frame" && "sub_frame" && "xmlhttprequest" && "other") { resolve(); return; }
|
||||
if (initiator && (
|
||||
[
|
||||
...r.mediumRedirects.scribe.normal,
|
||||
...r.mediumRedirects.scribe.tor,
|
||||
...r.scribeNormalCustomRedirects,
|
||||
...r.scribeTorCustomRedirects,
|
||||
].includes(initiator.origin))) { resolve(); return; }
|
||||
|
||||
if (!targets.some(rx => rx.test(url.host))) { resolve(); return; }
|
||||
if (/^\/($|@[a-zA-Z.]{0,}(\/|)$)/.test(url.pathname)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.mediumProtocol == 'normal') instancesList = [...r.scribeNormalRedirectsChecks, ...r.scribeNormalCustomRedirects];
|
||||
else if (r.mediumProtocol == 'tor') instancesList = [...r.scribeTorRedirectsChecks, ...r.scribeTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
disableMedium = r.disableMedium;
|
||||
mediumRedirects = r.mediumRedirects;
|
||||
scribeNormalRedirectsChecks = r.scribeNormalRedirectsChecks;
|
||||
scribeNormalCustomRedirects = r.scribeNormalCustomRedirects;
|
||||
scribeTorRedirectsChecks = r.scribeTorRedirectsChecks;
|
||||
scribeTorCustomRedirects = r.scribeTorCustomRedirects;
|
||||
mediumProtocol = r.mediumProtocol;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
if (disableMedium) return;
|
||||
if (type != "main_frame" && "sub_frame" && "xmlhttprequest" && "other") return;
|
||||
if (initiator && (
|
||||
[
|
||||
...mediumRedirects.scribe.normal,
|
||||
...mediumRedirects.scribe.tor,
|
||||
...scribeNormalCustomRedirects,
|
||||
...scribeTorCustomRedirects,
|
||||
].includes(initiator.origin))) return;
|
||||
|
||||
if (!targets.some(rx => rx.test(url.host))) return;
|
||||
if (/^\/($|@[a-zA-Z.]{0,}(\/|)$)/.test(url.pathname)) return;
|
||||
|
||||
let instancesList;
|
||||
if (mediumProtocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects];
|
||||
else if (mediumProtocol == 'tor') instancesList = [...scribeTorRedirectsChecks, ...scribeTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList)
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"mediumRedirects",
|
||||
"mediumProtocol",
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
const all = [
|
||||
...mediumRedirects.scribe.tor,
|
||||
...mediumRedirects.scribe.normal,
|
||||
|
||||
"scribeNormalRedirectsChecks",
|
||||
"scribeNormalCustomRedirects",
|
||||
"scribeTorRedirectsChecks",
|
||||
"scribeTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.mediumRedirects.scribe.tor,
|
||||
...r.mediumRedirects.scribe.normal,
|
||||
...scribeNormalCustomRedirects,
|
||||
...scribeTorCustomRedirects,
|
||||
];
|
||||
if (!all.includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
...r.scribeNormalCustomRedirects,
|
||||
...r.scribeTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
let instancesList;
|
||||
if (mediumProtocol == 'normal') instancesList = [...scribeNormalCustomRedirects, ...scribeNormalRedirectsChecks];
|
||||
else if (mediumProtocol == 'tor') instancesList = [...scribeTorCustomRedirects, ...scribeTorRedirectsChecks];
|
||||
|
||||
let instancesList;
|
||||
if (r.mediumProtocol == 'normal') instancesList = [...r.scribeNormalCustomRedirects, ...r.scribeNormalRedirectsChecks];
|
||||
else if (r.mediumProtocol == 'tor') instancesList = [...r.scribeTorCustomRedirects, ...r.scribeTorRedirectsChecks];
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
@ -157,8 +167,7 @@ function initDefaults() {
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
switchInstance,
|
||||
initDefaults,
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ let redirects = {
|
||||
"simpleertube": {
|
||||
"normal": [
|
||||
"https://tube.simple-web.org",
|
||||
"https://tube.fr.tild3.org",
|
||||
"https://tube.ftild3.org",
|
||||
"https://stube.alefvanoon.xyz",
|
||||
"https://st.phreedom.club",
|
||||
"https://simpleertube.esmailelbob.xyz",
|
||||
@ -31,94 +31,93 @@ function setRedirects(val) {
|
||||
}
|
||||
browser.storage.local.set({ simpleertubeTorRedirectsChecks })
|
||||
}
|
||||
|
||||
let
|
||||
disablePeertubeTargets,
|
||||
peertubeRedirects,
|
||||
simpleertubeNormalRedirectsChecks,
|
||||
simpleertubeTorRedirectsChecks;
|
||||
simpleertubeNormalCustomRedirects,
|
||||
simpleertubeTorRedirectsChecks,
|
||||
simpleertubeTorCustomRedirects,
|
||||
peerTubeTargets,
|
||||
peertubeTargetsProtocol;
|
||||
|
||||
|
||||
async function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"peerTubeTargets",
|
||||
"peertubeTargetsProtocol",
|
||||
|
||||
"simpleertubeNormalRedirectsChecks",
|
||||
"simpleertubeNormalCustomRedirects",
|
||||
|
||||
"simpleertubeTorRedirectsChecks",
|
||||
"simpleertubeTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...redirects.simpleertube.normal,
|
||||
...redirects.simpleertube.tor,
|
||||
...r.simpleertubeNormalCustomRedirects,
|
||||
...r.simpleertubeTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
let instancesList;
|
||||
if (r.peertubeTargetsProtocol == 'normal') instancesList = [...r.simpleertubeNormalRedirectsChecks, ...r.simpleertubeNormalCustomRedirects];
|
||||
else if (r.peertubeTargetsProtocol == 'tor') instancesList = [...r.simpleertubeTorRedirectsChecks, ...r.simpleertubeTorCustomRedirects];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) resolve()
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disablePeertubeTargets",
|
||||
|
||||
"peertubeRedirects",
|
||||
|
||||
"simpleertubeNormalRedirectsChecks",
|
||||
"simpleertubeNormalCustomRedirects",
|
||||
|
||||
"simpleertubeTorRedirectsChecks",
|
||||
"simpleertubeTorCustomRedirects",
|
||||
|
||||
"peerTubeTargets",
|
||||
"peertubeTargetsProtocol"
|
||||
],
|
||||
r => {
|
||||
if (r.disablePeertubeTargets) { resolve(); return; }
|
||||
if (
|
||||
initiator &&
|
||||
(
|
||||
[
|
||||
...r.peertubeRedirects.simpleertube.normal,
|
||||
...r.simpleertubeNormalCustomRedirects
|
||||
].includes(initiator.origin) ||
|
||||
r.peerTubeTargets.includes(initiator.host)
|
||||
)
|
||||
) { resolve(); return; }
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (!r.peerTubeTargets.includes(protocolHost)) { resolve(); return; }
|
||||
if (type != "main_frame") { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.peertubeTargetsProtocol == 'normal') instancesList = [...r.simpleertubeNormalRedirectsChecks, ...r.simpleertubeNormalCustomRedirects];
|
||||
if (r.peertubeTargetsProtocol == 'tor') instancesList = [...r.simpleertubeTorRedirectsChecks, ...r.simpleertubeTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
if (url.host == 'search.joinpeertube.org') { resolve(randomInstance); return; }
|
||||
|
||||
resolve(`${randomInstance}/${url.host}${url.pathname}${url.search}`);
|
||||
disablePeertubeTargets = r.disablePeertubeTargets;
|
||||
peertubeRedirects = r.peertubeRedirects;
|
||||
simpleertubeNormalRedirectsChecks = r.simpleertubeNormalRedirectsChecks;
|
||||
simpleertubeNormalCustomRedirects = r.simpleertubeNormalCustomRedirects;
|
||||
simpleertubeTorRedirectsChecks = r.simpleertubeTorRedirectsChecks;
|
||||
simpleertubeTorCustomRedirects = r.simpleertubeTorCustomRedirects;
|
||||
peerTubeTargets = r.peerTubeTargets;
|
||||
peertubeTargetsProtocol = r.peertubeTargetsProtocol;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
async function initDefaults() {
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...redirects.simpleertube.normal,
|
||||
...redirects.simpleertube.tor,
|
||||
...simpleertubeNormalCustomRedirects,
|
||||
...simpleertubeTorCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
if (disablePeertubeTargets) return;
|
||||
if (initiator && (all().includes(initiator.origin) || peerTubeTargets.includes(initiator.host))) return;
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (!peerTubeTargets.includes(protocolHost)) return;
|
||||
if (type != "main_frame") return;
|
||||
|
||||
let instancesList;
|
||||
if (peertubeTargetsProtocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects];
|
||||
if (peertubeTargetsProtocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
if (url.host == 'search.joinpeertube.org' || url.host == 'sepiasearch.org') return randomInstance;
|
||||
return `${randomInstance}/${url.host}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (peertubeTargetsProtocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects];
|
||||
else if (peertubeTargetsProtocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects];
|
||||
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function initDefaults() {
|
||||
return new Promise(resolve => {
|
||||
fetch('/instances/data.json').then(response => response.text()).then(async data => {
|
||||
let dataJson = JSON.parse(data);
|
||||
|
@ -37,353 +37,289 @@ function setRedirects(val) {
|
||||
}
|
||||
|
||||
let
|
||||
disableReddit,
|
||||
redditFrontend,
|
||||
redditRedirects,
|
||||
redditProtocol,
|
||||
libredditNormalRedirectsChecks,
|
||||
tedditNormalRedirectsChecks;
|
||||
libredditNormalCustomRedirects,
|
||||
libredditTorRedirectsChecks,
|
||||
libredditTorCustomRedirects,
|
||||
tedditNormalRedirectsChecks,
|
||||
tedditNormalCustomRedirects,
|
||||
tedditTorRedirectsChecks,
|
||||
tedditTorCustomRedirects;
|
||||
|
||||
function initLibredditCookies(test, from) {
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"redditProtocol",
|
||||
"libredditNormalRedirectsChecks",
|
||||
"libredditNormalCustomRedirects",
|
||||
"libredditTorRedirectsChecks",
|
||||
"libredditTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.libredditNormalRedirectsChecks,
|
||||
...r.libredditTorRedirectsChecks,
|
||||
...r.libredditNormalCustomRedirects,
|
||||
...r.libredditTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.redditProtocol == 'normal') checkedInstances = [...r.libredditNormalRedirectsChecks, ...r.libredditNormalCustomRedirects];
|
||||
else if (r.redditProtocol == 'tor') checkedInstances = [...r.libredditTorRedirectsChecks, ...r.libredditTorCustomRedirects];
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('libreddit', from, to, "theme");
|
||||
utils.copyCookie('libreddit', from, to, "front_page");
|
||||
utils.copyCookie('libreddit', from, to, "layout");
|
||||
utils.copyCookie('libreddit', from, to, "wide");
|
||||
utils.copyCookie('libreddit', from, to, "post_sort");
|
||||
utils.copyCookie('libreddit', from, to, "comment_sort");
|
||||
utils.copyCookie('libreddit', from, to, "show_nsfw");
|
||||
utils.copyCookie('libreddit', from, to, "autoplay_videos");
|
||||
utils.copyCookie('libreddit', from, to, "use_hls");
|
||||
utils.copyCookie('libreddit', from, to, "hide_hls_notification");
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function setLibredditCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"redditProtocol",
|
||||
"disableReddit",
|
||||
"redditFrontend",
|
||||
"redditRedirects",
|
||||
"redditProtocol",
|
||||
"libredditNormalRedirectsChecks",
|
||||
"libredditNormalCustomRedirects",
|
||||
"libredditTorRedirectsChecks",
|
||||
"libredditTorCustomRedirects",
|
||||
"tedditNormalRedirectsChecks",
|
||||
"tedditNormalCustomRedirects",
|
||||
"tedditTorRedirectsChecks",
|
||||
"tedditTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableReddit || r.redditFrontend != 'libreddit' || r.redditProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.redditProtocol == 'normal') checkedInstances = [...r.libredditNormalRedirectsChecks, ...r.libredditNormalCustomRedirects]
|
||||
else if (r.redditProtocol == 'tor') checkedInstances = [...r.libredditTorRedirectsChecks, ...r.libredditTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('libreddit', to, "theme");
|
||||
utils.getCookiesFromStorage('libreddit', to, "front_page");
|
||||
utils.getCookiesFromStorage('libreddit', to, "layout");
|
||||
utils.getCookiesFromStorage('libreddit', to, "wide");
|
||||
utils.getCookiesFromStorage('libreddit', to, "post_sort");
|
||||
utils.getCookiesFromStorage('libreddit', to, "comment_sort");
|
||||
utils.getCookiesFromStorage('libreddit', to, "show_nsfw");
|
||||
utils.getCookiesFromStorage('libreddit', to, "autoplay_videos");
|
||||
utils.getCookiesFromStorage('libreddit', to, "use_hls");
|
||||
utils.getCookiesFromStorage('libreddit', to, "hide_hls_notification");
|
||||
}
|
||||
disableReddit = r.disableReddit;
|
||||
redditFrontend = r.redditFrontend;
|
||||
redditRedirects = r.redditRedirects;
|
||||
redditProtocol = r.redditProtocol;
|
||||
libredditNormalRedirectsChecks = r.libredditNormalRedirectsChecks;
|
||||
libredditNormalCustomRedirects = r.libredditNormalCustomRedirects;
|
||||
libredditTorRedirectsChecks = r.libredditTorRedirectsChecks;
|
||||
libredditTorCustomRedirects = r.libredditTorCustomRedirects;
|
||||
tedditNormalRedirectsChecks = r.tedditNormalRedirectsChecks;
|
||||
tedditNormalCustomRedirects = r.tedditNormalCustomRedirects;
|
||||
tedditTorRedirectsChecks = r.tedditTorRedirectsChecks;
|
||||
tedditTorCustomRedirects = r.tedditTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function initLibredditCookies(test, from) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...libredditNormalRedirectsChecks,
|
||||
...libredditTorRedirectsChecks,
|
||||
...libredditNormalCustomRedirects,
|
||||
...libredditTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (redditProtocol == 'normal') checkedInstances = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects];
|
||||
else if (redditProtocol == 'tor') checkedInstances = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects];
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('libreddit', from, to, "theme");
|
||||
utils.copyCookie('libreddit', from, to, "front_page");
|
||||
utils.copyCookie('libreddit', from, to, "layout");
|
||||
utils.copyCookie('libreddit', from, to, "wide");
|
||||
utils.copyCookie('libreddit', from, to, "post_sort");
|
||||
utils.copyCookie('libreddit', from, to, "comment_sort");
|
||||
utils.copyCookie('libreddit', from, to, "show_nsfw");
|
||||
utils.copyCookie('libreddit', from, to, "autoplay_videos");
|
||||
utils.copyCookie('libreddit', from, to, "use_hls");
|
||||
utils.copyCookie('libreddit', from, to, "hide_hls_notification");
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setLibredditCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableReddit || redditFrontend != 'libreddit' || redditProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (redditProtocol == 'normal') checkedInstances = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]
|
||||
else if (redditProtocol == 'tor') checkedInstances = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('libreddit', to, "theme");
|
||||
utils.getCookiesFromStorage('libreddit', to, "front_page");
|
||||
utils.getCookiesFromStorage('libreddit', to, "layout");
|
||||
utils.getCookiesFromStorage('libreddit', to, "wide");
|
||||
utils.getCookiesFromStorage('libreddit', to, "post_sort");
|
||||
utils.getCookiesFromStorage('libreddit', to, "comment_sort");
|
||||
utils.getCookiesFromStorage('libreddit', to, "show_nsfw");
|
||||
utils.getCookiesFromStorage('libreddit', to, "autoplay_videos");
|
||||
utils.getCookiesFromStorage('libreddit', to, "use_hls");
|
||||
utils.getCookiesFromStorage('libreddit', to, "hide_hls_notification");
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
function initTedditCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"redditProtocol",
|
||||
"tedditNormalRedirectsChecks",
|
||||
"tedditNormalCustomRedirects",
|
||||
"tedditTorRedirectsChecks",
|
||||
"tedditTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.tedditNormalRedirectsChecks,
|
||||
...r.tedditTorRedirectsChecks,
|
||||
...r.tedditNormalCustomRedirects,
|
||||
...r.tedditTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...tedditNormalRedirectsChecks,
|
||||
...tedditTorRedirectsChecks,
|
||||
...tedditNormalCustomRedirects,
|
||||
...tedditTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.redditProtocol == 'normal') checkedInstances = [...r.tedditNormalRedirectsChecks, ...r.tedditNormalCustomRedirects]
|
||||
else if (r.redditProtocol == 'tor') checkedInstances = [...r.tedditTorRedirectsChecks, ...r.tedditTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('teddit', from, to, 'collapse_child_comments')
|
||||
utils.copyCookie('teddit', from, to, 'domain_instagram')
|
||||
utils.copyCookie('teddit', from, to, 'domain_twitter')
|
||||
utils.copyCookie('teddit', from, to, 'domain_youtube')
|
||||
utils.copyCookie('teddit', from, to, 'flairs')
|
||||
utils.copyCookie('teddit', from, to, 'highlight_controversial')
|
||||
utils.copyCookie('teddit', from, to, 'nsfw_enabled')
|
||||
utils.copyCookie('teddit', from, to, 'post_media_max_height')
|
||||
utils.copyCookie('teddit', from, to, 'show_upvoted_percentage')
|
||||
utils.copyCookie('teddit', from, to, 'show_upvotes')
|
||||
utils.copyCookie('teddit', from, to, 'theme')
|
||||
utils.copyCookie('teddit', from, to, 'videos_muted')
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (redditProtocol == 'normal') checkedInstances = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects]
|
||||
else if (redditProtocol == 'tor') checkedInstances = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('teddit', from, to, 'collapse_child_comments')
|
||||
utils.copyCookie('teddit', from, to, 'domain_instagram')
|
||||
utils.copyCookie('teddit', from, to, 'domain_twitter')
|
||||
utils.copyCookie('teddit', from, to, 'domain_youtube')
|
||||
utils.copyCookie('teddit', from, to, 'flairs')
|
||||
utils.copyCookie('teddit', from, to, 'highlight_controversial')
|
||||
utils.copyCookie('teddit', from, to, 'nsfw_enabled')
|
||||
utils.copyCookie('teddit', from, to, 'post_media_max_height')
|
||||
utils.copyCookie('teddit', from, to, 'show_upvoted_percentage')
|
||||
utils.copyCookie('teddit', from, to, 'show_upvotes')
|
||||
utils.copyCookie('teddit', from, to, 'theme')
|
||||
utils.copyCookie('teddit', from, to, 'videos_muted')
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setTedditCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"redditProtocol",
|
||||
"disableReddit",
|
||||
"redditFrontend",
|
||||
"tedditNormalRedirectsChecks",
|
||||
"tedditNormalCustomRedirects",
|
||||
"tedditTorRedirectsChecks",
|
||||
"tedditTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableReddit || r.redditFrontend != 'teddit' || r.redditProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.redditProtocol == 'normal') checkedInstances = [...r.tedditNormalRedirectsChecks, ...r.tedditNormalCustomRedirects]
|
||||
else if (r.redditProtocol == 'tor') checkedInstances = [...r.tedditTorRedirectsChecks, ...r.tedditTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('teddit', to, 'collapse_child_comments')
|
||||
utils.getCookiesFromStorage('teddit', to, 'domain_instagram')
|
||||
utils.getCookiesFromStorage('teddit', to, 'domain_twitter')
|
||||
utils.getCookiesFromStorage('teddit', to, 'domain_youtube')
|
||||
utils.getCookiesFromStorage('teddit', to, 'flairs')
|
||||
utils.getCookiesFromStorage('teddit', to, 'highlight_controversial')
|
||||
utils.getCookiesFromStorage('teddit', to, 'nsfw_enabled')
|
||||
utils.getCookiesFromStorage('teddit', to, 'post_media_max_height')
|
||||
utils.getCookiesFromStorage('teddit', to, 'show_upvoted_percentage')
|
||||
utils.getCookiesFromStorage('teddit', to, 'show_upvotes')
|
||||
utils.getCookiesFromStorage('teddit', to, 'theme')
|
||||
utils.getCookiesFromStorage('teddit', to, 'videos_muted')
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableReddit || redditFrontend != 'teddit' || redditProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (redditProtocol == 'normal') checkedInstances = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects]
|
||||
else if (redditProtocol == 'tor') checkedInstances = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('teddit', to, 'collapse_child_comments')
|
||||
utils.getCookiesFromStorage('teddit', to, 'domain_instagram')
|
||||
utils.getCookiesFromStorage('teddit', to, 'domain_twitter')
|
||||
utils.getCookiesFromStorage('teddit', to, 'domain_youtube')
|
||||
utils.getCookiesFromStorage('teddit', to, 'flairs')
|
||||
utils.getCookiesFromStorage('teddit', to, 'highlight_controversial')
|
||||
utils.getCookiesFromStorage('teddit', to, 'nsfw_enabled')
|
||||
utils.getCookiesFromStorage('teddit', to, 'post_media_max_height')
|
||||
utils.getCookiesFromStorage('teddit', to, 'show_upvoted_percentage')
|
||||
utils.getCookiesFromStorage('teddit', to, 'show_upvotes')
|
||||
utils.getCookiesFromStorage('teddit', to, 'theme')
|
||||
utils.getCookiesFromStorage('teddit', to, 'videos_muted')
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...redditRedirects.libreddit.normal,
|
||||
...redditRedirects.libreddit.tor,
|
||||
...redditRedirects.teddit.normal,
|
||||
...redditRedirects.teddit.tor,
|
||||
...libredditNormalCustomRedirects,
|
||||
...libredditTorCustomRedirects,
|
||||
...tedditNormalCustomRedirects,
|
||||
...tedditTorCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4
|
||||
// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png
|
||||
|
||||
// https://teddit.net/vids/1mq8d0ma3yk81.mp4
|
||||
// https://teddit.net/pics/w:null_4v3t1vgvrzk81.png
|
||||
|
||||
|
||||
// redd.it/t5379n
|
||||
// https://v.redd.it/z08avb339n801/DASH_1_2_M
|
||||
// https://i.redd.it/bfkhs659tzk81.jpg
|
||||
function redirect(url, type, initiator) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableReddit",
|
||||
"redditFrontend",
|
||||
"redditRedirects",
|
||||
"redditProtocol",
|
||||
if (disableReddit) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB';
|
||||
const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/;
|
||||
if (type !== "main_frame" || url.pathname.match(bypassPaths)) return;
|
||||
|
||||
"libredditNormalRedirectsChecks",
|
||||
"libredditNormalCustomRedirects",
|
||||
"libredditTorRedirectsChecks",
|
||||
"libredditTorCustomRedirects",
|
||||
let libredditInstancesList;
|
||||
let tedditInstancesList;
|
||||
if (redditProtocol == 'normal') {
|
||||
libredditInstancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects];
|
||||
tedditInstancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects];
|
||||
} else if (redditProtocol == 'tor') {
|
||||
libredditInstancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects];
|
||||
tedditInstancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects];
|
||||
}
|
||||
|
||||
"tedditNormalRedirectsChecks",
|
||||
"tedditNormalCustomRedirects",
|
||||
"tedditTorRedirectsChecks",
|
||||
"tedditTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4
|
||||
// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png
|
||||
if (url.host === "i.redd.it") {
|
||||
if (redditFrontend == 'teddit') {
|
||||
if (tedditInstancesList.length === 0) return;
|
||||
let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList);
|
||||
return `${tedditRandomInstance}/pics/w:null_${url.pathname.substring(1)}${url.reddit}`;
|
||||
}
|
||||
if (redditFrontend == 'libreddit') {
|
||||
if (libredditInstancesList.length === 0) return;
|
||||
let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
return `${libredditRandomInstance}/img${url.pathname}${url.reddit}`
|
||||
}
|
||||
}
|
||||
else if (url.host === "redd.it") {
|
||||
if (redditFrontend == 'libreddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
||||
if (libredditInstancesList.length === 0) return;
|
||||
let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
// https://redd.it/foo => https://libredd.it/comments/foo
|
||||
return `${libredditRandomInstance}/comments${url.pathname}${url.reddit}`;
|
||||
}
|
||||
if (redditFrontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
||||
if (tedditInstancesList.length === 0) return;
|
||||
let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList);
|
||||
// https://redd.it/foo => https://teddit.net/comments/foo
|
||||
return `${tedditRandomInstance}/comments${url.pathname}${url.reddit}`
|
||||
}
|
||||
}
|
||||
else if (url.host === 'preview.redd.it') {
|
||||
if (redditFrontend == 'teddit') return;
|
||||
if (redditFrontend == 'libreddit') {
|
||||
if (libredditInstancesList.length === 0) return;
|
||||
const libredditRandomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
return `${libredditRandomInstance}/preview/pre${url.pathname}${url.reddit}`;
|
||||
}
|
||||
}
|
||||
|
||||
// https://teddit.net/vids/1mq8d0ma3yk81.mp4
|
||||
// https://teddit.net/pics/w:null_4v3t1vgvrzk81.png
|
||||
|
||||
|
||||
// redd.it/t5379n
|
||||
// https://v.redd.it/z08avb339n801/DASH_1_2_M
|
||||
// https://i.redd.it/bfkhs659tzk81.jpg
|
||||
|
||||
if (r.disableReddit) { resolve(); return; }
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; }
|
||||
|
||||
if (
|
||||
initiator &&
|
||||
[
|
||||
...r.redditRedirects.libreddit.normal,
|
||||
...r.redditRedirects.libreddit.tor,
|
||||
...r.redditRedirects.teddit.normal,
|
||||
...r.redditRedirects.teddit.tor,
|
||||
...r.libredditNormalCustomRedirects,
|
||||
...r.libredditTorCustomRedirects,
|
||||
...r.tedditNormalCustomRedirects,
|
||||
...r.tedditTorCustomRedirects,
|
||||
].includes(initiator.origin)
|
||||
) { resolve('BYPASSTAB'); return; }
|
||||
|
||||
const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/;
|
||||
if (type !== "main_frame" || url.pathname.match(bypassPaths)) { resolve(); return; }
|
||||
|
||||
let libredditInstancesList;
|
||||
let tedditInstancesList;
|
||||
if (r.redditProtocol == 'normal') {
|
||||
libredditInstancesList = [...r.libredditNormalRedirectsChecks, ...r.libredditNormalCustomRedirects];
|
||||
tedditInstancesList = [...r.tedditNormalRedirectsChecks, ...r.tedditNormalCustomRedirects];
|
||||
} else if (r.redditProtocol == 'tor') {
|
||||
libredditInstancesList = [...r.libredditTorRedirectsChecks, ...r.libredditTorCustomRedirects];
|
||||
tedditInstancesList = [...r.tedditTorRedirectsChecks, ...r.tedditTorCustomRedirects];
|
||||
}
|
||||
|
||||
if (url.host === "i.redd.it") {
|
||||
if (r.redditFrontend == 'teddit') {
|
||||
if (tedditInstancesList.length === 0) { resolve(); return; }
|
||||
let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList);
|
||||
resolve(`${tedditRandomInstance}/pics/w:null_${url.pathname.substring(1)}${url.reddit}`); return;
|
||||
}
|
||||
if (r.redditFrontend == 'libreddit') {
|
||||
if (libredditInstancesList.length === 0) { resolve(); return; }
|
||||
let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
resolve(`${libredditRandomInstance}/img${url.pathname}${url.reddit}`); return;
|
||||
}
|
||||
}
|
||||
else if (url.host === "redd.it") {
|
||||
if (r.redditFrontend == 'libreddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
||||
if (libredditInstancesList.length === 0) { resolve(); return; }
|
||||
let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
// https://redd.it/foo => https://libredd.it/comments/foo
|
||||
resolve(`${libredditRandomInstance}/comments${url.pathname}${url.reddit}`); return;
|
||||
}
|
||||
if (r.redditFrontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
||||
if (tedditInstancesList.length === 0) { resolve(); return; }
|
||||
let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList);
|
||||
// https://redd.it/foo => https://teddit.net/comments/foo
|
||||
resolve(`${tedditRandomInstance}/comments${url.pathname}${url.reddit}`); return;
|
||||
}
|
||||
}
|
||||
else if (url.host === 'preview.redd.it') {
|
||||
if (r.redditFrontend == 'teddit') {
|
||||
{ resolve(); return; }
|
||||
}
|
||||
if (r.redditFrontend == 'libreddit') {
|
||||
if (libredditInstancesList.length === 0) { resolve(); return; }
|
||||
let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
resolve(`${libredditRandomInstance}/preview/pre${url.pathname}${url.reddit}`); return;
|
||||
}
|
||||
}
|
||||
|
||||
let randomInstance;
|
||||
if (r.redditFrontend == 'libreddit') {
|
||||
if (libredditInstancesList.length === 0) { resolve(); return; }
|
||||
randomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
}
|
||||
if (r.redditFrontend == 'teddit') {
|
||||
if (tedditInstancesList.length === 0) { resolve(); return; }
|
||||
randomInstance = utils.getRandomInstance(tedditInstancesList);
|
||||
}
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function reverse(url) {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![...redirects.nitter.normal,
|
||||
...redirects.nitter.tor,
|
||||
...nitterNormalCustomRedirects,
|
||||
...nitterTorCustomRedirects].includes(protocolHost)
|
||||
) return;
|
||||
if (url.pathname.includes('/pics/w:null_'))
|
||||
return `https://reddit.com${url.pathname}${url.reddit}`;
|
||||
let randomInstance;
|
||||
if (redditFrontend == 'libreddit') {
|
||||
if (libredditInstancesList.length === 0) return;
|
||||
randomInstance = utils.getRandomInstance(libredditInstancesList);
|
||||
}
|
||||
if (redditFrontend == 'teddit') {
|
||||
if (tedditInstancesList.length === 0) return;
|
||||
randomInstance = utils.getRandomInstance(tedditInstancesList);
|
||||
}
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"redditRedirects",
|
||||
"redditFrontend",
|
||||
"redditProtocol",
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
let instancesList;
|
||||
if (redditFrontend == 'libreddit') {
|
||||
if (redditProtocol == 'normal') instancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects];
|
||||
else if (redditProtocol == 'tor') instancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects];
|
||||
if ([
|
||||
...redditRedirects.teddit.normal,
|
||||
...redditRedirects.teddit.tor
|
||||
].includes(protocolHost)) url.pathname = url.pathname.replace("/pics/w:null_", "/img/");
|
||||
}
|
||||
else if (redditFrontend == 'teddit') {
|
||||
if (redditProtocol == 'normal') instancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects];
|
||||
else if (redditProtocol == 'tor') instancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects];
|
||||
if ([
|
||||
...redditRedirects.libreddit.normal,
|
||||
...redditRedirects.libreddit.tor
|
||||
].includes(protocolHost)
|
||||
) url.pathname = url.pathname.replace("/img/", "/pics/w:null_");
|
||||
}
|
||||
|
||||
"libredditNormalRedirectsChecks",
|
||||
"libredditNormalCustomRedirects",
|
||||
"libredditTorRedirectsChecks",
|
||||
"libredditTorCustomRedirects",
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
"tedditNormalRedirectsChecks",
|
||||
"tedditNormalCustomRedirects",
|
||||
"tedditTorRedirectsChecks",
|
||||
"tedditTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.redditRedirects.libreddit.normal,
|
||||
...r.redditRedirects.libreddit.tor,
|
||||
|
||||
...r.libredditNormalCustomRedirects,
|
||||
...r.libredditTorCustomRedirects,
|
||||
|
||||
...r.redditRedirects.teddit.normal,
|
||||
...r.redditRedirects.teddit.tor,
|
||||
|
||||
...r.tedditNormalCustomRedirects,
|
||||
...r.tedditTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.redditFrontend == 'libreddit') {
|
||||
if (r.redditProtocol == 'normal') instancesList = [...r.libredditNormalRedirectsChecks, ...r.libredditNormalCustomRedirects];
|
||||
else if (r.redditProtocol == 'tor') instancesList = [...r.libredditTorRedirectsChecks, ...r.libredditTorCustomRedirects];
|
||||
if ([
|
||||
...r.redditRedirects.teddit.normal,
|
||||
...r.redditRedirects.teddit.tor
|
||||
].includes(protocolHost)) url.pathname = url.pathname.replace("/pics/w:null_", "/img/");
|
||||
}
|
||||
else if (r.redditFrontend == 'teddit') {
|
||||
if (r.redditProtocol == 'normal') instancesList = [...r.tedditNormalRedirectsChecks, ...r.tedditNormalCustomRedirects];
|
||||
else if (r.redditProtocol == 'tor') instancesList = [...r.tedditTorRedirectsChecks, ...r.tedditTorCustomRedirects];
|
||||
if ([
|
||||
...r.redditRedirects.libreddit.normal,
|
||||
...r.redditRedirects.libreddit.tor
|
||||
].includes(protocolHost)
|
||||
) url.pathname = url.pathname.replace("/img/", "/pics/w:null_");
|
||||
}
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.reddit}`)
|
||||
}
|
||||
)
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.reddit}`);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,10 @@ import utils from './utils.js'
|
||||
const targets = [
|
||||
/^https?:\/{2}(www\.|search\.|)google(\.[a-z]{2,3}){1,2}(\/search(\?.*|$)|\/$)/,
|
||||
/^https?:\/{2}(www\.|www2\.|)bing\.com/,
|
||||
|
||||
/^https?:\/{2}yandex(\.[a-z]{2,3}){1,2}/,
|
||||
|
||||
/^https?:\/{2}search\.libredirect\.invalid/,
|
||||
];
|
||||
|
||||
let redirects = {
|
||||
"searx": {
|
||||
"normal": [],
|
||||
@ -54,388 +53,344 @@ function setRedirects(val) {
|
||||
}
|
||||
|
||||
let
|
||||
disableSearch,
|
||||
searchFrontend,
|
||||
searchRedirects,
|
||||
searchProtocol,
|
||||
whoogleNormalRedirectsChecks,
|
||||
whoogleNormalCustomRedirects,
|
||||
whoogleTorRedirectsChecks,
|
||||
whoogleTorCustomRedirects,
|
||||
whoogleI2pRedirectsChecks,
|
||||
whoogleI2pCustomRedirects,
|
||||
searxNormalRedirectsChecks,
|
||||
searxNormalCustomRedirects,
|
||||
searxTorRedirectsChecks,
|
||||
searxTorCustomRedirects,
|
||||
searxI2pRedirectsChecks,
|
||||
searxI2pCustomRedirects,
|
||||
searxngNormalRedirectsChecks,
|
||||
whoogleNormalRedirectsChecks;
|
||||
searxngNormalCustomRedirects,
|
||||
searxngTorRedirectsChecks,
|
||||
searxngTorCustomRedirects,
|
||||
searxngI2pRedirectsChecks,
|
||||
searxngI2pCustomRedirects;
|
||||
|
||||
function initSearxCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
function init() {
|
||||
return new Promise(async resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableSearch",
|
||||
"searchFrontend",
|
||||
"searchRedirects",
|
||||
"searchProtocol",
|
||||
"whoogleNormalRedirectsChecks",
|
||||
"whoogleNormalCustomRedirects",
|
||||
"whoogleTorRedirectsChecks",
|
||||
"whoogleTorCustomRedirects",
|
||||
"whoogleI2pRedirectsChecks",
|
||||
"whoogleI2pCustomRedirects",
|
||||
"searxNormalRedirectsChecks",
|
||||
"searxNormalCustomRedirects",
|
||||
"searxTorRedirectsChecks",
|
||||
"searxTorCustomRedirects",
|
||||
"searxI2pRedirectsChecks",
|
||||
"searxI2pCustomRedirects",
|
||||
"searxngNormalRedirectsChecks",
|
||||
"searxngNormalCustomRedirects",
|
||||
"searxngTorRedirectsChecks",
|
||||
"searxngTorCustomRedirects",
|
||||
"searxngI2pRedirectsChecks",
|
||||
"searxngI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.searxNormalRedirectsChecks,
|
||||
...r.searxNormalCustomRedirects,
|
||||
...r.searxTorRedirectsChecks,
|
||||
...r.searxTorCustomRedirects,
|
||||
...r.searxI2pRedirectsChecks,
|
||||
...r.searxI2pCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.searchProtocol == 'normal') checkedInstances = [...r.searxNormalRedirectsChecks, ...r.searxNormalCustomRedirects];
|
||||
else if (r.searchProtocol == 'tor') checkedInstances = [...r.searxTorRedirectsChecks, ...r.searxTorCustomRedirects];
|
||||
else if (r.searchProtocol == 'i2p') checkedInstances = [...r.searxI2pRedirectsChecks, ...r.searxI2pCustomRedirects];
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('searx', from, to, 'advanced_search');
|
||||
utils.copyCookie('searx', from, to, 'autocomplete');
|
||||
utils.copyCookie('searx', from, to, 'categories');
|
||||
utils.copyCookie('searx', from, to, 'disabled_engines');
|
||||
utils.copyCookie('searx', from, to, 'disabled_plugins');
|
||||
utils.copyCookie('searx', from, to, 'doi_resolver');
|
||||
utils.copyCookie('searx', from, to, 'enabled_engines');
|
||||
utils.copyCookie('searx', from, to, 'enabled_plugins');
|
||||
utils.copyCookie('searx', from, to, 'image_proxy');
|
||||
utils.copyCookie('searx', from, to, 'language');
|
||||
utils.copyCookie('searx', from, to, 'locale');
|
||||
utils.copyCookie('searx', from, to, 'method');
|
||||
utils.copyCookie('searx', from, to, 'oscar-style');
|
||||
utils.copyCookie('searx', from, to, 'results_on_new_tab');
|
||||
utils.copyCookie('searx', from, to, 'safesearch');
|
||||
utils.copyCookie('searx', from, to, 'theme');
|
||||
utils.copyCookie('searx', from, to, 'tokens');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
disableSearch = r.disableSearch;
|
||||
searchFrontend = r.searchFrontend;
|
||||
searchRedirects = r.searchRedirects;
|
||||
searchProtocol = r.searchProtocol;
|
||||
whoogleNormalRedirectsChecks = r.whoogleNormalRedirectsChecks;
|
||||
whoogleNormalCustomRedirects = r.whoogleNormalCustomRedirects;
|
||||
whoogleTorRedirectsChecks = r.whoogleTorRedirectsChecks;
|
||||
whoogleTorCustomRedirects = r.whoogleTorCustomRedirects;
|
||||
whoogleI2pRedirectsChecks = r.whoogleI2pRedirectsChecks;
|
||||
whoogleI2pCustomRedirects = r.whoogleI2pCustomRedirects;
|
||||
searxNormalRedirectsChecks = r.searxNormalRedirectsChecks;
|
||||
searxNormalCustomRedirects = r.searxNormalCustomRedirects;
|
||||
searxTorRedirectsChecks = r.searxTorRedirectsChecks;
|
||||
searxTorCustomRedirects = r.searxTorCustomRedirects;
|
||||
searxI2pRedirectsChecks = r.searxI2pRedirectsChecks;
|
||||
searxI2pCustomRedirects = r.searxI2pCustomRedirects;
|
||||
searxngNormalRedirectsChecks = r.searxngNormalRedirectsChecks;
|
||||
searxngNormalCustomRedirects = r.searxngNormalCustomRedirects;
|
||||
searxngTorRedirectsChecks = r.searxngTorRedirectsChecks;
|
||||
searxngTorCustomRedirects = r.searxngTorCustomRedirects;
|
||||
searxngI2pRedirectsChecks = r.searxngI2pRedirectsChecks;
|
||||
searxngI2pCustomRedirects = r.searxngI2pCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function initSearxCookies(test, from) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...searxNormalRedirectsChecks,
|
||||
...searxNormalCustomRedirects,
|
||||
...searxTorRedirectsChecks,
|
||||
...searxTorCustomRedirects,
|
||||
...searxI2pRedirectsChecks,
|
||||
...searxI2pCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (searchProtocol == 'normal') checkedInstances = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects];
|
||||
else if (searchProtocol == 'tor') checkedInstances = [...searxTorRedirectsChecks, ...searxTorCustomRedirects];
|
||||
else if (searchProtocol == 'i2p') checkedInstances = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects];
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('searx', from, to, 'advanced_search');
|
||||
utils.copyCookie('searx', from, to, 'autocomplete');
|
||||
utils.copyCookie('searx', from, to, 'categories');
|
||||
utils.copyCookie('searx', from, to, 'disabled_engines');
|
||||
utils.copyCookie('searx', from, to, 'disabled_plugins');
|
||||
utils.copyCookie('searx', from, to, 'doi_resolver');
|
||||
utils.copyCookie('searx', from, to, 'enabled_engines');
|
||||
utils.copyCookie('searx', from, to, 'enabled_plugins');
|
||||
utils.copyCookie('searx', from, to, 'image_proxy');
|
||||
utils.copyCookie('searx', from, to, 'language');
|
||||
utils.copyCookie('searx', from, to, 'locale');
|
||||
utils.copyCookie('searx', from, to, 'method');
|
||||
utils.copyCookie('searx', from, to, 'oscar-style');
|
||||
utils.copyCookie('searx', from, to, 'results_on_new_tab');
|
||||
utils.copyCookie('searx', from, to, 'safesearch');
|
||||
utils.copyCookie('searx', from, to, 'theme');
|
||||
utils.copyCookie('searx', from, to, 'tokens');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setSearxCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableSearch",
|
||||
"searchProtocol",
|
||||
"searchFrontend",
|
||||
"searxNormalRedirectsChecks",
|
||||
"searxNormalCustomRedirects",
|
||||
"searxTorRedirectsChecks",
|
||||
"searxTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableSearch || r.searchFrontend != 'searx') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.searchProtocol == 'normal') checkedInstances = [...r.searxNormalRedirectsChecks, ...r.searxNormalCustomRedirects]
|
||||
else if (r.searchProtocol == 'tor') checkedInstances = [...r.searxTorRedirectsChecks, ...r.searxTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('searx', to, 'advanced_search');
|
||||
utils.getCookiesFromStorage('searx', to, 'autocomplete');
|
||||
utils.getCookiesFromStorage('searx', to, 'categories');
|
||||
utils.getCookiesFromStorage('searx', to, 'disabled_engines');
|
||||
utils.getCookiesFromStorage('searx', to, 'disabled_plugins');
|
||||
utils.getCookiesFromStorage('searx', to, 'doi_resolver');
|
||||
utils.getCookiesFromStorage('searx', to, 'enabled_engines');
|
||||
utils.getCookiesFromStorage('searx', to, 'enabled_plugins');
|
||||
utils.getCookiesFromStorage('searx', to, 'image_proxy');
|
||||
utils.getCookiesFromStorage('searx', to, 'language');
|
||||
utils.getCookiesFromStorage('searx', to, 'locale');
|
||||
utils.getCookiesFromStorage('searx', to, 'method');
|
||||
utils.getCookiesFromStorage('searx', to, 'oscar-style');
|
||||
utils.getCookiesFromStorage('searx', to, 'results_on_new_tab');
|
||||
utils.getCookiesFromStorage('searx', to, 'safesearch');
|
||||
utils.getCookiesFromStorage('searx', to, 'theme');
|
||||
utils.getCookiesFromStorage('searx', to, 'tokens');
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableSearch || searchFrontend != 'searx') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (searchProtocol == 'normal') checkedInstances = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]
|
||||
else if (searchProtocol == 'tor') checkedInstances = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('searx', to, 'advanced_search');
|
||||
utils.getCookiesFromStorage('searx', to, 'autocomplete');
|
||||
utils.getCookiesFromStorage('searx', to, 'categories');
|
||||
utils.getCookiesFromStorage('searx', to, 'disabled_engines');
|
||||
utils.getCookiesFromStorage('searx', to, 'disabled_plugins');
|
||||
utils.getCookiesFromStorage('searx', to, 'doi_resolver');
|
||||
utils.getCookiesFromStorage('searx', to, 'enabled_engines');
|
||||
utils.getCookiesFromStorage('searx', to, 'enabled_plugins');
|
||||
utils.getCookiesFromStorage('searx', to, 'image_proxy');
|
||||
utils.getCookiesFromStorage('searx', to, 'language');
|
||||
utils.getCookiesFromStorage('searx', to, 'locale');
|
||||
utils.getCookiesFromStorage('searx', to, 'method');
|
||||
utils.getCookiesFromStorage('searx', to, 'oscar-style');
|
||||
utils.getCookiesFromStorage('searx', to, 'results_on_new_tab');
|
||||
utils.getCookiesFromStorage('searx', to, 'safesearch');
|
||||
utils.getCookiesFromStorage('searx', to, 'theme');
|
||||
utils.getCookiesFromStorage('searx', to, 'tokens');
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
function initSearxngCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"searchProtocol",
|
||||
"searxngNormalRedirectsChecks",
|
||||
"searxngNormalCustomRedirects",
|
||||
"searxngTorRedirectsChecks",
|
||||
"searxngTorCustomRedirects",
|
||||
"searxngI2pRedirectsChecks",
|
||||
"searxngI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.searxngNormalRedirectsChecks,
|
||||
...r.searxngNormalCustomRedirects,
|
||||
...r.searxngTorRedirectsChecks,
|
||||
...r.searxngTorCustomRedirects,
|
||||
...r.searxngI2pRedirectsChecks,
|
||||
...r.searxngI2pCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...searxngNormalRedirectsChecks,
|
||||
...searxngNormalCustomRedirects,
|
||||
...searxngTorRedirectsChecks,
|
||||
...searxngTorCustomRedirects,
|
||||
...searxngI2pRedirectsChecks,
|
||||
...searxngI2pCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.searchProtocol == 'normal') checkedInstances = [...r.searxngNormalRedirectsChecks, ...r.searxngNormalCustomRedirects];
|
||||
else if (r.searchProtocol == 'tor') checkedInstances = [...r.searxngTorRedirectsChecks, ...r.searxngTorCustomRedirects];
|
||||
else if (r.searchProtocol == 'i2p') checkedInstances = [...r.searxngI2pRedirectsChecks, ...r.searxngI2pCustomRedirects];
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('searxng', from, to, 'autocomplete');
|
||||
utils.copyCookie('searxng', from, to, 'categories');
|
||||
utils.copyCookie('searxng', from, to, 'disabled_engines');
|
||||
utils.copyCookie('searxng', from, to, 'disabled_plugins');
|
||||
utils.copyCookie('searxng', from, to, 'doi_resolver');
|
||||
utils.copyCookie('searxng', from, to, 'enabled_plugins');
|
||||
utils.copyCookie('searxng', from, to, 'enabled_engines');
|
||||
utils.copyCookie('searxng', from, to, 'image_proxy');
|
||||
utils.copyCookie('searxng', from, to, 'infinite_scroll');
|
||||
utils.copyCookie('searxng', from, to, 'language');
|
||||
utils.copyCookie('searxng', from, to, 'locale');
|
||||
utils.copyCookie('searxng', from, to, 'maintab');
|
||||
utils.copyCookie('searxng', from, to, 'method');
|
||||
utils.copyCookie('searxng', from, to, 'query_in_title');
|
||||
utils.copyCookie('searxng', from, to, 'results_on_new_tab');
|
||||
utils.copyCookie('searxng', from, to, 'safesearch');
|
||||
utils.copyCookie('searxng', from, to, 'simple_style');
|
||||
utils.copyCookie('searxng', from, to, 'theme');
|
||||
utils.copyCookie('searxng', from, to, 'tokens');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (searchProtocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
|
||||
else if (searchProtocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
|
||||
else if (searchProtocol == 'i2p') checkedInstances = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects];
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('searxng', from, to, 'autocomplete');
|
||||
utils.copyCookie('searxng', from, to, 'categories');
|
||||
utils.copyCookie('searxng', from, to, 'disabled_engines');
|
||||
utils.copyCookie('searxng', from, to, 'disabled_plugins');
|
||||
utils.copyCookie('searxng', from, to, 'doi_resolver');
|
||||
utils.copyCookie('searxng', from, to, 'enabled_plugins');
|
||||
utils.copyCookie('searxng', from, to, 'enabled_engines');
|
||||
utils.copyCookie('searxng', from, to, 'image_proxy');
|
||||
utils.copyCookie('searxng', from, to, 'infinite_scroll');
|
||||
utils.copyCookie('searxng', from, to, 'language');
|
||||
utils.copyCookie('searxng', from, to, 'locale');
|
||||
utils.copyCookie('searxng', from, to, 'maintab');
|
||||
utils.copyCookie('searxng', from, to, 'method');
|
||||
utils.copyCookie('searxng', from, to, 'query_in_title');
|
||||
utils.copyCookie('searxng', from, to, 'results_on_new_tab');
|
||||
utils.copyCookie('searxng', from, to, 'safesearch');
|
||||
utils.copyCookie('searxng', from, to, 'simple_style');
|
||||
utils.copyCookie('searxng', from, to, 'theme');
|
||||
utils.copyCookie('searxng', from, to, 'tokens');
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setSearxngCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"searchProtocol",
|
||||
"disableSearch",
|
||||
"searchFrontend",
|
||||
"searxngNormalRedirectsChecks",
|
||||
"searxngNormalCustomRedirects",
|
||||
"searxngTorRedirectsChecks",
|
||||
"searxngTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableSearch || r.searchFrontend != 'searxng', r.searchProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.searchProtocol == 'normal') checkedInstances = [...r.searxngNormalRedirectsChecks, ...r.searxngNormalCustomRedirects]
|
||||
else if (r.searchProtocol == 'tor') checkedInstances = [...r.searxngTorRedirectsChecks, ...r.searxngTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('searxng', to, 'autocomplete');
|
||||
utils.getCookiesFromStorage('searxng', to, 'categories');
|
||||
utils.getCookiesFromStorage('searxng', to, 'disabled_engines');
|
||||
utils.getCookiesFromStorage('searxng', to, 'disabled_plugins');
|
||||
utils.getCookiesFromStorage('searxng', to, 'doi_resolver');
|
||||
utils.getCookiesFromStorage('searxng', to, 'enabled_plugins');
|
||||
utils.getCookiesFromStorage('searxng', to, 'enabled_engines');
|
||||
utils.getCookiesFromStorage('searxng', to, 'image_proxy');
|
||||
utils.getCookiesFromStorage('searxng', to, 'infinite_scroll');
|
||||
utils.getCookiesFromStorage('searxng', to, 'language');
|
||||
utils.getCookiesFromStorage('searxng', to, 'locale');
|
||||
utils.getCookiesFromStorage('searxng', to, 'maintab');
|
||||
utils.getCookiesFromStorage('searxng', to, 'method');
|
||||
utils.getCookiesFromStorage('searxng', to, 'query_in_title');
|
||||
utils.getCookiesFromStorage('searxng', to, 'results_on_new_tab');
|
||||
utils.getCookiesFromStorage('searxng', to, 'safesearch');
|
||||
utils.getCookiesFromStorage('searxng', to, 'simple_style');
|
||||
utils.getCookiesFromStorage('searxng', to, 'theme');
|
||||
utils.getCookiesFromStorage('searxng', to, 'tokens');
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableSearch || searchFrontend != 'searxng', searchProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (searchProtocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]
|
||||
else if (searchProtocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('searxng', to, 'autocomplete');
|
||||
utils.getCookiesFromStorage('searxng', to, 'categories');
|
||||
utils.getCookiesFromStorage('searxng', to, 'disabled_engines');
|
||||
utils.getCookiesFromStorage('searxng', to, 'disabled_plugins');
|
||||
utils.getCookiesFromStorage('searxng', to, 'doi_resolver');
|
||||
utils.getCookiesFromStorage('searxng', to, 'enabled_plugins');
|
||||
utils.getCookiesFromStorage('searxng', to, 'enabled_engines');
|
||||
utils.getCookiesFromStorage('searxng', to, 'image_proxy');
|
||||
utils.getCookiesFromStorage('searxng', to, 'infinite_scroll');
|
||||
utils.getCookiesFromStorage('searxng', to, 'language');
|
||||
utils.getCookiesFromStorage('searxng', to, 'locale');
|
||||
utils.getCookiesFromStorage('searxng', to, 'maintab');
|
||||
utils.getCookiesFromStorage('searxng', to, 'method');
|
||||
utils.getCookiesFromStorage('searxng', to, 'query_in_title');
|
||||
utils.getCookiesFromStorage('searxng', to, 'results_on_new_tab');
|
||||
utils.getCookiesFromStorage('searxng', to, 'safesearch');
|
||||
utils.getCookiesFromStorage('searxng', to, 'simple_style');
|
||||
utils.getCookiesFromStorage('searxng', to, 'theme');
|
||||
utils.getCookiesFromStorage('searxng', to, 'tokens');
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function redirect(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableSearch",
|
||||
"searchFrontend",
|
||||
"searchRedirects",
|
||||
"searchProtocol",
|
||||
if (disableSearch) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
if (url.searchParams.has('tbm')) return;
|
||||
if (url.hostname.includes('google') && !url.searchParams.has('q') && url.pathname != '/') return;
|
||||
let randomInstance;
|
||||
let path;
|
||||
if (searchFrontend == 'searx') {
|
||||
let instancesList;
|
||||
if (searchProtocol == 'normal') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects];
|
||||
else if (searchProtocol == 'tor') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects];
|
||||
else if (searchProtocol == 'i2p') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
randomInstance = utils.getRandomInstance(instancesList)
|
||||
path = "/";
|
||||
}
|
||||
else if (searchFrontend == 'searxng') {
|
||||
let instancesList;
|
||||
if (searchProtocol == 'normal') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
|
||||
else if (searchProtocol == 'tor') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
|
||||
else if (searchProtocol == 'i2p') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
randomInstance = utils.getRandomInstance(instancesList)
|
||||
path = "/";
|
||||
}
|
||||
else if (searchFrontend == 'whoogle') {
|
||||
let instancesList;
|
||||
if (searchProtocol == 'normal') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects];
|
||||
if (searchProtocol == 'tor') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects];
|
||||
if (searchProtocol == 'i2p') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
randomInstance = utils.getRandomInstance(instancesList)
|
||||
path = "/search";
|
||||
}
|
||||
|
||||
"whoogleNormalRedirectsChecks",
|
||||
"whoogleNormalCustomRedirects",
|
||||
if (
|
||||
((url.hostname.includes('google') || url.hostname.includes('bing')) && !url.searchParams.has('q')) ||
|
||||
(url.hostname.includes('yandex') && !url.searchParams.has('text'))
|
||||
) path = '/';
|
||||
|
||||
"whoogleTorRedirectsChecks",
|
||||
"whoogleTorCustomRedirects",
|
||||
let searchQuery = "";
|
||||
if (
|
||||
(
|
||||
url.hostname.includes('google') ||
|
||||
url.hostname.includes('bing') ||
|
||||
url.hostname.includes('search.libredirect.invalid')
|
||||
) &&
|
||||
url.searchParams.has('q')
|
||||
) searchQuery = `?q=${url.searchParams.get('q')}`;
|
||||
if (url.hostname.includes('yandex') && url.searchParams.has('text')) searchQuery = `?q=${url.searchParams.get('text')}`;
|
||||
|
||||
"whoogleI2pRedirectsChecks",
|
||||
"whoogleI2pCustomRedirects",
|
||||
|
||||
"searxNormalRedirectsChecks",
|
||||
"searxNormalCustomRedirects",
|
||||
|
||||
"searxTorRedirectsChecks",
|
||||
"searxTorCustomRedirects",
|
||||
|
||||
"searxI2pRedirectsChecks",
|
||||
"searxI2pCustomRedirects",
|
||||
|
||||
"searxngNormalRedirectsChecks",
|
||||
"searxngNormalCustomRedirects",
|
||||
|
||||
"searxngTorRedirectsChecks",
|
||||
"searxngTorCustomRedirects",
|
||||
|
||||
"searxngI2pRedirectsChecks",
|
||||
"searxngI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableSearch) { resolve(); return; }
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; }
|
||||
if (url.searchParams.has('tbm')) { resolve(); return; }
|
||||
if (url.hostname.includes('google') && !url.searchParams.has('q') && url.pathname != '/') { resolve(); return; }
|
||||
let randomInstance;
|
||||
let path;
|
||||
if (r.searchFrontend == 'searx') {
|
||||
let instancesList;
|
||||
if (r.searchProtocol == 'normal') instancesList = [...r.searxNormalRedirectsChecks, ...r.searxNormalCustomRedirects];
|
||||
else if (r.searchProtocol == 'tor') instancesList = [...r.searxTorRedirectsChecks, ...r.searxTorCustomRedirects];
|
||||
else if (r.searchProtocol == 'i2p') instancesList = [...r.searxI2pRedirectsChecks, ...r.searxI2pCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
randomInstance = utils.getRandomInstance(instancesList)
|
||||
path = "/";
|
||||
}
|
||||
else if (r.searchFrontend == 'searxng') {
|
||||
let instancesList;
|
||||
if (r.searchProtocol == 'normal') instancesList = [...r.searxngNormalRedirectsChecks, ...r.searxngNormalCustomRedirects];
|
||||
else if (r.searchProtocol == 'tor') instancesList = [...r.searxngTorRedirectsChecks, ...r.searxngTorCustomRedirects];
|
||||
else if (r.searchProtocol == 'i2p') instancesList = [...r.searxngI2pRedirectsChecks, ...r.searxngI2pCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
randomInstance = utils.getRandomInstance(instancesList)
|
||||
path = "/";
|
||||
}
|
||||
else if (r.searchFrontend == 'whoogle') {
|
||||
let instancesList;
|
||||
if (r.searchProtocol == 'normal') instancesList = [...r.whoogleNormalRedirectsChecks, ...r.whoogleNormalCustomRedirects];
|
||||
if (r.searchProtocol == 'tor') instancesList = [...r.whoogleTorRedirectsChecks, ...r.whoogleTorCustomRedirects];
|
||||
if (r.searchProtocol == 'i2p') instancesList = [...r.whoogleI2pRedirectsChecks, ...r.whoogleI2pCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
randomInstance = utils.getRandomInstance(instancesList)
|
||||
path = "/search";
|
||||
}
|
||||
|
||||
if (
|
||||
((url.hostname.includes('google') || url.hostname.includes('bing')) && !url.searchParams.has('q')) ||
|
||||
(url.hostname.includes('yandex') && !url.searchParams.has('text'))
|
||||
) path = '/';
|
||||
|
||||
let searchQuery = "";
|
||||
if (
|
||||
(
|
||||
url.hostname.includes('google') ||
|
||||
url.hostname.includes('bing') ||
|
||||
url.hostname.includes('search.libredirect.invalid')
|
||||
) &&
|
||||
url.searchParams.has('q')
|
||||
) searchQuery = `?q=${url.searchParams.get('q')}`;
|
||||
if (url.hostname.includes('yandex') && url.searchParams.has('text')) searchQuery = `?q=${url.searchParams.get('text')}`;
|
||||
|
||||
resolve(`${randomInstance}${path}${searchQuery}`);
|
||||
})
|
||||
})
|
||||
return `${randomInstance}${path}${searchQuery}`;
|
||||
}
|
||||
|
||||
async function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"searchFrontend",
|
||||
"searchRedirects",
|
||||
"searchProtocol",
|
||||
function switchInstance(url) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...searchRedirects.searx.normal,
|
||||
...searchRedirects.searx.tor,
|
||||
...searchRedirects.searx.i2p,
|
||||
|
||||
"whoogleNormalRedirectsChecks",
|
||||
"whoogleNormalCustomRedirects",
|
||||
...searchRedirects.searxng.normal,
|
||||
...searchRedirects.searxng.tor,
|
||||
...searchRedirects.searxng.i2p,
|
||||
|
||||
"whoogleTorRedirectsChecks",
|
||||
"whoogleTorCustomRedirects",
|
||||
...searchRedirects.whoogle.normal,
|
||||
...searchRedirects.whoogle.tor,
|
||||
...searchRedirects.whoogle.i2p,
|
||||
|
||||
"whoogleI2pRedirectsChecks",
|
||||
"whoogleI2pCustomRedirects",
|
||||
...searxNormalCustomRedirects,
|
||||
...searxTorCustomRedirects,
|
||||
...searxI2pCustomRedirects,
|
||||
|
||||
"searxNormalRedirectsChecks",
|
||||
"searxNormalCustomRedirects",
|
||||
...searxngNormalCustomRedirects,
|
||||
...searxngTorCustomRedirects,
|
||||
...searxngI2pCustomRedirects,
|
||||
|
||||
"searxTorRedirectsChecks",
|
||||
"searxTorCustomRedirects",
|
||||
...whoogleNormalCustomRedirects,
|
||||
...whoogleTorCustomRedirects,
|
||||
...whoogleI2pCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
"searxI2pRedirectsChecks",
|
||||
"searxI2pCustomRedirects",
|
||||
let instancesList;
|
||||
if (searchProtocol == 'normal') {
|
||||
if (searchFrontend == 'searx') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects];
|
||||
else if (searchFrontend == 'searxng') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects];
|
||||
else if (searchFrontend == 'whoogle') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects];
|
||||
}
|
||||
else if (searchProtocol == 'tor') {
|
||||
if (searchFrontend == 'searx') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects];
|
||||
else if (searchFrontend == 'searxng') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects];
|
||||
else if (searchFrontend == 'whoogle') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects];
|
||||
}
|
||||
else if (searchProtocol == 'i2p') {
|
||||
if (searchFrontend == 'searx') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects];
|
||||
else if (searchFrontend == 'searxng') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects];
|
||||
else if (searchFrontend == 'whoogle') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects];
|
||||
}
|
||||
|
||||
"searxngNormalRedirectsChecks",
|
||||
"searxngNormalCustomRedirects",
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
"searxngTorRedirectsChecks",
|
||||
"searxngTorCustomRedirects",
|
||||
|
||||
"searxngI2pRedirectsChecks",
|
||||
"searxngI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.searchRedirects.searx.normal,
|
||||
...r.searchRedirects.searx.tor,
|
||||
...r.searchRedirects.searx.i2p,
|
||||
|
||||
...r.searchRedirects.searxng.normal,
|
||||
...r.searchRedirects.searxng.tor,
|
||||
...r.searchRedirects.searxng.i2p,
|
||||
|
||||
...r.searchRedirects.whoogle.normal,
|
||||
...r.searchRedirects.whoogle.tor,
|
||||
...r.searchRedirects.whoogle.i2p,
|
||||
|
||||
...r.searxNormalCustomRedirects,
|
||||
...r.searxTorCustomRedirects,
|
||||
...r.searxI2pCustomRedirects,
|
||||
|
||||
...r.searxngNormalCustomRedirects,
|
||||
...r.searxngTorCustomRedirects,
|
||||
...r.searxngI2pCustomRedirects,
|
||||
|
||||
...r.whoogleNormalCustomRedirects,
|
||||
...r.whoogleTorCustomRedirects,
|
||||
...r.whoogleI2pCustomRedirects,
|
||||
].includes(protocolHost)) {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
let instancesList;
|
||||
if (r.searchProtocol == 'normal') {
|
||||
if (r.searchFrontend == 'searx') instancesList = [...r.searxNormalRedirectsChecks, ...r.searxNormalCustomRedirects];
|
||||
else if (r.searchFrontend == 'searxng') instancesList = [...r.searxngNormalRedirectsChecks, ...r.searxngNormalCustomRedirects];
|
||||
else if (r.searchFrontend == 'whoogle') instancesList = [...r.whoogleNormalRedirectsChecks, ...r.whoogleNormalCustomRedirects];
|
||||
}
|
||||
else if (r.searchProtocol == 'tor') {
|
||||
if (r.searchFrontend == 'searx') instancesList = [...r.searxTorRedirectsChecks, ...r.searxTorCustomRedirects];
|
||||
else if (r.searchFrontend == 'searxng') instancesList = [...r.searxngTorRedirectsChecks, ...r.searxngTorCustomRedirects];
|
||||
else if (r.searchFrontend == 'whoogle') instancesList = [...r.whoogleTorRedirectsChecks, ...r.whoogleTorCustomRedirects];
|
||||
}
|
||||
else if (r.searchProtocol == 'i2p') {
|
||||
if (r.searchFrontend == 'searx') instancesList = [...r.searxI2pRedirectsChecks, ...r.searxI2pCustomRedirects];
|
||||
else if (r.searchFrontend == 'searxng') instancesList = [...r.searxngI2pRedirectsChecks, ...r.searxngI2pCustomRedirects];
|
||||
else if (r.searchFrontend == 'whoogle') instancesList = [...r.whoogleI2pRedirectsChecks, ...r.whoogleI2pCustomRedirects];
|
||||
}
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) resolve();
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
@ -505,13 +460,10 @@ function initDefaults() {
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
|
||||
initSearxCookies,
|
||||
setSearxCookies,
|
||||
|
||||
initSearxngCookies,
|
||||
setSearxngCookies,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
switchInstance,
|
||||
|
@ -29,91 +29,88 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
let sendNormalRedirectsChecks;
|
||||
let
|
||||
disableSendTarget,
|
||||
sendTargetsRedirects,
|
||||
sendNormalRedirectsChecks,
|
||||
sendNormalCustomRedirects,
|
||||
sendTorRedirectsChecks,
|
||||
sendTorCustomRedirects,
|
||||
sendTargetsProtocol;
|
||||
|
||||
function switchInstance(url) {
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableSendTarget",
|
||||
"sendTargetsRedirects",
|
||||
"sendTargetsProtocol",
|
||||
|
||||
"sendNormalRedirectsChecks",
|
||||
"sendNormalCustomRedirects",
|
||||
|
||||
"sendTorRedirectsChecks",
|
||||
"sendTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.sendTargetsRedirects.send.normal,
|
||||
...r.sendTargetsRedirects.send.tor,
|
||||
...r.sendNormalCustomRedirects,
|
||||
...r.sendTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
if (url.pathname != '/') resolve();
|
||||
|
||||
let instancesList;
|
||||
if (r.sendTargetsProtocol == 'normal') instancesList = [...r.sendNormalRedirectsChecks, ...r.sendNormalCustomRedirects];
|
||||
else if (r.sendTargetsProtocol == 'tor') instancesList = [...r.sendTorRedirectsChecks, ...r.sendTorCustomRedirects];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) resolve();
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
disableSendTarget = r.disableSendTarget;
|
||||
sendTargetsRedirects = r.sendTargetsRedirects;
|
||||
sendNormalRedirectsChecks = r.sendNormalRedirectsChecks;
|
||||
sendNormalCustomRedirects = r.sendNormalCustomRedirects;
|
||||
sendTorRedirectsChecks = r.sendTorRedirectsChecks;
|
||||
sendTorCustomRedirects = r.sendTorCustomRedirects;
|
||||
sendTargetsProtocol = r.sendTargetsProtocol;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...sendTargetsRedirects.send.normal,
|
||||
...sendTargetsRedirects.send.tor,
|
||||
...sendNormalCustomRedirects,
|
||||
...sendTorRedirectsChecks,
|
||||
...sendTorCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableSendTarget",
|
||||
"sendTargetsRedirects",
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve(); return; }
|
||||
if (url.pathname != '/') { resolve(); return; }
|
||||
|
||||
"sendNormalRedirectsChecks",
|
||||
"sendNormalCustomRedirects",
|
||||
let instancesList;
|
||||
if (sendTargetsProtocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects];
|
||||
else if (sendTargetsProtocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects];
|
||||
|
||||
"sendTorRedirectsChecks",
|
||||
"sendTorCustomRedirects",
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
"sendTargetsProtocol"
|
||||
],
|
||||
r => {
|
||||
if (r.disableSendTarget) { resolve(); return; }
|
||||
if (type != "main_frame") { resolve(); return; }
|
||||
if (
|
||||
initiator && (
|
||||
[
|
||||
...r.sendTargetsRedirects.send.normal,
|
||||
...r.sendTargetsRedirects.send.tor,
|
||||
...r.sendNormalCustomRedirects,
|
||||
...r.sendTorRedirectsChecks
|
||||
].includes(initiator.origin) ||
|
||||
targets.includes(initiator.host)
|
||||
)
|
||||
) { resolve(); return; }
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.sendTargetsProtocol == 'normal') instancesList = [...r.sendNormalRedirectsChecks, ...r.sendNormalCustomRedirects];
|
||||
if (r.sendTargetsProtocol == 'tor') instancesList = [...r.sendTorRedirectsChecks, ...r.sendTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(randomInstance);
|
||||
}
|
||||
)
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
if (disableSendTarget) return;
|
||||
if (type != "main_frame") return;
|
||||
if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
|
||||
let instancesList;
|
||||
if (sendTargetsProtocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects];
|
||||
if (sendTargetsProtocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
}
|
||||
|
||||
function initDefaults() {
|
||||
return new Promise(resolve => {
|
||||
fetch('/instances/data.json').then(response => response.text()).then(async data => {
|
||||
|
@ -27,138 +27,116 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
let proxiTokNormalRedirectsChecks;
|
||||
let proxiTokTorRedirectsChecks;
|
||||
let proxiTokNormalCustomRedirects = [];
|
||||
let proxiTokTorCustomRedirects = [];
|
||||
|
||||
let disable; // disableTiktok
|
||||
let protocol;
|
||||
|
||||
function initProxiTokCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"tiktokProtocol",
|
||||
"proxiTokNormalRedirectsChecks",
|
||||
"proxiTokNormalCustomRedirects",
|
||||
"proxiTokTorRedirectsChecks",
|
||||
"proxiTokTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.proxiTokNormalRedirectsChecks,
|
||||
...r.proxiTokNormalCustomRedirects,
|
||||
...r.proxiTokTorRedirectsChecks,
|
||||
...r.proxiTokTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...proxiTokNormalRedirectsChecks,
|
||||
...proxiTokNormalCustomRedirects,
|
||||
...proxiTokTorRedirectsChecks,
|
||||
...proxiTokTorCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.tiktokProtocol == 'normal') checkedInstances = [...r.proxiTokNormalRedirectsChecks, ...r.proxiTokNormalCustomRedirects]
|
||||
else if (r.tiktokProtocol == 'tor') checkedInstances = [...r.proxiTokTorRedirectsChecks, ...r.proxiTokTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('proxitok', from, to, 'theme');
|
||||
utils.copyCookie('proxitok', from, to, 'api-legacy');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (tiktokProtocol == 'normal') checkedInstances = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects]
|
||||
else if (tiktokProtocol == 'tor') checkedInstances = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('proxitok', from, to, 'theme');
|
||||
utils.copyCookie('proxitok', from, to, 'api-legacy');
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setProxiTokCookies() {
|
||||
return new Promise(resolve => {
|
||||
if (disableTiktok || tiktokProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (tiktokProtocol == 'normal') checkedInstances = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects]
|
||||
else if (tiktokProtocol == 'tor') checkedInstances = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('proxitok', to, 'theme');
|
||||
utils.getCookiesFromStorage('proxitok', to, 'api-legacy');
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
let
|
||||
disableTiktok,
|
||||
tiktokProtocol,
|
||||
tiktokRedirects,
|
||||
proxiTokNormalRedirectsChecks,
|
||||
proxiTokNormalCustomRedirects,
|
||||
proxiTokTorRedirectsChecks,
|
||||
proxiTokTorCustomRedirects;
|
||||
|
||||
function init() {
|
||||
return new Promise(async resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"tiktokProtocol",
|
||||
"disableTiktok",
|
||||
"tiktokProtocol",
|
||||
"tiktokRedirects",
|
||||
"proxiTokNormalRedirectsChecks",
|
||||
"proxiTokNormalCustomRedirects",
|
||||
"proxiTokTorRedirectsChecks",
|
||||
"proxiTokTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableTiktok || r.tiktokProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.tiktokProtocol == 'normal') checkedInstances = [...r.proxiTokNormalRedirectsChecks, ...r.proxiTokNormalCustomRedirects]
|
||||
else if (r.tiktokProtocol == 'tor') checkedInstances = [...r.proxiTokTorRedirectsChecks, ...r.proxiTokTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('proxitok', to, 'theme');
|
||||
utils.getCookiesFromStorage('proxitok', to, 'api-legacy');
|
||||
}
|
||||
disableTiktok = r.disableTiktok;
|
||||
tiktokProtocol = r.tiktokProtocol;
|
||||
tiktokRedirects = r.tiktokRedirects;
|
||||
proxiTokNormalRedirectsChecks = r.proxiTokNormalRedirectsChecks;
|
||||
proxiTokNormalCustomRedirects = r.proxiTokNormalCustomRedirects;
|
||||
proxiTokTorRedirectsChecks = r.proxiTokTorRedirectsChecks;
|
||||
proxiTokTorCustomRedirects = r.proxiTokTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
// https://www.tiktok.com/@keysikaspol/video/7061265241887345946
|
||||
// https://www.tiktok.com/@keysikaspol
|
||||
function redirect(url, type, initiator) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableTiktok",
|
||||
"tiktokProtocol",
|
||||
if (disableTiktok) return;
|
||||
if (type != "main_frame") return;
|
||||
const all = [
|
||||
...tiktokRedirects.proxiTok.normal,
|
||||
...proxiTokNormalCustomRedirects
|
||||
];
|
||||
if (initiator && (all.includes(initiator.origin) || targets.includes(initiator.host))) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
|
||||
"tiktokRedirects",
|
||||
let instancesList;
|
||||
if (tiktokProtocol == 'normal') instancesList = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects];
|
||||
if (tiktokProtocol == 'tor') instancesList = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
"proxiTokNormalRedirectsChecks",
|
||||
"proxiTokNormalCustomRedirects",
|
||||
|
||||
"proxiTokTorRedirectsChecks",
|
||||
"proxiTokTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableTiktok) { resolve(); return; };
|
||||
if (type != "main_frame") { resolve(); return; };
|
||||
if (initiator && (
|
||||
[
|
||||
...r.tiktokRedirects.proxiTok.normal,
|
||||
...r.proxiTokNormalCustomRedirects
|
||||
].includes(initiator.origin) ||
|
||||
targets.includes(initiator.host)
|
||||
)
|
||||
) { resolve(); return; };
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; };
|
||||
// https://www.tiktok.com/@keysikaspol/video/7061265241887345946
|
||||
// https://www.tiktok.com/@keysikaspol
|
||||
|
||||
let instancesList;
|
||||
if (r.tiktokProtocol == 'normal') instancesList = [...r.proxiTokNormalRedirectsChecks, ...r.proxiTokNormalCustomRedirects];
|
||||
if (r.tiktokProtocol == 'tor') instancesList = [...r.proxiTokTorRedirectsChecks, ...r.proxiTokTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; };
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}`;
|
||||
}
|
||||
|
||||
async function reverse(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"tiktokRedirects",
|
||||
"proxiTokNormalCustomRedirects",
|
||||
"proxiTokTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.tiktokRedirects.proxiTok.normal,
|
||||
...r.tiktokRedirects.proxiTok.tor,
|
||||
...r.proxiTokNormalCustomRedirects,
|
||||
...r.proxiTokTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
function reverse(url) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
const all = [
|
||||
...tiktokRedirects.proxiTok.normal,
|
||||
...tiktokRedirects.proxiTok.tor,
|
||||
...proxiTokNormalCustomRedirects,
|
||||
...proxiTokTorCustomRedirects
|
||||
];
|
||||
if (!all.includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
resolve(`https://tiktok.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
resolve(`https://tiktok.com${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ browser.storage.local.get(
|
||||
r => {
|
||||
if (r['lingva_chakra-ui-color-mode'] !== undefined) localStorage.setItem('chakra-ui-color-mode', r['lingva_chakra-ui-color-mode']);
|
||||
if (r.lingva_isauto !== undefined) localStorage.setItem('isauto', r.lingva_isauto);
|
||||
console.log('r.lingva_isauto', r.lingva_isauto, localStorage.getItem('isauto'))
|
||||
if (r.lingva_source !== undefined) localStorage.setItem('source', r.lingva_source);
|
||||
if (r.lingva_target !== undefined) localStorage.setItem('target', r.lingva_target);
|
||||
|
||||
|
@ -18,8 +18,59 @@ let redirects = {
|
||||
};
|
||||
|
||||
let
|
||||
translateDisable,
|
||||
translateFrontend,
|
||||
translateProtocol,
|
||||
translateRedirects,
|
||||
simplyTranslateNormalRedirectsChecks,
|
||||
lingvaNormalRedirectsChecks;
|
||||
simplyTranslateNormalCustomRedirects,
|
||||
simplyTranslateTorRedirectsChecks,
|
||||
simplyTranslateTorCustomRedirects,
|
||||
lingvaNormalRedirectsChecks,
|
||||
lingvaNormalCustomRedirects,
|
||||
lingvaTorRedirectsChecks,
|
||||
lingvaTorCustomRedirects;
|
||||
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"translateDisable",
|
||||
"translateFrontend",
|
||||
"translateProtocol",
|
||||
"translateRedirects",
|
||||
|
||||
"simplyTranslateNormalRedirectsChecks",
|
||||
"simplyTranslateNormalCustomRedirects",
|
||||
"simplyTranslateTorRedirectsChecks",
|
||||
"simplyTranslateTorCustomRedirects",
|
||||
|
||||
"lingvaNormalRedirectsChecks",
|
||||
"lingvaNormalCustomRedirects",
|
||||
"lingvaTorRedirectsChecks",
|
||||
"lingvaTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
translateDisable = r.translateDisable;
|
||||
translateFrontend = r.translateFrontend;
|
||||
translateProtocol = r.translateProtocol;
|
||||
translateRedirects = r.translateRedirects;
|
||||
simplyTranslateNormalRedirectsChecks = r.simplyTranslateNormalRedirectsChecks;
|
||||
simplyTranslateNormalCustomRedirects = r.simplyTranslateNormalCustomRedirects;
|
||||
simplyTranslateTorRedirectsChecks = r.simplyTranslateTorRedirectsChecks;
|
||||
simplyTranslateTorCustomRedirects = r.simplyTranslateTorCustomRedirects;
|
||||
lingvaNormalRedirectsChecks = r.lingvaNormalRedirectsChecks;
|
||||
lingvaNormalCustomRedirects = r.lingvaNormalCustomRedirects;
|
||||
lingvaTorRedirectsChecks = r.lingvaTorRedirectsChecks;
|
||||
lingvaTorCustomRedirects = r.lingvaTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function setRedirects(val) {
|
||||
browser.storage.local.get('cloudflareList', r => {
|
||||
@ -44,226 +95,153 @@ function setRedirects(val) {
|
||||
}
|
||||
|
||||
function initLingvaLocalStorage(test, url, tabId) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"translateDisable",
|
||||
"translateProtocol",
|
||||
"translateFrontend",
|
||||
"lingvaNormalRedirectsChecks",
|
||||
"lingvaNormalCustomRedirects",
|
||||
"lingvaTorRedirectsChecks",
|
||||
"lingvaTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.translateDisable || r.translateFrontend != 'lingva') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.lingvaNormalRedirectsChecks,
|
||||
...r.lingvaNormalCustomRedirects,
|
||||
...r.lingvaTorRedirectsChecks,
|
||||
...r.lingvaTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (translateDisable || translateFrontend != 'lingva') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...lingvaNormalRedirectsChecks,
|
||||
...lingvaNormalCustomRedirects,
|
||||
...lingvaTorRedirectsChecks,
|
||||
...lingvaTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
browser.tabs.executeScript(
|
||||
tabId,
|
||||
{ file: "/assets/javascripts/helpers/translate/get_lingva_preferences.js", runAt: "document_start" }
|
||||
);
|
||||
if (!test) {
|
||||
browser.tabs.executeScript(
|
||||
tabId,
|
||||
{ file: "/assets/javascripts/helpers/translate/get_lingva_preferences.js", runAt: "document_start" }
|
||||
);
|
||||
|
||||
let checkedInstances;
|
||||
if (r.translateProtocol == 'normal') checkedInstances = [...r.lingvaNormalRedirectsChecks, ...r.lingvaNormalCustomRedirects];
|
||||
if (r.translateProtocol == 'tor') checkedInstances = [...r.lingvaTorRedirectsChecks, ...r.lingvaTorCustomRedirects];
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
if (checkedInstances.length === 0) { resolve(); return; }
|
||||
for (const to of checkedInstances)
|
||||
browser.tabs.create(
|
||||
{ url: to },
|
||||
tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/translate/set_lingva_preferences.js", runAt: "document_start" })
|
||||
);
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
})
|
||||
let checkedInstances;
|
||||
if (translateProtocol == 'normal') checkedInstances = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects];
|
||||
if (translateProtocol == 'tor') checkedInstances = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects];
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
if (checkedInstances.length === 0) { resolve(); return; }
|
||||
for (const to of checkedInstances)
|
||||
browser.tabs.create(
|
||||
{ url: to },
|
||||
tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/translate/set_lingva_preferences.js", runAt: "document_start" })
|
||||
);
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function initSimplyTranslateCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"translateProtocol",
|
||||
"simplyTranslateNormalRedirectsChecks",
|
||||
"simplyTranslateNormalCustomRedirects",
|
||||
"simplyTranslateTorRedirectsChecks",
|
||||
"simplyTranslateTorCustomRedirects",
|
||||
"simplyTranslateI2pRedirectsChecks",
|
||||
"simplyTranslateI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.simplyTranslateNormalRedirectsChecks,
|
||||
...r.simplyTranslateNormalCustomRedirects,
|
||||
...r.simplyTranslateTorRedirectsChecks,
|
||||
...r.simplyTranslateTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.translateProtocol == 'normal') checkedInstances = [...r.simplyTranslateNormalRedirectsChecks, ...r.simplyTranslateNormalCustomRedirects]
|
||||
else if (r.translateProtocol == 'tor') checkedInstances = [...r.simplyTranslateTorRedirectsChecks, ...r.simplyTranslateTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('simplyTranslate', from, to, 'from_lang');
|
||||
utils.copyCookie('simplyTranslate', from, to, 'to_lang');
|
||||
utils.copyCookie('simplyTranslate', from, to, 'tts_enabled');
|
||||
utils.copyCookie('simplyTranslate', from, to, 'use_text_fields');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...simplyTranslateNormalRedirectsChecks,
|
||||
...simplyTranslateNormalCustomRedirects,
|
||||
...simplyTranslateTorRedirectsChecks,
|
||||
...simplyTranslateTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (translateProtocol == 'normal') checkedInstances = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]
|
||||
else if (translateProtocol == 'tor') checkedInstances = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('simplyTranslate', from, to, 'from_lang');
|
||||
utils.copyCookie('simplyTranslate', from, to, 'to_lang');
|
||||
utils.copyCookie('simplyTranslate', from, to, 'tts_enabled');
|
||||
utils.copyCookie('simplyTranslate', from, to, 'use_text_fields');
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function setSimplyTranslateCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"translateProtocol",
|
||||
"translateDisable",
|
||||
"translateFrontend",
|
||||
"simplyTranslateNormalRedirectsChecks",
|
||||
"simplyTranslateNormalCustomRedirects",
|
||||
"simplyTranslateTorRedirectsChecks",
|
||||
"simplyTranslateTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.translateDisable || r.translateFrontend != 'simplyTranslate') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.translateProtocol == 'normal') checkedInstances = [...r.simplyTranslateNormalRedirectsChecks, ...r.simplyTranslateNormalCustomRedirects]
|
||||
else if (r.translateProtocol == 'tor') checkedInstances = [...r.simplyTranslateTorRedirectsChecks, ...r.simplyTranslateTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'from_lang');
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'to_lang');
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'tts_enabled');
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'use_text_fields');
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (translateDisable || translateFrontend != 'simplyTranslate') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (translateProtocol == 'normal') checkedInstances = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]
|
||||
else if (translateProtocol == 'tor') checkedInstances = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'from_lang');
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'to_lang');
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'tts_enabled');
|
||||
utils.getCookiesFromStorage('simplyTranslate', to, 'use_text_fields');
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function redirect(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"translateDisable",
|
||||
"translateFrontend",
|
||||
"translateProtocol",
|
||||
"translateRedirects",
|
||||
if (translateDisable) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
|
||||
"simplyTranslateNormalRedirectsChecks",
|
||||
"simplyTranslateNormalCustomRedirects",
|
||||
"simplyTranslateTorRedirectsChecks",
|
||||
"simplyTranslateTorCustomRedirects",
|
||||
if (translateFrontend == 'simplyTranslate') {
|
||||
let instancesList;
|
||||
if (translateProtocol == 'normal') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects];
|
||||
if (translateProtocol == 'tor') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
"lingvaNormalRedirectsChecks",
|
||||
"lingvaNormalCustomRedirects",
|
||||
"lingvaTorRedirectsChecks",
|
||||
"lingvaTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.translateDisable) { resolve(); return; };
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; };
|
||||
const randomInstance = utils.getRandomInstance(instancesList)
|
||||
return `${randomInstance}/${url.search}`;
|
||||
}
|
||||
else if (translateFrontend == 'lingva') {
|
||||
let params_arr = url.search.split('&');
|
||||
params_arr[0] = params_arr[0].substring(1);
|
||||
let params = {};
|
||||
for (let i = 0; i < params_arr.length; i++) {
|
||||
let pair = params_arr[i].split('=');
|
||||
params[pair[0]] = pair[1];
|
||||
}
|
||||
let instancesList;
|
||||
if (translateProtocol == 'normal') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects];
|
||||
if (translateProtocol == 'tor') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
if (r.translateFrontend == 'simplyTranslate') {
|
||||
let instancesList;
|
||||
if (r.translateProtocol == 'normal') instancesList = [...r.simplyTranslateNormalRedirectsChecks, ...r.simplyTranslateNormalCustomRedirects];
|
||||
if (r.translateProtocol == 'tor') instancesList = [...r.simplyTranslateTorRedirectsChecks, ...r.simplyTranslateTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; };
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
resolve(`${randomInstance}/${url.search}`);
|
||||
}
|
||||
else if (r.translateFrontend == 'lingva') {
|
||||
let params_arr = url.search.split('&');
|
||||
params_arr[0] = params_arr[0].substring(1);
|
||||
let params = {};
|
||||
for (let i = 0; i < params_arr.length; i++) {
|
||||
let pair = params_arr[i].split('=');
|
||||
params[pair[0]] = pair[1];
|
||||
}
|
||||
let instancesList;
|
||||
if (r.translateProtocol == 'normal') instancesList = [...r.lingvaNormalRedirectsChecks, ...r.lingvaNormalCustomRedirects];
|
||||
if (r.translateProtocol == 'tor') instancesList = [...r.lingvaTorRedirectsChecks, ...r.lingvaTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
if (params.sl && params.tl && params.text) {
|
||||
resolve(`${randomInstance}/${params.sl}/${params.tl}/${params.text}`); return;
|
||||
}
|
||||
resolve(randomInstance);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
const randomInstance = utils.getRandomInstance(instancesList)
|
||||
if (params.sl && params.tl && params.text) {
|
||||
return `${randomInstance}/${params.sl}/${params.tl}/${params.text}`
|
||||
}
|
||||
return randomInstance;
|
||||
}
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"translateDisable",
|
||||
"translateFrontend",
|
||||
"translateProtocol",
|
||||
"translateRedirects",
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (translateDisable) { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...translateRedirects.simplyTranslate.normal,
|
||||
...translateRedirects.simplyTranslate.tor,
|
||||
|
||||
"simplyTranslateNormalRedirectsChecks",
|
||||
"simplyTranslateNormalCustomRedirects",
|
||||
"simplyTranslateTorRedirectsChecks",
|
||||
"simplyTranslateTorCustomRedirects",
|
||||
...simplyTranslateNormalCustomRedirects,
|
||||
...simplyTranslateTorCustomRedirects,
|
||||
|
||||
"lingvaNormalRedirectsChecks",
|
||||
"lingvaNormalCustomRedirects",
|
||||
"lingvaTorRedirectsChecks",
|
||||
"lingvaTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.translateDisable) { resolve(); return; };
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.translateRedirects.simplyTranslate.normal,
|
||||
...r.translateRedirects.simplyTranslate.tor,
|
||||
...translateRedirects.lingva.normal,
|
||||
...translateRedirects.lingva.tor,
|
||||
|
||||
...r.simplyTranslateNormalCustomRedirects,
|
||||
...r.simplyTranslateTorCustomRedirects,
|
||||
...lingvaNormalCustomRedirects,
|
||||
...lingvaTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
...r.translateRedirects.lingva.normal,
|
||||
...r.translateRedirects.lingva.tor,
|
||||
let instancesList;
|
||||
if (translateProtocol == 'normal') {
|
||||
if (translateFrontend == 'simplyTranslate') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects];
|
||||
else if (translateFrontend == 'lingva') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects];
|
||||
}
|
||||
else if (translateProtocol == 'tor') {
|
||||
if (translateFrontend == 'simplyTranslate') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects];
|
||||
else if (translateFrontend == 'lingva') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects];
|
||||
}
|
||||
|
||||
...r.lingvaNormalCustomRedirects,
|
||||
...r.lingvaTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.translateProtocol == 'normal') {
|
||||
if (r.translateFrontend == 'simplyTranslate') instancesList = [...r.simplyTranslateNormalRedirectsChecks, ...r.simplyTranslateNormalCustomRedirects];
|
||||
else if (r.translateFrontend == 'lingva') instancesList = [...r.lingvaNormalRedirectsChecks, ...r.lingvaNormalCustomRedirects];
|
||||
}
|
||||
else if (r.translateProtocol == 'tor') {
|
||||
if (r.translateFrontend == 'simplyTranslate') instancesList = [...r.simplyTranslateTorRedirectsChecks, ...r.simplyTranslateTorCustomRedirects];
|
||||
else if (r.translateFrontend == 'lingva') instancesList = [...r.lingvaTorRedirectsChecks, ...r.lingvaTorCustomRedirects];
|
||||
}
|
||||
|
||||
const index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
@ -310,9 +288,7 @@ export default {
|
||||
initSimplyTranslateCookies,
|
||||
setSimplyTranslateCookies,
|
||||
initLingvaLocalStorage,
|
||||
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
switchInstance,
|
||||
|
@ -32,241 +32,174 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
let nitterNormalRedirectsChecks;
|
||||
let
|
||||
disableTwitter,
|
||||
twitterProtocol,
|
||||
twitterRedirects,
|
||||
nitterNormalRedirectsChecks,
|
||||
nitterNormalCustomRedirects,
|
||||
nitterTorRedirectsChecks,
|
||||
nitterTorCustomRedirects;
|
||||
|
||||
async function redirect(url, initiator) {
|
||||
return new Promise(resolve => {
|
||||
function init() {
|
||||
return new Promise(async resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableTwitter",
|
||||
"twitterProtocol",
|
||||
|
||||
"twitterRedirects",
|
||||
|
||||
"nitterNormalRedirectsChecks",
|
||||
"nitterNormalCustomRedirects",
|
||||
|
||||
"nitterTorRedirectsChecks",
|
||||
"nitterTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableTwitter) { resolve(); return; }
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; }
|
||||
if (url.pathname.split("/").includes("home")) { resolve(); return; }
|
||||
|
||||
if (
|
||||
initiator &&
|
||||
[
|
||||
...r.twitterRedirects.nitter.normal,
|
||||
...r.twitterRedirects.nitter.tor,
|
||||
...r.nitterTorCustomRedirects,
|
||||
...r.nitterNormalCustomRedirects
|
||||
].includes(initiator.origin)
|
||||
) { resolve('BYPASSTAB'); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.twitterProtocol == 'normal') instancesList = [...r.nitterNormalRedirectsChecks, ...r.nitterNormalCustomRedirects];
|
||||
else if (r.twitterProtocol == 'tor') instancesList = [...r.nitterTorRedirectsChecks, ...r.nitterTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
console.log('randomInstance', randomInstance);
|
||||
// https://pbs.twimg.com/profile_images/648888480974508032/66_cUYfj_400x400.jpg
|
||||
if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video")
|
||||
resolve(`${randomInstance}/pic/${encodeURIComponent(`${url.host}${url.pathname}`)}`);
|
||||
else if (url.pathname.split("/").includes("tweets"))
|
||||
resolve(`${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}`);
|
||||
else if (url.host == 't.co')
|
||||
resolve(`${randomInstance}/t.co${url.pathname}`);
|
||||
else
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function reverse(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"twitterRedirects",
|
||||
"nitterNormalCustomRedirects",
|
||||
"nitterTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.twitterRedirects.nitter.normal,
|
||||
...r.twitterRedirects.nitter.tor,
|
||||
...r.nitterNormalCustomRedirects,
|
||||
...r.nitterTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
resolve(`https://twitter.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"twitterRedirects",
|
||||
"twitterProtocol",
|
||||
|
||||
"nitterNormalRedirectsChecks",
|
||||
"nitterNormalCustomRedirects",
|
||||
|
||||
"nitterTorRedirectsChecks",
|
||||
"nitterTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.twitterRedirects.nitter.normal,
|
||||
...r.twitterRedirects.nitter.tor,
|
||||
...r.nitterNormalCustomRedirects,
|
||||
...r.nitterTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.twitterProtocol == 'normal') instancesList = [...r.nitterNormalRedirectsChecks, ...r.nitterNormalCustomRedirects];
|
||||
else if (r.twitterProtocol == 'tor') instancesList = [...r.nitterTorRedirectsChecks, ...r.nitterTorCustomRedirects];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function removeXFrameOptions(e) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"twitterRedirects",
|
||||
"twitterProtocol",
|
||||
|
||||
"nitterNormalRedirectsChecks",
|
||||
"nitterNormalCustomRedirects",
|
||||
|
||||
"nitterTorRedirectsChecks",
|
||||
"nitterTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let url = new URL(e.url);
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.twitterRedirects.nitter.normal,
|
||||
...r.twitterRedirects.nitter.tor,
|
||||
...r.nitterNormalCustomRedirects,
|
||||
...r.nitterTorCustomRedirects,
|
||||
].includes(protocolHost) ||
|
||||
e.type != 'sub_frame'
|
||||
) { resolve(); return; }
|
||||
let isChanged = false;
|
||||
for (const i in e.responseHeaders) if (e.responseHeaders[i].name == 'x-frame-options') {
|
||||
e.responseHeaders.splice(i, 1);
|
||||
isChanged = true;
|
||||
}
|
||||
if (isChanged) resolve({ responseHeaders: e.responseHeaders });
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function initNitterCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"twitterProtocol",
|
||||
"nitterNormalRedirectsChecks",
|
||||
"nitterNormalCustomRedirects",
|
||||
"nitterTorRedirectsChecks",
|
||||
"nitterTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (
|
||||
![
|
||||
...r.nitterNormalRedirectsChecks,
|
||||
...r.nitterTorRedirectsChecks,
|
||||
...r.nitterNormalCustomRedirects,
|
||||
...r.nitterTorCustomRedirects,
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.twitterProtocol == 'normal') checkedInstances = [...r.nitterNormalRedirectsChecks, ...r.nitterNormalCustomRedirects]
|
||||
else if (r.twitterProtocol == 'tor') checkedInstances = [...r.nitterTorRedirectsChecks, ...r.nitterTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('nitter', from, to, 'theme');
|
||||
utils.copyCookie('nitter', from, to, 'infiniteScroll');
|
||||
utils.copyCookie('nitter', from, to, 'stickyProfile');
|
||||
utils.copyCookie('nitter', from, to, 'bidiSupport');
|
||||
utils.copyCookie('nitter', from, to, 'hideTweetStats');
|
||||
utils.copyCookie('nitter', from, to, 'hideBanner');
|
||||
utils.copyCookie('nitter', from, to, 'hidePins');
|
||||
utils.copyCookie('nitter', from, to, 'hideReplies');
|
||||
utils.copyCookie('nitter', from, to, 'squareAvatars');
|
||||
utils.copyCookie('nitter', from, to, 'mp4Playback');
|
||||
utils.copyCookie('nitter', from, to, 'hlsPlayback');
|
||||
utils.copyCookie('nitter', from, to, 'proxyVideos');
|
||||
utils.copyCookie('nitter', from, to, 'muteVideos');
|
||||
utils.copyCookie('nitter', from, to, 'autoplayGifs');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function setNitterCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"twitterProtocol",
|
||||
"disableTwitter",
|
||||
"youtubeFrontend",
|
||||
"nitterNormalRedirectsChecks",
|
||||
"nitterNormalCustomRedirects",
|
||||
"nitterTorRedirectsChecks",
|
||||
"nitterTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableYoutube || r.youtubeFrontend != 'nitter' || r.twitterProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.youtubeProtocol == 'normal') checkedInstances = [...r.nitterNormalRedirectsChecks, ...r.nitterNormalCustomRedirects]
|
||||
else if (r.youtubeProtocol == 'tor') checkedInstances = [...r.nitterTorRedirectsChecks, ...r.nitterTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('nitter', to, 'theme');
|
||||
utils.getCookiesFromStorage('nitter', to, 'infiniteScroll');
|
||||
utils.getCookiesFromStorage('nitter', to, 'stickyProfile');
|
||||
utils.getCookiesFromStorage('nitter', to, 'bidiSupport');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hideTweetStats');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hideBanner');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hidePins');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hideReplies');
|
||||
utils.getCookiesFromStorage('nitter', to, 'squareAvatars');
|
||||
utils.getCookiesFromStorage('nitter', to, 'mp4Playback');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hlsPlayback');
|
||||
utils.getCookiesFromStorage('nitter', to, 'proxyVideos');
|
||||
utils.getCookiesFromStorage('nitter', to, 'muteVideos');
|
||||
utils.getCookiesFromStorage('nitter', to, 'autoplayGifs');
|
||||
}
|
||||
disableTwitter = r.disableTwitter;
|
||||
twitterProtocol = r.twitterProtocol;
|
||||
twitterRedirects = r.twitterRedirects;
|
||||
nitterNormalRedirectsChecks = r.nitterNormalRedirectsChecks;
|
||||
nitterNormalCustomRedirects = r.nitterNormalCustomRedirects;
|
||||
nitterTorRedirectsChecks = r.nitterTorRedirectsChecks;
|
||||
nitterTorCustomRedirects = r.nitterTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...nitterNormalRedirectsChecks,
|
||||
...nitterTorRedirectsChecks,
|
||||
...nitterNormalCustomRedirects,
|
||||
...nitterTorCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
function redirect(url, initiator) {
|
||||
if (disableTwitter) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
if (url.pathname.split("/").includes("home")) return;
|
||||
if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB';
|
||||
|
||||
let instancesList;
|
||||
if (twitterProtocol == 'normal') instancesList = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects];
|
||||
else if (twitterProtocol == 'tor') instancesList = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
// https://pbs.twimg.com/profile_images/648888480974508032/66_cUYfj_400x400.jpg
|
||||
if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video")
|
||||
return `${randomInstance}/pic/${encodeURIComponent(`${url.host}${url.pathname}`)}`;
|
||||
else if (url.pathname.split("/").includes("tweets"))
|
||||
return `${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}`;
|
||||
else if (url.host == 't.co')
|
||||
return `${randomInstance}/t.co${url.pathname}`;
|
||||
else
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function reverse(url) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve; return; }
|
||||
resolve(`https://twitter.com${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(async resolve => {
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost)) { resolve; return; }
|
||||
let instancesList;
|
||||
if (twitterProtocol == 'normal') instancesList = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects];
|
||||
else if (twitterProtocol == 'tor') instancesList = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) { resolve; return; }
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function removeXFrameOptions(e) {
|
||||
let url = new URL(e.url);
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (!all().includes(protocolHost) || e.type != 'sub_frame') return;
|
||||
let isChanged = false;
|
||||
for (const i in e.responseHeaders) if (e.responseHeaders[i].name == 'x-frame-options') {
|
||||
e.responseHeaders.splice(i, 1);
|
||||
isChanged = true;
|
||||
}
|
||||
if (isChanged) return { responseHeaders: e.responseHeaders };
|
||||
}
|
||||
|
||||
function initNitterCookies(test, from) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(from);
|
||||
if (!all().includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (twitterProtocol == 'normal') checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects]
|
||||
else if (twitterProtocol == 'tor') checkedInstances = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('nitter', from, to, 'theme');
|
||||
utils.copyCookie('nitter', from, to, 'infiniteScroll');
|
||||
utils.copyCookie('nitter', from, to, 'stickyProfile');
|
||||
utils.copyCookie('nitter', from, to, 'bidiSupport');
|
||||
utils.copyCookie('nitter', from, to, 'hideTweetStats');
|
||||
utils.copyCookie('nitter', from, to, 'hideBanner');
|
||||
utils.copyCookie('nitter', from, to, 'hidePins');
|
||||
utils.copyCookie('nitter', from, to, 'hideReplies');
|
||||
utils.copyCookie('nitter', from, to, 'squareAvatars');
|
||||
utils.copyCookie('nitter', from, to, 'mp4Playback');
|
||||
utils.copyCookie('nitter', from, to, 'hlsPlayback');
|
||||
utils.copyCookie('nitter', from, to, 'proxyVideos');
|
||||
utils.copyCookie('nitter', from, to, 'muteVideos');
|
||||
utils.copyCookie('nitter', from, to, 'autoplayGifs');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setNitterCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableTwitter || twitterProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (twitterProtocol == 'normal') checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects]
|
||||
else if (twitterProtocol == 'tor') checkedInstances = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('nitter', to, 'theme');
|
||||
utils.getCookiesFromStorage('nitter', to, 'infiniteScroll');
|
||||
utils.getCookiesFromStorage('nitter', to, 'stickyProfile');
|
||||
utils.getCookiesFromStorage('nitter', to, 'bidiSupport');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hideTweetStats');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hideBanner');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hidePins');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hideReplies');
|
||||
utils.getCookiesFromStorage('nitter', to, 'squareAvatars');
|
||||
utils.getCookiesFromStorage('nitter', to, 'mp4Playback');
|
||||
utils.getCookiesFromStorage('nitter', to, 'hlsPlayback');
|
||||
utils.getCookiesFromStorage('nitter', to, 'proxyVideos');
|
||||
utils.getCookiesFromStorage('nitter', to, 'muteVideos');
|
||||
utils.getCookiesFromStorage('nitter', to, 'autoplayGifs');
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function initDefaults() {
|
||||
return new Promise(resolve => {
|
||||
fetch('/instances/data.json').then(response => response.text()).then(data => {
|
||||
@ -297,14 +230,11 @@ function initDefaults() {
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
switchInstance,
|
||||
reverse,
|
||||
removeXFrameOptions,
|
||||
|
||||
initNitterCookies,
|
||||
setNitterCookies,
|
||||
|
||||
initDefaults,
|
||||
};
|
||||
|
@ -313,16 +313,13 @@ function copyRaw(test, copyRawElement) {
|
||||
let currTab = tabs[0];
|
||||
if (currTab) {
|
||||
let url;
|
||||
try {
|
||||
url = new URL(currTab.url);
|
||||
} catch { resolve(); return; }
|
||||
let newUrl;
|
||||
newUrl = await youtubeHelper.reverse(url);
|
||||
|
||||
if (!newUrl) newUrl = await twitterHelper.reverse(url);
|
||||
if (!newUrl) newUrl = await instagramHelper.reverse(url);
|
||||
if (!newUrl) newUrl = await tiktokHelper.reverse(url);
|
||||
if (!newUrl) newUrl = await imgurHelper.reverse(url);
|
||||
try { url = new URL(currTab.url); }
|
||||
catch { resolve(); return; }
|
||||
let newUrl = await youtubeHelper.reverse(url);
|
||||
if (!newUrl) newUrl = twitterHelper.reverse(url);
|
||||
if (!newUrl) newUrl = instagramHelper.reverse(url);
|
||||
if (!newUrl) newUrl = tiktokHelper.reverse(url);
|
||||
if (!newUrl) newUrl = imgurHelper.reverse(url);
|
||||
|
||||
if (newUrl) {
|
||||
resolve(true);
|
||||
@ -372,7 +369,7 @@ function unify(test, unifyElement) {
|
||||
if (!result) result = await translateHelper.initLingvaLocalStorage(test, url);
|
||||
|
||||
if (result) {
|
||||
if (!test) {
|
||||
if (!test && unifyElement) {
|
||||
const textElement = unifyElement.getElementsByTagName('h4')[0]
|
||||
const oldHtml = textElement.innerHTML;
|
||||
textElement.innerHTML = 'Unified';
|
||||
@ -395,17 +392,17 @@ function switchInstance(test) {
|
||||
try { url = new URL(currTab.url); }
|
||||
catch { resolve(); return };
|
||||
let newUrl = await youtubeHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await twitterHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await instagramHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await redditHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await searchHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = twitterHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = instagramHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = redditHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = searchHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await translateHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await mediumHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await sendTargetsHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await peertubeHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await lbryHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await imgurHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await wikipediaHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = mediumHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = sendTargetsHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = peertubeHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = lbryHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = imgurHelper.switchInstance(url);
|
||||
// if (!newUrl) newUrl = wikipediaHelper.switchInstance(url);
|
||||
|
||||
if (newUrl) {
|
||||
if (!test)
|
||||
|
@ -26,172 +26,157 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
let wikilessNormalRedirectsChecks;
|
||||
let
|
||||
disableWikipedia,
|
||||
wikipediaRedirects,
|
||||
wikipediaProtocol,
|
||||
wikilessNormalRedirectsChecks,
|
||||
wikilessTorRedirectsChecks,
|
||||
wikilessI2pRedirectsChecks,
|
||||
wikilessNormalCustomRedirects,
|
||||
wikilessTorCustomRedirects,
|
||||
wikilessI2pCustomRedirects;
|
||||
|
||||
function initWikilessCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"wikipediaProtocol",
|
||||
"wikilessNormalRedirectsChecks",
|
||||
"wikilessNormalCustomRedirects",
|
||||
"wikilessTorRedirectsChecks",
|
||||
"wikilessTorCustomRedirects",
|
||||
"wikilessI2pRedirectsChecks",
|
||||
"wikilessI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.wikilessNormalRedirectsChecks,
|
||||
...r.wikilessNormalCustomRedirects,
|
||||
...r.wikilessTorRedirectsChecks,
|
||||
...r.wikilessTorCustomRedirects,
|
||||
...r.wikilessI2pRedirectsChecks,
|
||||
...r.wikilessI2pCustomRedirects,
|
||||
].includes(protocolHost)) resolve();
|
||||
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.wikipediaProtocol == 'normal') checkedInstances = [...r.wikilessNormalRedirectsChecks, ...r.wikilessNormalCustomRedirects]
|
||||
else if (r.wikipediaProtocol == 'tor') checkedInstances = [...r.wikilessTorRedirectsChecks, ...r.wikilessTorCustomRedirects]
|
||||
else if (r.wikipediaProtocol == 'i2p') checkedInstances = [...r.wikilessI2pRedirectsChecks, ...r.wikilessI2pCustomRedirects]
|
||||
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('wikiless', from, to, 'theme');
|
||||
utils.copyCookie('wikiless', from, to, 'default_lang');
|
||||
}
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function setWikilessCookies() {
|
||||
return new Promise(resolve => {
|
||||
function init() {
|
||||
return new Promise(async resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableWikipedia",
|
||||
"wikipediaRedirects",
|
||||
"wikipediaProtocol",
|
||||
|
||||
"wikilessNormalRedirectsChecks",
|
||||
"wikilessNormalCustomRedirects",
|
||||
"wikilessTorRedirectsChecks",
|
||||
"wikilessI2pRedirectsChecks",
|
||||
"wikilessNormalCustomRedirects",
|
||||
"wikilessTorCustomRedirects",
|
||||
"wikilessI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableWikipedia || r.wikipediaProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.wikipediaProtocol == 'normal') checkedInstances = [...r.wikilessNormalRedirectsChecks, ...r.wikilessNormalCustomRedirects]
|
||||
else if (r.wikipediaProtocol == 'tor') checkedInstances = [...r.wikilessTorRedirectsChecks, ...r.wikilessTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('wikiless', to, 'theme');
|
||||
utils.getCookiesFromStorage('wikiless', to, 'default_lang');
|
||||
}
|
||||
disableWikipedia = r.disableWikipedia;
|
||||
wikipediaRedirects = r.wikipediaRedirects;
|
||||
wikipediaProtocol = r.wikipediaProtocol;
|
||||
wikilessNormalRedirectsChecks = r.wikilessNormalRedirectsChecks;
|
||||
wikilessTorRedirectsChecks = r.wikilessTorRedirectsChecks;
|
||||
wikilessI2pRedirectsChecks = r.wikilessI2pRedirectsChecks;
|
||||
wikilessNormalCustomRedirects = r.wikilessNormalCustomRedirects;
|
||||
wikilessTorCustomRedirects = r.wikilessTorCustomRedirects;
|
||||
wikilessI2pCustomRedirects = r.wikilessI2pCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableWikipedia",
|
||||
"wikipediaRedirects",
|
||||
"wikipediaProtocol",
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
"wikilessNormalRedirectsChecks",
|
||||
"wikilessTorRedirectsChecks",
|
||||
"wikilessI2pRedirectsChecks",
|
||||
"wikilessNormalCustomRedirects",
|
||||
"wikilessTorCustomRedirects",
|
||||
"wikilessI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableWikipedia) { resolve(); return; }
|
||||
if (!targets.test(url.href)) { resolve(); return; }
|
||||
function initWikilessCookies(test, from) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(from);
|
||||
const all = [
|
||||
...wikilessNormalRedirectsChecks,
|
||||
...wikilessNormalCustomRedirects,
|
||||
...wikilessTorRedirectsChecks,
|
||||
...wikilessTorCustomRedirects,
|
||||
...wikilessI2pRedirectsChecks,
|
||||
...wikilessI2pCustomRedirects,
|
||||
];
|
||||
if (!all.includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
let GETArguments = [];
|
||||
if (url.search.length > 0) {
|
||||
let search = url.search.substring(1); //get rid of '?'
|
||||
let argstrings = search.split("&");
|
||||
for (let i = 0; i < argstrings.length; i++) {
|
||||
let args = argstrings[i].split("=");
|
||||
GETArguments.push([args[0], args[1]]);
|
||||
}
|
||||
}
|
||||
let instancesList;
|
||||
if (r.wikipediaProtocol == 'normal') instancesList = [...r.wikilessNormalRedirectsChecks, ...r.wikilessNormalCustomRedirects];
|
||||
else if (r.wikipediaProtocol == 'tor') instancesList = [...r.wikilessTorRedirectsChecks, ...r.wikilessTorCustomRedirects];
|
||||
else if (r.wikipediaProtocol == 'i2p') instancesList = [...r.wikilessI2pRedirectsChecks, ...r.wikilessI2pCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
let randomInstance = utils.getRandomInstance(instancesList)
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (wikipediaProtocol == 'normal') checkedInstances = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects]
|
||||
else if (wikipediaProtocol == 'tor') checkedInstances = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects]
|
||||
else if (wikipediaProtocol == 'i2p') checkedInstances = [...wikilessI2pRedirectsChecks, ...wikilessI2pCustomRedirects]
|
||||
|
||||
let link = `${randomInstance}${url.pathname}`;
|
||||
let urlSplit = url.host.split(".");
|
||||
if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") {
|
||||
if (urlSplit[0] == "m")
|
||||
GETArguments.push(["mobileaction", "toggle_view_mobile"]);
|
||||
else
|
||||
GETArguments.push(["lang", urlSplit[0]]);
|
||||
if (urlSplit[1] == "m")
|
||||
GETArguments.push(["mobileaction", "toggle_view_mobile"]);
|
||||
// wikiless doesn't have mobile view support yet
|
||||
}
|
||||
for (let i = 0; i < GETArguments.length; i++)
|
||||
link += (i == 0 ? "?" : "&") + GETArguments[i][0] + "=" + GETArguments[i][1];
|
||||
|
||||
resolve(link);
|
||||
for (const to of checkedInstances) {
|
||||
utils.copyCookie('wikiless', from, to, 'theme');
|
||||
utils.copyCookie('wikiless', from, to, 'default_lang');
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function setWikilessCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableWikipedia || wikipediaProtocol === undefined) { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (wikipediaProtocol == 'normal') checkedInstances = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects]
|
||||
else if (wikipediaProtocol == 'tor') checkedInstances = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects]
|
||||
for (const to of checkedInstances) {
|
||||
utils.getCookiesFromStorage('wikiless', to, 'theme');
|
||||
utils.getCookiesFromStorage('wikiless', to, 'default_lang');
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
function redirect(url) {
|
||||
if (disableWikipedia) return;
|
||||
if (!targets.test(url.href)) return;
|
||||
|
||||
let GETArguments = [];
|
||||
if (url.search.length > 0) {
|
||||
let search = url.search.substring(1); //get rid of '?'
|
||||
let argstrings = search.split("&");
|
||||
for (let i = 0; i < argstrings.length; i++) {
|
||||
let args = argstrings[i].split("=");
|
||||
GETArguments.push([args[0], args[1]]);
|
||||
}
|
||||
}
|
||||
let instancesList;
|
||||
if (wikipediaProtocol == 'normal') instancesList = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects];
|
||||
else if (wikipediaProtocol == 'tor') instancesList = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects];
|
||||
else if (wikipediaProtocol == 'i2p') instancesList = [...wikilessI2pRedirectsChecks, ...wikilessI2pCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
const randomInstance = utils.getRandomInstance(instancesList)
|
||||
|
||||
let link = `${randomInstance}${url.pathname}`;
|
||||
let urlSplit = url.host.split(".");
|
||||
if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") {
|
||||
if (urlSplit[0] == "m")
|
||||
GETArguments.push(["mobileaction", "toggle_view_mobile"]);
|
||||
else
|
||||
GETArguments.push(["lang", urlSplit[0]]);
|
||||
if (urlSplit[1] == "m")
|
||||
GETArguments.push(["mobileaction", "toggle_view_mobile"]);
|
||||
// wikiless doesn't have mobile view support yet
|
||||
}
|
||||
for (let i = 0; i < GETArguments.length; i++)
|
||||
link += (i == 0 ? "?" : "&") + GETArguments[i][0] + "=" + GETArguments[i][1];
|
||||
return link;
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"wikipediaRedirects",
|
||||
"wikipediaProtocol",
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
const wikipediaList = [
|
||||
...wikipediaRedirects.wikiless.normal,
|
||||
...wikipediaRedirects.wikiless.tor,
|
||||
...wikipediaRedirects.wikiless.i2p,
|
||||
|
||||
"wikilessNormalRedirectsChecks",
|
||||
"wikilessTorRedirectsChecks",
|
||||
...wikilessNormalCustomRedirects,
|
||||
...wikilessTorCustomRedirects,
|
||||
...wikilessI2pCustomRedirects
|
||||
]
|
||||
if (!wikipediaList.includes(protocolHost)) return;
|
||||
|
||||
"wikilessI2pRedirectsChecks",
|
||||
"wikilessNormalCustomRedirects",
|
||||
let instancesList;
|
||||
if (wikipediaProtocol == 'normal') instancesList = [...wikilessNormalCustomRedirects, ...wikilessNormalRedirectsChecks];
|
||||
else if (wikipediaProtocol == 'tor') instancesList = [...wikilessTorCustomRedirects, ...wikilessTorRedirectsChecks];
|
||||
else if (wikipediaProtocol == 'i2p') instancesList = [...wikilessI2pCustomRedirects, ...wikilessI2pRedirectsChecks];
|
||||
|
||||
"wikilessTorCustomRedirects",
|
||||
"wikilessI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
let wikipediaList = [
|
||||
...r.wikipediaRedirects.wikiless.normal,
|
||||
...r.wikipediaRedirects.wikiless.tor,
|
||||
...r.wikipediaRedirects.wikiless.i2p,
|
||||
|
||||
...r.wikilessNormalCustomRedirects,
|
||||
...r.wikilessTorCustomRedirects,
|
||||
...r.wikilessI2pCustomRedirects
|
||||
]
|
||||
if (!wikipediaList.includes(protocolHost)) resolve();
|
||||
|
||||
let instancesList;
|
||||
if (r.wikipediaProtocol == 'normal') instancesList = [...r.wikilessNormalCustomRedirects, ...r.wikilessNormalRedirectsChecks];
|
||||
else if (r.wikipediaProtocol == 'tor') instancesList = [...r.wikilessTorCustomRedirects, ...r.wikilessTorRedirectsChecks];
|
||||
else if (r.wikipediaProtocol == 'i2p') instancesList = [...r.wikilessI2pCustomRedirects, ...r.wikilessI2pRedirectsChecks];
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length === 0) resolve();
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -57,16 +57,26 @@ function setRedirects(val) {
|
||||
}
|
||||
|
||||
let
|
||||
disableYoutube,
|
||||
OnlyEmbeddedVideo,
|
||||
youtubeFrontend,
|
||||
youtubeProtocol,
|
||||
youtubeEmbedFrontend,
|
||||
youtubeRedirects,
|
||||
invidiousNormalRedirectsChecks,
|
||||
invidiousNormalCustomRedirects,
|
||||
invidiousTorRedirectsChecks,
|
||||
|
||||
invidiousTorCustomRedirects,
|
||||
pipedNormalRedirectsChecks,
|
||||
pipedNormalCustomRedirects,
|
||||
pipedTorRedirectsChecks,
|
||||
|
||||
pipedTorCustomRedirects,
|
||||
pipedMaterialNormalRedirectsChecks,
|
||||
pipedMaterialTorRedirectsChecks;
|
||||
pipedMaterialNormalCustomRedirects,
|
||||
pipedMaterialTorRedirectsChecks,
|
||||
pipedMaterialTorCustomRedirects;
|
||||
|
||||
function redirect(url, details, initiator) {
|
||||
function init() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
@ -75,231 +85,184 @@ function redirect(url, details, initiator) {
|
||||
"youtubeFrontend",
|
||||
"youtubeProtocol",
|
||||
"youtubeEmbedFrontend",
|
||||
|
||||
"youtubeRedirects",
|
||||
|
||||
"invidiousNormalRedirectsChecks",
|
||||
"invidiousNormalCustomRedirects",
|
||||
|
||||
"invidiousTorRedirectsChecks",
|
||||
"invidiousTorCustomRedirects",
|
||||
|
||||
"pipedNormalRedirectsChecks",
|
||||
"pipedNormalCustomRedirects",
|
||||
|
||||
"pipedTorRedirectsChecks",
|
||||
"pipedTorCustomRedirects",
|
||||
|
||||
"pipedMaterialNormalRedirectsChecks",
|
||||
"pipedMaterialNormalCustomRedirects",
|
||||
|
||||
"pipedMaterialTorRedirectsChecks",
|
||||
"pipedMaterialTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableYoutube) { resolve(); return; }
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; }
|
||||
|
||||
if (
|
||||
initiator && (
|
||||
[
|
||||
...r.youtubeRedirects.invidious.normal,
|
||||
...r.invidiousNormalCustomRedirects,
|
||||
...r.youtubeRedirects.invidious.tor,
|
||||
...r.invidiousTorCustomRedirects,
|
||||
|
||||
...r.youtubeRedirects.piped.normal,
|
||||
...r.youtubeRedirects.piped.tor,
|
||||
...r.pipedNormalCustomRedirects,
|
||||
...r.pipedTorCustomRedirects
|
||||
].includes(initiator.origin)
|
||||
)
|
||||
) { resolve('BYPASSTAB'); return; }
|
||||
|
||||
const isInvidious = r.youtubeFrontend == 'invidious';
|
||||
const isPiped = r.youtubeFrontend == 'piped';
|
||||
const isPipedMaterial = r.youtubeFrontend == 'pipedMaterial'
|
||||
const isFreetube = r.youtubeFrontend == 'freetube';
|
||||
const isYatte = r.youtubeFrontend == 'yatte';
|
||||
|
||||
const isFrontendYoutube = r.youtubeEmbedFrontend == "youtube";
|
||||
const isFrontendInvidious = r.youtubeEmbedFrontend == 'invidious';
|
||||
const isFrontendPiped = r.youtubeEmbedFrontend == 'piped';
|
||||
const isFrontendPipedMaterial = r.youtubeEmbedFrontend == 'pipedMaterial';
|
||||
|
||||
const isOnlyEmbeddedVideo = r.OnlyEmbeddedVideo == 'onlyNotEmbedded';
|
||||
const isOnlyNotEmbedded = r.OnlyEmbeddedVideo == 'onlyNotEmbedded'
|
||||
|
||||
const is_main_frame = details.type === "main_frame";
|
||||
const is_sub_frame = details.type === "sub_frame";
|
||||
|
||||
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) { resolve(); return; } // Don't redirect YouTube Player API.
|
||||
|
||||
if (r.youtubeFrontend == 'yatte' && is_main_frame)
|
||||
resolve(url.href.replace(/^https?:\/{2}/, 'yattee://'));
|
||||
|
||||
else if (isFreetube && is_main_frame)
|
||||
resolve(`freetube://https:${url.pathname}${url.search}`);
|
||||
|
||||
else if (isFreetube && params && isFrontendYoutube)
|
||||
resolve();
|
||||
|
||||
else if (isInvidious || ((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) {
|
||||
|
||||
if (isOnlyEmbeddedVideo && !is_sub_frame) { resolve(); return; }
|
||||
if (isOnlyNotEmbedded && params && !((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.youtubeProtocol == 'normal') instancesList = [...r.invidiousNormalRedirectsChecks, ...r.invidiousNormalCustomRedirects];
|
||||
else if (r.youtubeProtocol == 'tor') instancesList = [...r.invidiousTorRedirectsChecks, ...r.invidiousTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
} else if (isPiped || ((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)) {
|
||||
|
||||
if (isOnlyEmbeddedVideo && !is_sub_frame) { resolve(); return; }
|
||||
if (
|
||||
isOnlyNotEmbedded && params &&
|
||||
!((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)
|
||||
) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.youtubeProtocol == 'normal') instancesList = [...r.pipedNormalRedirectsChecks, ...r.pipedNormalCustomRedirects];
|
||||
else if (r.youtubeProtocol == 'tor') instancesList = [...r.pipedTorRedirectsChecks, ...r.pipedTorCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`)
|
||||
}
|
||||
else if (isPipedMaterial || ((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)) {
|
||||
if (isOnlyEmbeddedVideo && details.type !== "sub_frame") { resolve(); return; }
|
||||
if (
|
||||
isOnlyNotEmbedded && params &&
|
||||
!((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)
|
||||
) { resolve(); return; }
|
||||
|
||||
let instancesList;
|
||||
if (r.youtubeProtocol == 'normal') instancesList = [...r.pipedMaterialNormalRedirectsChecks, ...r.pipedMaterialNormalCustomRedirects];
|
||||
else if (r.youtubeProtocol == 'tor') instancesList = [...r.pipedMaterialTorRedirectsChecks, ...r.pipedMaterialTorCustomRedirects];
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
else resolve('CANCEL');
|
||||
disableYoutube = r.disableYoutube;
|
||||
OnlyEmbeddedVideo = r.OnlyEmbeddedVideo;
|
||||
youtubeFrontend = r.youtubeFrontend;
|
||||
youtubeProtocol = r.youtubeProtocol;
|
||||
youtubeEmbedFrontend = r.youtubeEmbedFrontend;
|
||||
youtubeRedirects = r.youtubeRedirects;
|
||||
invidiousNormalRedirectsChecks = r.invidiousNormalRedirectsChecks;
|
||||
invidiousNormalCustomRedirects = r.invidiousNormalCustomRedirects;
|
||||
invidiousTorRedirectsChecks = r.invidiousTorRedirectsChecks;
|
||||
invidiousTorCustomRedirects = r.invidiousTorCustomRedirects;
|
||||
pipedNormalRedirectsChecks = r.pipedNormalRedirectsChecks;
|
||||
pipedNormalCustomRedirects = r.pipedNormalCustomRedirects;
|
||||
pipedTorRedirectsChecks = r.pipedTorRedirectsChecks;
|
||||
pipedTorCustomRedirects = r.pipedTorCustomRedirects;
|
||||
pipedMaterialNormalRedirectsChecks = r.pipedMaterialNormalRedirectsChecks;
|
||||
pipedMaterialNormalCustomRedirects = r.pipedMaterialNormalCustomRedirects;
|
||||
pipedMaterialTorRedirectsChecks = r.pipedMaterialTorRedirectsChecks;
|
||||
pipedMaterialTorCustomRedirects = r.pipedMaterialTorCustomRedirects;
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
function all() {
|
||||
return [
|
||||
...youtubeRedirects.invidious.normal,
|
||||
...youtubeRedirects.invidious.tor,
|
||||
|
||||
...youtubeRedirects.piped.normal,
|
||||
...youtubeRedirects.piped.tor,
|
||||
|
||||
...youtubeRedirects.pipedMaterial.normal,
|
||||
...youtubeRedirects.pipedMaterial.tor,
|
||||
|
||||
...invidiousNormalCustomRedirects,
|
||||
...invidiousTorCustomRedirects,
|
||||
|
||||
...pipedNormalCustomRedirects,
|
||||
...pipedTorCustomRedirects,
|
||||
|
||||
...pipedMaterialNormalCustomRedirects,
|
||||
...pipedMaterialTorCustomRedirects,
|
||||
];
|
||||
}
|
||||
|
||||
function redirect(url, details, initiator) {
|
||||
if (disableYoutube) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB';
|
||||
|
||||
const isInvidious = youtubeFrontend == 'invidious';
|
||||
const isPiped = youtubeFrontend == 'piped';
|
||||
const isPipedMaterial = youtubeFrontend == 'pipedMaterial'
|
||||
const isFreetube = youtubeFrontend == 'freetube';
|
||||
const isYatte = youtubeFrontend == 'yatte';
|
||||
|
||||
const isFrontendYoutube = youtubeEmbedFrontend == "youtube";
|
||||
const isFrontendInvidious = youtubeEmbedFrontend == 'invidious';
|
||||
const isFrontendPiped = youtubeEmbedFrontend == 'piped';
|
||||
const isFrontendPipedMaterial = youtubeEmbedFrontend == 'pipedMaterial';
|
||||
|
||||
const isOnlyEmbeddedVideo = OnlyEmbeddedVideo == 'onlyNotEmbedded';
|
||||
const isOnlyNotEmbedded = OnlyEmbeddedVideo == 'onlyNotEmbedded'
|
||||
|
||||
const is_main_frame = details.type === "main_frame";
|
||||
const is_sub_frame = details.type === "sub_frame";
|
||||
|
||||
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return; // Don't redirect YouTube Player API.
|
||||
|
||||
if (youtubeFrontend == 'yatte' && is_main_frame)
|
||||
return url.href.replace(/^https?:\/{2}/, 'yattee://');
|
||||
|
||||
else if (isFreetube && is_main_frame)
|
||||
return `freetube://https:${url.pathname}${url.search}`;
|
||||
|
||||
else if (isFreetube && params && isFrontendYoutube)
|
||||
return;
|
||||
|
||||
else if (isInvidious || ((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) {
|
||||
|
||||
if (isOnlyEmbeddedVideo && !is_sub_frame) return;
|
||||
if (isOnlyNotEmbedded && params && !((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) return;
|
||||
|
||||
let instancesList;
|
||||
if (youtubeProtocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
|
||||
else if (youtubeProtocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
} else if (isPiped || ((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)) {
|
||||
|
||||
if (isOnlyEmbeddedVideo && !is_sub_frame) return;
|
||||
if (
|
||||
isOnlyNotEmbedded && params &&
|
||||
!((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)
|
||||
) return;
|
||||
|
||||
let instancesList;
|
||||
if (youtubeProtocol == 'normal') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects];
|
||||
else if (youtubeProtocol == 'tor') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
else if (isPipedMaterial || ((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)) {
|
||||
if (isOnlyEmbeddedVideo && details.type !== "sub_frame") return;
|
||||
if (
|
||||
isOnlyNotEmbedded && params &&
|
||||
!((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)
|
||||
) return;
|
||||
|
||||
let instancesList;
|
||||
if (youtubeProtocol == 'normal') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects];
|
||||
else if (youtubeProtocol == 'tor') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects];
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
else return 'CANCEL';
|
||||
}
|
||||
|
||||
function reverse(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"youtubeRedirects",
|
||||
"invidiousNormalCustomRedirects",
|
||||
"invidiousTorCustomRedirects",
|
||||
"pipedNormalCustomRedirects",
|
||||
"pipedTorCustomRedirects",
|
||||
"pipedMaterialNormalCustomRedirects",
|
||||
"pipedMaterialTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.youtubeRedirects.invidious.normal,
|
||||
...r.youtubeRedirects.invidious.tor,
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
const instances = all();
|
||||
if (!instances.includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
...r.youtubeRedirects.piped.normal,
|
||||
...r.youtubeRedirects.piped.tor,
|
||||
|
||||
...r.youtubeRedirects.pipedMaterial.normal,
|
||||
...r.youtubeRedirects.pipedMaterial.tor,
|
||||
|
||||
...r.invidiousNormalCustomRedirects,
|
||||
...r.invidiousTorCustomRedirects,
|
||||
|
||||
...r.pipedNormalCustomRedirects,
|
||||
...r.pipedTorCustomRedirects,
|
||||
|
||||
...r.pipedMaterialNormalCustomRedirects,
|
||||
...r.pipedMaterialTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
resolve(`https://youtube.com${url.pathname}${url.search}`);
|
||||
})
|
||||
resolve(`https://youtube.com${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"youtubeRedirects",
|
||||
"youtubeFrontend",
|
||||
"youtubeProtocol",
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
const instances = all();
|
||||
if (!instances.includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
"invidiousNormalRedirectsChecks",
|
||||
"invidiousNormalCustomRedirects",
|
||||
let instancesList;
|
||||
if (youtubeProtocol == 'normal') {
|
||||
if (youtubeFrontend == 'invidious') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
|
||||
else if (youtubeFrontend == 'piped') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects];
|
||||
else if (youtubeFrontend == 'pipedMaterial') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects];
|
||||
}
|
||||
else if (youtubeProtocol == 'tor') {
|
||||
if (youtubeFrontend == 'invidious') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
|
||||
else if (youtubeFrontend == 'piped') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects];
|
||||
else if (youtubeFrontend == 'pipedMaterial') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects];
|
||||
}
|
||||
|
||||
"invidiousTorRedirectsChecks",
|
||||
"invidiousTorCustomRedirects",
|
||||
const i = instancesList.indexOf(protocolHost);
|
||||
if (i > -1) instancesList.splice(i, 1);
|
||||
if (instancesList.length == 0) { resolve(); return; }
|
||||
|
||||
"pipedNormalRedirectsChecks",
|
||||
"pipedNormalCustomRedirects",
|
||||
|
||||
"pipedTorRedirectsChecks",
|
||||
"pipedTorCustomRedirects",
|
||||
|
||||
"pipedMaterialNormalRedirectsChecks",
|
||||
"pipedMaterialNormalCustomRedirects",
|
||||
|
||||
"pipedMaterialTorRedirectsChecks",
|
||||
"pipedMaterialTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.youtubeRedirects.invidious.normal,
|
||||
...r.youtubeRedirects.invidious.tor,
|
||||
|
||||
...r.youtubeRedirects.piped.normal,
|
||||
...r.youtubeRedirects.piped.tor,
|
||||
|
||||
...r.youtubeRedirects.pipedMaterial.normal,
|
||||
...r.youtubeRedirects.pipedMaterial.tor,
|
||||
|
||||
...r.invidiousNormalCustomRedirects,
|
||||
...r.invidiousTorCustomRedirects,
|
||||
|
||||
...r.pipedNormalCustomRedirects,
|
||||
...r.pipedTorCustomRedirects,
|
||||
|
||||
...r.pipedMaterialNormalCustomRedirects,
|
||||
...r.pipedMaterialTorCustomRedirects
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
|
||||
let instancesList;
|
||||
if (r.youtubeProtocol == 'normal') {
|
||||
if (r.youtubeFrontend == 'invidious') instancesList = [...r.invidiousNormalRedirectsChecks, ...r.invidiousNormalCustomRedirects];
|
||||
else if (r.youtubeFrontend == 'piped') instancesList = [...r.pipedNormalRedirectsChecks, ...r.pipedNormalCustomRedirects];
|
||||
else if (r.youtubeFrontend == 'pipedMaterial') instancesList = [...r.pipedMaterialNormalRedirectsChecks, ...r.pipedMaterialNormalCustomRedirects];
|
||||
}
|
||||
else if (r.youtubeProtocol == 'tor') {
|
||||
if (r.youtubeFrontend == 'invidious') instancesList = [...r.invidiousTorRedirectsChecks, ...r.invidiousTorCustomRedirects];
|
||||
else if (r.youtubeFrontend == 'piped') instancesList = [...r.pipedTorRedirectsChecks, ...r.pipedTorCustomRedirects];
|
||||
else if (r.youtubeFrontend == 'pipedMaterial') instancesList = [...r.pipedMaterialTorRedirectsChecks, ...r.pipedMaterialTorCustomRedirects];
|
||||
}
|
||||
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
if (instancesList.length == 0) { resolve(); return; }
|
||||
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(`${randomInstance}${url.pathname}${url.search}`);
|
||||
})
|
||||
}
|
||||
|
||||
@ -365,207 +328,130 @@ function initDefaults() {
|
||||
}
|
||||
|
||||
function initInvidiousCookies(test, from) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutube",
|
||||
"youtubeProtocol",
|
||||
"youtubeFrontend",
|
||||
"invidiousNormalRedirectsChecks",
|
||||
"invidiousNormalCustomRedirects",
|
||||
"invidiousTorRedirectsChecks",
|
||||
"invidiousTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableYoutube || r.youtubeFrontend != 'invidious') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...r.invidiousNormalRedirectsChecks,
|
||||
...r.invidiousTorRedirectsChecks,
|
||||
...r.invidiousNormalCustomRedirects,
|
||||
...r.invidiousTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (r.youtubeProtocol == 'normal') checkedInstances = [...r.invidiousNormalRedirectsChecks, ...r.invidiousNormalCustomRedirects]
|
||||
else if (r.youtubeProtocol == 'tor') checkedInstances = [...r.invidiousTorRedirectsChecks, ...r.invidiousTorCustomRedirects]
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
for (const to of checkedInstances)
|
||||
utils.copyCookie('invidious', from, to, 'PREFS');
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
})
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(from);
|
||||
if (![
|
||||
...invidiousNormalRedirectsChecks,
|
||||
...invidiousTorRedirectsChecks,
|
||||
...invidiousNormalCustomRedirects,
|
||||
...invidiousTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
if (!test) {
|
||||
let checkedInstances;
|
||||
if (youtubeProtocol == 'normal') checkedInstances = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects]
|
||||
else if (youtubeProtocol == 'tor') checkedInstances = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects]
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
for (const to of checkedInstances)
|
||||
utils.copyCookie('invidious', from, to, 'PREFS');
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function setInvidiousCookies() {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutube",
|
||||
"youtubeProtocol",
|
||||
"youtubeFrontend",
|
||||
"invidiousNormalRedirectsChecks",
|
||||
"invidiousNormalCustomRedirects",
|
||||
"invidiousTorRedirectsChecks",
|
||||
"invidiousTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableYoutube || r.youtubeFrontend != 'invidious') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (r.youtubeProtocol == 'normal') checkedInstances = [...r.invidiousNormalRedirectsChecks, ...r.invidiousNormalCustomRedirects]
|
||||
else if (r.youtubeProtocol == 'tor') checkedInstances = [...r.invidiousTorRedirectsChecks, ...r.invidiousTorCustomRedirects]
|
||||
for (const to of checkedInstances)
|
||||
utils.getCookiesFromStorage('invidious', to, 'PREFS');
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (youtubeProtocol == 'normal') checkedInstances = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects]
|
||||
else if (youtubeProtocol == 'tor') checkedInstances = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects]
|
||||
for (const to of checkedInstances)
|
||||
utils.getCookiesFromStorage('invidious', to, 'PREFS');
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
|
||||
function initPipedLocalStorage(test, url, tabId) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutube",
|
||||
"youtubeProtocol",
|
||||
"youtubeFrontend",
|
||||
"pipedNormalRedirectsChecks",
|
||||
"pipedNormalCustomRedirects",
|
||||
"pipedTorRedirectsChecks",
|
||||
"pipedTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableYoutube || r.youtubeFrontend != 'piped') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.pipedNormalCustomRedirects,
|
||||
...r.pipedNormalRedirectsChecks,
|
||||
...r.pipedTorRedirectsChecks,
|
||||
...r.pipedTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
console.log('initPipedLocalStorage');
|
||||
if (disableYoutube || youtubeFrontend != 'piped') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...pipedNormalCustomRedirects,
|
||||
...pipedNormalRedirectsChecks,
|
||||
...pipedTorRedirectsChecks,
|
||||
...pipedTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
browser.tabs.executeScript(tabId, { file: "/assets/javascripts/helpers/youtube/get_piped_preferences.js", runAt: "document_start" });
|
||||
if (!test) {
|
||||
|
||||
let checkedInstances;
|
||||
if (r.youtubeProtocol == 'normal') checkedInstances = [...r.pipedNormalCustomRedirects, ...r.pipedNormalRedirectsChecks]
|
||||
else if (r.youtubeProtocol == 'tor') checkedInstances = [...r.pipedTorRedirectsChecks, ...r.pipedTorCustomRedirects]
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
for (const to of checkedInstances)
|
||||
browser.tabs.create(
|
||||
{ url: to },
|
||||
tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/youtube/set_piped_preferences.js", runAt: "document_start" })
|
||||
);
|
||||
}
|
||||
resolve(true);
|
||||
browser.tabs.executeScript(tabId, { file: "/assets/javascripts/helpers/youtube/get_piped_preferences.js", runAt: "document_start" });
|
||||
|
||||
let checkedInstances;
|
||||
if (youtubeProtocol == 'normal') checkedInstances = [...pipedNormalCustomRedirects, ...pipedNormalRedirectsChecks]
|
||||
else if (youtubeProtocol == 'tor') checkedInstances = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects]
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
for (const to of checkedInstances) {
|
||||
browser.tabs.create(
|
||||
{ url: checkedInstances[0] },
|
||||
tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/youtube/set_piped_preferences.js", runAt: "document_start" })
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function initPipedMaterialLocalStorage(test, url, tabId,) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutube",
|
||||
"youtubeProtocol",
|
||||
"youtubeFrontend",
|
||||
"pipedMaterialNormalRedirectsChecks",
|
||||
"pipedMaterialNormalCustomRedirects",
|
||||
"pipedMaterialTorRedirectsChecks",
|
||||
"pipedMaterialTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
if (r.disableYoutube || r.youtubeFrontend != 'pipedMaterial') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.pipedMaterialNormalRedirectsChecks,
|
||||
...r.pipedMaterialNormalCustomRedirects,
|
||||
...r.pipedMaterialTorRedirectsChecks,
|
||||
...r.pipedMaterialTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'pipedMaterial') { resolve(); return; }
|
||||
const protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...pipedMaterialNormalRedirectsChecks,
|
||||
...pipedMaterialNormalCustomRedirects,
|
||||
...pipedMaterialTorRedirectsChecks,
|
||||
...pipedMaterialTorCustomRedirects,
|
||||
].includes(protocolHost)) { resolve(); return; }
|
||||
|
||||
if (!test) {
|
||||
browser.tabs.executeScript(tabId, { file: "/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js", runAt: "document_start" });
|
||||
if (!test) {
|
||||
browser.tabs.executeScript(tabId, { file: "/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js", runAt: "document_start" });
|
||||
|
||||
let checkedInstances;
|
||||
if (r.youtubeProtocol == 'normal') checkedInstances = [...r.pipedMaterialNormalRedirectsChecks, ...r.pipedMaterialNormalCustomRedirects]
|
||||
else if (r.youtubeProtocol == 'tor') checkedInstances = [...r.pipedMaterialTorRedirectsChecks, ...r.pipedMaterialTorCustomRedirects]
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
for (const to of checkedInstances)
|
||||
browser.tabs.create(
|
||||
{ url: to },
|
||||
tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js", runAt: "document_start" })
|
||||
);
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
)
|
||||
let checkedInstances;
|
||||
if (youtubeProtocol == 'normal') checkedInstances = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects]
|
||||
else if (youtubeProtocol == 'tor') checkedInstances = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects]
|
||||
const i = checkedInstances.indexOf(protocolHost);
|
||||
if (i !== -1) checkedInstances.splice(i, 1);
|
||||
for (const to of checkedInstances)
|
||||
browser.tabs.create(
|
||||
{ url: to },
|
||||
tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js", runAt: "document_start" })
|
||||
);
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
|
||||
function removeXFrameOptions(e) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"youtubeRedirects",
|
||||
"invidiousNormalCustomRedirects",
|
||||
"invidiousTorCustomRedirects",
|
||||
const url = new URL(e.url);
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
const instances = all();
|
||||
if (!instances.includes(protocolHost) || e.type != 'sub_frame') return;
|
||||
|
||||
"pipedNormalCustomRedirects",
|
||||
"pipedTorCustomRedirects",
|
||||
|
||||
"pipedMaterialNormalCustomRedirects",
|
||||
"pipedMaterialTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
const url = new URL(e.url);
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (![
|
||||
...r.youtubeRedirects.invidious.normal,
|
||||
...r.youtubeRedirects.invidious.tor,
|
||||
...r.youtubeRedirects.piped.normal,
|
||||
...r.youtubeRedirects.piped.tor,
|
||||
|
||||
...r.invidiousNormalCustomRedirects,
|
||||
...r.invidiousTorCustomRedirects,
|
||||
|
||||
...r.pipedNormalCustomRedirects,
|
||||
...r.pipedTorCustomRedirects,
|
||||
|
||||
...r.pipedMaterialNormalCustomRedirects,
|
||||
...r.pipedMaterialTorCustomRedirects,
|
||||
].includes(protocolHost) || e.type != 'sub_frame') { resolve(); return; }
|
||||
let isChanged = false;
|
||||
for (const i in e.responseHeaders)
|
||||
if (e.responseHeaders[i].name == 'x-frame-options') {
|
||||
e.responseHeaders.splice(i, 1);
|
||||
isChanged = true;
|
||||
}
|
||||
if (isChanged) resolve({ responseHeaders: e.responseHeaders });
|
||||
})
|
||||
})
|
||||
let isChanged = false;
|
||||
for (const i in e.responseHeaders)
|
||||
if (e.responseHeaders[i].name == 'x-frame-options') {
|
||||
e.responseHeaders.splice(i, 1);
|
||||
isChanged = true;
|
||||
}
|
||||
if (isChanged) return { responseHeaders: e.responseHeaders };
|
||||
}
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
initPipedLocalStorage,
|
||||
initPipedMaterialLocalStorage,
|
||||
initInvidiousCookies,
|
||||
setInvidiousCookies,
|
||||
|
||||
redirect,
|
||||
reverse,
|
||||
|
||||
switchInstance,
|
||||
|
||||
initPipedLocalStorage,
|
||||
|
||||
initDefaults,
|
||||
|
||||
removeXFrameOptions,
|
||||
};
|
||||
|
@ -16,59 +16,69 @@ let redirects = {
|
||||
},
|
||||
};
|
||||
|
||||
let
|
||||
disableYoutubeMusic,
|
||||
beatbumpNormalRedirectsChecks,
|
||||
beatbumpNormalCustomRedirects;
|
||||
|
||||
function init() {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutubeMusic",
|
||||
"beatbumpNormalRedirectsChecks",
|
||||
"beatbumpNormalCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
disableYoutubeMusic = r.disableYoutubeMusic;
|
||||
beatbumpNormalRedirectsChecks = r.beatbumpNormalRedirectsChecks;
|
||||
beatbumpNormalCustomRedirects = r.beatbumpNormalCustomRedirects;
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
init();
|
||||
browser.storage.onChanged.addListener(init)
|
||||
|
||||
/*
|
||||
Video
|
||||
https://music.youtube.com/watch?v=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA
|
||||
https://beatbump.ml/listen?id=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA
|
||||
|
||||
Playlist
|
||||
https://music.youtube.com/playlist?list=PLqxd0OMLeWy64zlwhjouj92ISc38FbOns
|
||||
https://music.youtube.com/playlist?list=PLqxd0OMLeWy7lrJSzt9LnOJjbC1IaruPM
|
||||
https://music.youtube.com/playlist?list=PLQod4DlD72ZMJmOrSNbmEmK_iZ1oXPzKd
|
||||
https://beatbump.ml/playlist/VLPLqxd0OMLeWy64zlwhjouj92ISc38FbOns
|
||||
|
||||
Channel
|
||||
https://music.youtube.com/channel/UCfgmMDI7T5tOQqjnOBRe_wg
|
||||
https://beatbump.ml/artist/UCfgmMDI7T5tOQqjnOBRe_wg
|
||||
|
||||
Albums
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_lcr5O1zS8f6WIFI_yxqVp2RK9Dyy2bbw0
|
||||
https://beatbump.ml/release?id=MPREb_3DURc4yEUtD
|
||||
https://beatbump.ml/release?id=MPREb_evaZrV1WNdS
|
||||
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_n6OHVllUZUCnlIY1m-gUaH8uqkN3Y-Ca8
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_nBOTxAc3_RGB82-Z54jdARGxGaCYlpngY
|
||||
https://beatbump.ml/release?id=MPREb_QygdC0wEoLe
|
||||
|
||||
https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
|
||||
*/
|
||||
function redirect(url, type, initiator) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutubeMusic",
|
||||
if (disableYoutubeMusic) return;
|
||||
if (!targets.some(rx => rx.test(url.href))) return;
|
||||
|
||||
"beatbumpNormalRedirectsChecks",
|
||||
"beatbumpNormalCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
/*
|
||||
Video
|
||||
https://music.youtube.com/watch?v=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA
|
||||
https://beatbump.ml/listen?id=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA
|
||||
|
||||
Playlist
|
||||
https://music.youtube.com/playlist?list=PLqxd0OMLeWy64zlwhjouj92ISc38FbOns
|
||||
https://music.youtube.com/playlist?list=PLqxd0OMLeWy7lrJSzt9LnOJjbC1IaruPM
|
||||
https://music.youtube.com/playlist?list=PLQod4DlD72ZMJmOrSNbmEmK_iZ1oXPzKd
|
||||
https://beatbump.ml/playlist/VLPLqxd0OMLeWy64zlwhjouj92ISc38FbOns
|
||||
|
||||
Channel
|
||||
https://music.youtube.com/channel/UCfgmMDI7T5tOQqjnOBRe_wg
|
||||
https://beatbump.ml/artist/UCfgmMDI7T5tOQqjnOBRe_wg
|
||||
|
||||
Albums
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_lcr5O1zS8f6WIFI_yxqVp2RK9Dyy2bbw0
|
||||
https://beatbump.ml/release?id=MPREb_3DURc4yEUtD
|
||||
https://beatbump.ml/release?id=MPREb_evaZrV1WNdS
|
||||
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_n6OHVllUZUCnlIY1m-gUaH8uqkN3Y-Ca8
|
||||
https://music.youtube.com/playlist?list=OLAK5uy_nBOTxAc3_RGB82-Z54jdARGxGaCYlpngY
|
||||
https://beatbump.ml/release?id=MPREb_QygdC0wEoLe
|
||||
|
||||
https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
|
||||
*/
|
||||
if (r.disableYoutubeMusic) { resolve(); return; }
|
||||
if (!targets.some(rx => rx.test(url.href))) { resolve(); return; }
|
||||
|
||||
let instancesList = [...r.beatbumpNormalRedirectsChecks, ...r.beatbumpNormalCustomRedirects];
|
||||
if (instancesList.length === 0) { resolve(); return; }
|
||||
let randomInstance = utils.getRandomInstance(instancesList);
|
||||
|
||||
resolve(
|
||||
`${randomInstance}${url.pathname}${url.search}`
|
||||
.replace("/watch?v=", "/listen?id=")
|
||||
.replace("/channel/", "/artist/")
|
||||
.replace("/playlist?list=", "/playlist/VL")
|
||||
);
|
||||
}
|
||||
)
|
||||
})
|
||||
let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects];
|
||||
if (instancesList.length === 0) return;
|
||||
const randomInstance = utils.getRandomInstance(instancesList);
|
||||
resolve(
|
||||
`${randomInstance}${url.pathname}${url.search}`
|
||||
.replace("/watch?v=", "/listen?id=")
|
||||
.replace("/channel/", "/artist/")
|
||||
.replace("/playlist?list=", "/playlist/VL")
|
||||
);
|
||||
}
|
||||
|
||||
async function initDefaults() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "__MSG_extensionName__",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"version": "1.7.0",
|
||||
"version": "2.0.0",
|
||||
"manifest_version": 2,
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
|
@ -19,19 +19,8 @@ import sendTargetsHelper from "../../assets/javascripts/helpers/sendTargets.js";
|
||||
import peertubeHelper from "../../assets/javascripts/helpers/peertube.js";
|
||||
import lbryHelper from "../../assets/javascripts/helpers/lbry.js";
|
||||
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
youtubeHelper.setInvidiousCookies();
|
||||
translateHelper.setSimplyTranslateCookies();
|
||||
twitterHelper.setNitterCookies();
|
||||
wikipediaHelper.setWikilessCookies();
|
||||
searchHelper.setSearxCookies();
|
||||
searchHelper.setSearxngCookies();
|
||||
redditHelper.setLibredditCookies();
|
||||
redditHelper.setTedditCookies();
|
||||
tiktokHelper.setProxiTokCookies();
|
||||
|
||||
browser.runtime.onInstalled.addListener(
|
||||
async details => {
|
||||
if (details.reason == 'install') {
|
||||
@ -58,8 +47,15 @@ browser.runtime.onInstalled.addListener(
|
||||
}
|
||||
)
|
||||
|
||||
async function wholeInit() {
|
||||
}
|
||||
youtubeHelper.setInvidiousCookies();
|
||||
translateHelper.setSimplyTranslateCookies();
|
||||
twitterHelper.setNitterCookies();
|
||||
wikipediaHelper.setWikilessCookies();
|
||||
searchHelper.setSearxCookies();
|
||||
searchHelper.setSearxngCookies();
|
||||
redditHelper.setLibredditCookies();
|
||||
redditHelper.setTedditCookies();
|
||||
tiktokHelper.setProxiTokCookies();
|
||||
|
||||
let incognitoInit = false;
|
||||
browser.tabs.onCreated.addListener(
|
||||
@ -75,39 +71,39 @@ browser.tabs.onCreated.addListener(
|
||||
|
||||
let BYPASSTABs = [];
|
||||
browser.webRequest.onBeforeRequest.addListener(
|
||||
async details => {
|
||||
details => {
|
||||
const url = new URL(details.url);
|
||||
if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/(blocklist|data).json$/).test(url.href) && details.type == 'xmlhttprequest') return;
|
||||
await wholeInit();
|
||||
let initiator;
|
||||
if (details.originUrl)
|
||||
initiator = new URL(details.originUrl);
|
||||
else if (details.initiator)
|
||||
initiator = new URL(details.initiator);
|
||||
try {
|
||||
if (details.originUrl) initiator = new URL(details.originUrl);
|
||||
else if (details.initiator) initiator = new URL(details.initiator);
|
||||
}
|
||||
catch { return null; }
|
||||
|
||||
let newUrl = await youtubeMusicHelper.redirect(url, details.type)
|
||||
if (!newUrl) newUrl = await youtubeHelper.redirect(url, details, initiator)
|
||||
if (!newUrl) newUrl = await twitterHelper.redirect(url, initiator);
|
||||
if (!newUrl) newUrl = await instagramHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await mapsHelper.redirect(url, initiator);
|
||||
if (!newUrl) newUrl = await redditHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await mediumHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await imgurHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await tiktokHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await sendTargetsHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await peertubeHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await lbryHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = await translateHelper.redirect(url);
|
||||
if (!newUrl) newUrl = await searchHelper.redirect(url)
|
||||
if (!newUrl) newUrl = await wikipediaHelper.redirect(url);
|
||||
|
||||
let newUrl = youtubeMusicHelper.redirect(url, details.type)
|
||||
if (!newUrl) newUrl = youtubeHelper.redirect(url, details, initiator)
|
||||
if (!newUrl) newUrl = twitterHelper.redirect(url, initiator);
|
||||
if (!newUrl) newUrl = instagramHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = mapsHelper.redirect(url, initiator);
|
||||
if (!newUrl) newUrl = redditHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = mediumHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = imgurHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = tiktokHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = sendTargetsHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = peertubeHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = lbryHelper.redirect(url, details.type, initiator);
|
||||
if (!newUrl) newUrl = translateHelper.redirect(url);
|
||||
if (!newUrl) newUrl = searchHelper.redirect(url)
|
||||
if (!newUrl) newUrl = wikipediaHelper.redirect(url);
|
||||
|
||||
if (
|
||||
details.frameAncestors && details.frameAncestors.length > 0 &&
|
||||
await generalHelper.isException(new URL(details.frameAncestors[0].url))
|
||||
generalHelper.isException(new URL(details.frameAncestors[0].url))
|
||||
) newUrl = null;
|
||||
|
||||
if (await generalHelper.isException(url)) newUrl = 'BYPASSTAB';
|
||||
|
||||
if (generalHelper.isException(url)) newUrl = 'BYPASSTAB';
|
||||
if (BYPASSTABs.includes(details.tabId)) newUrl = null;
|
||||
|
||||
if (newUrl) {
|
||||
@ -115,15 +111,13 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||
console.log(`Canceled ${url}`);
|
||||
return { cancel: true };
|
||||
}
|
||||
else if (newUrl === 'BYPASSTAB') {
|
||||
if (newUrl === 'BYPASSTAB') {
|
||||
console.log(`Bypassed ${details.tabId} ${url}`);
|
||||
if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
console.info("Redirecting", url.href, "=>", newUrl);
|
||||
return { redirectUrl: newUrl };
|
||||
}
|
||||
console.info("Redirecting", url.href, "=>", newUrl);
|
||||
return { redirectUrl: newUrl };
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@ -133,7 +127,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||
|
||||
browser.tabs.onRemoved.addListener(
|
||||
tabId => {
|
||||
let i = BYPASSTABs.indexOf(tabId);
|
||||
const i = BYPASSTABs.indexOf(tabId);
|
||||
if (i > -1) {
|
||||
BYPASSTABs.splice(i, 1);
|
||||
console.log("Removed BYPASSTABs", tabId);
|
||||
@ -143,7 +137,6 @@ browser.tabs.onRemoved.addListener(
|
||||
|
||||
browser.webRequest.onHeadersReceived.addListener(
|
||||
async e => {
|
||||
await wholeInit();
|
||||
let response = twitterHelper.removeXFrameOptions(e)
|
||||
if (!response) youtubeHelper.removeXFrameOptions(e)
|
||||
return response;
|
||||
@ -153,20 +146,17 @@ browser.webRequest.onHeadersReceived.addListener(
|
||||
);
|
||||
|
||||
async function redirectOfflineInstance(url, tabId) {
|
||||
await wholeInit();
|
||||
let newUrl;
|
||||
|
||||
newUrl = youtubeHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = twitterHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = instagramHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = redditHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = searchHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = translateHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = mediumHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = imgurHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = wikipediaHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = peertubeHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = lbryHelper.switchInstance(url);
|
||||
let newUrl = await youtubeHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await twitterHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await instagramHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await redditHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await searchHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await translateHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await mediumHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await imgurHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await wikipediaHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await peertubeHelper.switchInstance(url);
|
||||
if (!newUrl) newUrl = await lbryHelper.switchInstance(url);
|
||||
|
||||
if (newUrl) {
|
||||
if (counter >= 5) {
|
||||
@ -194,13 +184,7 @@ function isAutoRedirect() {
|
||||
browser.webRequest.onResponseStarted.addListener(
|
||||
async details => {
|
||||
if (!await isAutoRedirect()) return null;
|
||||
|
||||
if (details.type == 'main_frame' && (details.statusCode == 502 || details.statusCode == 503 || details.statusCode == 504)) {
|
||||
// if (details.type == 'main_frame' && details.statusCode >= 200) {
|
||||
// console.log("statusCode", details.statusCode);
|
||||
const url = new URL(details.url);
|
||||
redirectOfflineInstance(url, details.tabId);
|
||||
}
|
||||
if (details.type == 'main_frame' && details.statusCode >= 500) redirectOfflineInstance(new URL(details.url), details.tabId);
|
||||
},
|
||||
{ urls: ["<all_urls>"], }
|
||||
)
|
||||
@ -208,10 +192,7 @@ browser.webRequest.onResponseStarted.addListener(
|
||||
browser.webRequest.onErrorOccurred.addListener(
|
||||
async details => {
|
||||
if (!await isAutoRedirect()) return;
|
||||
if (details.type == 'main_frame') {
|
||||
const url = new URL(details.url);
|
||||
redirectOfflineInstance(url, details.tabId);
|
||||
}
|
||||
if (details.type == 'main_frame') redirectOfflineInstance(new URL(details.url), details.tabId);
|
||||
},
|
||||
{ urls: ["<all_urls>"], }
|
||||
)
|
||||
@ -232,7 +213,7 @@ browser.contextMenus.create({
|
||||
|
||||
browser.contextMenus.create({
|
||||
id: "switchInstance",
|
||||
title: chrome.i18n.getMessage("switchInstance"),
|
||||
title: browser.i18n.getMessage("switchInstance"),
|
||||
contexts: ["browser_action"]
|
||||
});
|
||||
|
||||
@ -257,3 +238,7 @@ browser.contextMenus.onClicked.addListener(
|
||||
else if (info.menuItemId == 'unify') utils.unify();
|
||||
}
|
||||
);
|
||||
|
||||
browser.runtime.onMessage.addListener(message => {
|
||||
if (message.function === 'unify') utils.unify();
|
||||
});
|
||||
|
@ -9,7 +9,10 @@ import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
await youtubeHelper.setInvidiousCookies();
|
||||
await youtubeHelper.initPipedLocalStorage();
|
||||
await youtubeHelper.initPipedMaterialLocalStorage();
|
||||
await translateHelper.setSimplyTranslateCookies();
|
||||
await translateHelper.initLingvaLocalStorage();
|
||||
await twitterHelper.setNitterCookies();
|
||||
await wikipediaHelper.setWikilessCookies();
|
||||
await searchHelper.setSearxCookies();
|
||||
|
@ -94,7 +94,7 @@ utils.unify(true).then(r => {
|
||||
if (!r) document.getElementById('unify_div').style.display = 'none';
|
||||
else {
|
||||
const unify = document.getElementById('unify');
|
||||
unify.addEventListener("click", () => utils.unify(false, unify));
|
||||
unify.addEventListener("click", () => browser.runtime.sendMessage({ function: 'unify' }));
|
||||
}
|
||||
})
|
||||
|
||||
@ -108,4 +108,14 @@ browser.storage.local.get(
|
||||
document.getElementById(frontend).classList.add("hide")
|
||||
else
|
||||
document.getElementById(frontend).classList.remove("hide")
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
for (const a of document.getElementsByTagName('a')) {
|
||||
a.addEventListener('click', e => {
|
||||
if (!a.classList.includes('button')) {
|
||||
browser.tabs.create({ url: a.getAttribute('href') });
|
||||
e.preventDefault();
|
||||
}
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user