Cleaning and updating the updateInstance func
This commit is contained in:
parent
933cd7b908
commit
eb6e58af52
|
@ -11,12 +11,6 @@ import mapsHelper from "./maps.js";
|
||||||
import medium from "./medium.js";
|
import medium from "./medium.js";
|
||||||
|
|
||||||
|
|
||||||
function filterInstances(instances) {
|
|
||||||
let onionScan = instances.filter((instance) => !instance.includes(".onion"))
|
|
||||||
let i2pScan = onionScan.filter((instance) => !instance.includes(".i2p"))
|
|
||||||
return i2pScan;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addHttps(instances) {
|
function addHttps(instances) {
|
||||||
return instances.map((item, i) => "https://" + item)
|
return instances.map((item, i) => "https://" + item)
|
||||||
}
|
}
|
||||||
|
@ -33,15 +27,24 @@ function updateInstances() {
|
||||||
|
|
||||||
if (request.status === 200) {
|
if (request.status === 200) {
|
||||||
const instances = JSON.parse(request.responseText);
|
const instances = JSON.parse(request.responseText);
|
||||||
youtubeHelper.redirects = addHttps(filterInstances(instances.invidious));
|
|
||||||
twitterHelper.redirects = addHttps(filterInstances(instances.nitter));
|
youtubeHelper.setRedirects(instances.invidious);
|
||||||
instagramHelper.redirects = addHttps(filterInstances(instances.bibliogram));
|
|
||||||
redditHelper.redirects.libreddit = addHttps(filterInstances(instances.simplyTranslate))
|
twitterHelper.setRedirects(instances.nitter);
|
||||||
redditHelper.redirects.teddit = addHttps(filterInstances(instances.teddit));
|
|
||||||
searchHelper.redirects.searx = addHttps(filterInstances(instances.simplyTranslate));
|
instagramHelper.setRedirects(instances.bibliogram);
|
||||||
searchHelper.redirects.whoogle = addHttps(filterInstances(instances.whoogle));
|
|
||||||
wikipediaHelper.redirects = addHttps(filterInstances(instances.wikiless));
|
redditHelper.setTedditRedirects(instances.teddit);
|
||||||
mediumHelper.redirects = addHttps(filterInstances(instances.scribe));
|
|
||||||
|
translateHelper.setSimplyTranslateRedirects(instances.simplyTranslate);
|
||||||
|
|
||||||
|
searchHelper.setSearxRedirects(instances.searx);
|
||||||
|
searchHelper.setWhoogleRedirects(instances.whoogle);
|
||||||
|
|
||||||
|
wikipediaHelper.setRedirects(instances.wikiless);
|
||||||
|
|
||||||
|
mediumHelper.setRedirects(instances.scribe);
|
||||||
|
|
||||||
console.info("Successfully updated Instances");
|
console.info("Successfully updated Instances");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +110,6 @@ function isException(url, initiator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
filterInstances,
|
|
||||||
getRandomInstance,
|
getRandomInstance,
|
||||||
updateInstances,
|
updateInstances,
|
||||||
addHttps,
|
addHttps,
|
||||||
|
|
|
@ -18,6 +18,13 @@ let redirects = {
|
||||||
"https://bib.actionsack.com"
|
"https://bib.actionsack.com"
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
function setRedirects(val) {
|
||||||
|
redirects = val;
|
||||||
|
browser.storage.sync.set({ instagramRedirects: val })
|
||||||
|
console.log("instagramRedirects: ", val)
|
||||||
|
}
|
||||||
|
|
||||||
const reservedPaths = [
|
const reservedPaths = [
|
||||||
"about",
|
"about",
|
||||||
"explore",
|
"explore",
|
||||||
|
@ -59,8 +66,7 @@ function setBibliogramInstance(val) {
|
||||||
browser.storage.sync.set({ bibliogramInstance })
|
browser.storage.sync.set({ bibliogramInstance })
|
||||||
};
|
};
|
||||||
|
|
||||||
async function redirect(url, initiator, type) {
|
function redirect(url, initiator, type) {
|
||||||
await init();
|
|
||||||
if (disableInstagram)
|
if (disableInstagram)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -86,25 +92,30 @@ async function redirect(url, initiator, type) {
|
||||||
return `${link}/u${url.pathname}${url.search}`;
|
return `${link}/u${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInstagram(url) {
|
||||||
|
return targets.includes(url.host)
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableInstagram",
|
"disableInstagram",
|
||||||
"bibliogramInstance",
|
"bibliogramInstance",
|
||||||
|
"instagramRedirects"
|
||||||
])
|
])
|
||||||
disableInstagram = result.disableInstagram ?? false;
|
disableInstagram = result.disableInstagram ?? false;
|
||||||
bibliogramInstance = result.bibliogramInstance;
|
bibliogramInstance = result.bibliogramInstance;
|
||||||
|
if (result.instagramRedirects)
|
||||||
|
redirects = result.instagramRedirects
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
getRedirects,
|
||||||
redirects,
|
setRedirects,
|
||||||
reservedPaths,
|
|
||||||
bypassPaths,
|
|
||||||
getDisableInstagram,
|
getDisableInstagram,
|
||||||
setDisableInstagram,
|
setDisableInstagram,
|
||||||
getBibliogramInstance,
|
getBibliogramInstance,
|
||||||
setBibliogramInstance,
|
setBibliogramInstance,
|
||||||
|
isInstagram,
|
||||||
redirect,
|
redirect,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@ const layers = {
|
||||||
traffic: "S", // not implemented on OSM, default to standard.
|
traffic: "S", // not implemented on OSM, default to standard.
|
||||||
bicycling: "C",
|
bicycling: "C",
|
||||||
};
|
};
|
||||||
|
|
||||||
function addressToLatLng(address, callback) {
|
function addressToLatLng(address, callback) {
|
||||||
const xmlhttp = new XMLHttpRequest();
|
const xmlhttp = new XMLHttpRequest();
|
||||||
xmlhttp.onreadystatechange = () => {
|
xmlhttp.onreadystatechange = () => {
|
||||||
|
@ -58,15 +59,12 @@ const getOsmInstance = () => osmInstance;
|
||||||
function setOsmInstance(val) {
|
function setOsmInstance(val) {
|
||||||
osmInstance = val;
|
osmInstance = val;
|
||||||
browser.storage.sync.set({ osmInstance })
|
browser.storage.sync.set({ osmInstance })
|
||||||
};
|
}
|
||||||
|
|
||||||
async function redirect(url, initiator) {
|
function redirect(url, initiator) {
|
||||||
await init()
|
if (disableMaps) return null;
|
||||||
if (disableMaps)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (initiator && initiator.host === "earth.google.com")
|
if (initiator && initiator.host === "earth.google.com") return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
let redirect;
|
let redirect;
|
||||||
let link = commonHelper.getRandomInstance(redirects.normal);
|
let link = commonHelper.getRandomInstance(redirects.normal);
|
||||||
|
@ -80,9 +78,9 @@ async function redirect(url, initiator) {
|
||||||
const [lat, lon] = url.searchParams.get("center").split(",");
|
const [lat, lon] = url.searchParams.get("center").split(",");
|
||||||
mapCentre = `#map=${url.searchParams.get("zoom") || "17"}/${lat}/${lon}`;
|
mapCentre = `#map=${url.searchParams.get("zoom") || "17"}/${lat}/${lon}`;
|
||||||
// Set default zoom if mapCentre not present
|
// Set default zoom if mapCentre not present
|
||||||
} else {
|
} else
|
||||||
params = "&zoom=17";
|
params = "&zoom=17";
|
||||||
}
|
|
||||||
// Set map layer
|
// Set map layer
|
||||||
params = `${params}&layers=${layers[url.searchParams.get("layer")] || layers["none"]
|
params = `${params}&layers=${layers[url.searchParams.get("layer")] || layers["none"]
|
||||||
}`;
|
}`;
|
||||||
|
@ -140,6 +138,9 @@ async function redirect(url, initiator) {
|
||||||
return redirect;
|
return redirect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMaps(url) {
|
||||||
|
return url.href.match(targets)
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
|
@ -151,18 +152,12 @@ async function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
|
||||||
redirects,
|
|
||||||
mapCentreRegex,
|
|
||||||
dataLatLngRegex,
|
|
||||||
placeRegex,
|
|
||||||
travelModes,
|
|
||||||
layers,
|
|
||||||
addressToLatLng,
|
addressToLatLng,
|
||||||
getDisableMaps,
|
getDisableMaps,
|
||||||
setDisableMaps,
|
setDisableMaps,
|
||||||
getOsmInstance,
|
getOsmInstance,
|
||||||
setOsmInstance,
|
setOsmInstance,
|
||||||
redirect,
|
redirect,
|
||||||
|
isMaps,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,6 +22,12 @@ let redirects = {
|
||||||
"https://scribe.nixnet.services"
|
"https://scribe.nixnet.services"
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
function setRedirects(val) {
|
||||||
|
redirects = val;
|
||||||
|
browser.storage.sync.set({ mediumRedirects: val })
|
||||||
|
console.log("mediumRedirects: ", val)
|
||||||
|
}
|
||||||
|
|
||||||
let disableMedium;
|
let disableMedium;
|
||||||
const getDisableMedium = () => disableMedium;
|
const getDisableMedium = () => disableMedium;
|
||||||
|
@ -38,8 +44,7 @@ function setScribeInstance(val) {
|
||||||
browser.storage.sync.set({ scribeInstance })
|
browser.storage.sync.set({ scribeInstance })
|
||||||
};
|
};
|
||||||
|
|
||||||
async function redirect(url, initiator) {
|
function redirect(url, initiator) {
|
||||||
await init()
|
|
||||||
if (disableMedium) return null;
|
if (disableMedium) return null;
|
||||||
|
|
||||||
if (url.pathname == "/") return null;
|
if (url.pathname == "/") return null;
|
||||||
|
@ -59,22 +64,35 @@ async function redirect(url, initiator) {
|
||||||
return `${commonHelper.getRandomInstance(redirects.normal)}${url.pathname}${url.search}`;
|
return `${commonHelper.getRandomInstance(redirects.normal)}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMedium(url) {
|
||||||
|
return targets.some((rx) => rx.test(url.host));
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableMedium",
|
"disableMedium",
|
||||||
"scribeInstance",
|
"scribeInstance",
|
||||||
|
"mediumRedirects"
|
||||||
])
|
])
|
||||||
disableMedium = result.disableMedium ?? false;
|
disableMedium = result.disableMedium ?? false;
|
||||||
scribeInstance = result.scribeInstance;
|
scribeInstance = result.scribeInstance;
|
||||||
|
if (result.mediumRedirects)
|
||||||
|
redirects = result.mediumRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
targets,
|
||||||
redirects,
|
|
||||||
|
getRedirects,
|
||||||
|
setRedirects,
|
||||||
|
|
||||||
getDisableMedium,
|
getDisableMedium,
|
||||||
setDisableMedium,
|
setDisableMedium,
|
||||||
|
|
||||||
getScribeInstance,
|
getScribeInstance,
|
||||||
setScribeInstance,
|
setScribeInstance,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
|
isMedium,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,6 +49,20 @@ let redirects = {
|
||||||
"desktop": "https://old.reddit.com", // desktop
|
"desktop": "https://old.reddit.com", // desktop
|
||||||
"mobile": "https://i.reddit.com", // mobile
|
"mobile": "https://i.reddit.com", // mobile
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
|
||||||
|
function setLibredditRedirects(val) {
|
||||||
|
redirects.libreddit = val;
|
||||||
|
browser.storage.sync.set({ redditRedirects: redirects })
|
||||||
|
console.log("libredditRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setTedditRedirects(val) {
|
||||||
|
redirects.teddit = val;
|
||||||
|
browser.storage.sync.set({ redditRedirects: redirects })
|
||||||
|
console.log("tedditRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/;
|
const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/;
|
||||||
|
|
||||||
let disableReddit;
|
let disableReddit;
|
||||||
|
@ -72,8 +86,7 @@ function setRedditFrontend(val) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
async function redirect(url, initiator, type) {
|
function redirect(url, initiator, type) {
|
||||||
await init()
|
|
||||||
if (disableReddit)
|
if (disableReddit)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -112,27 +125,40 @@ async function redirect(url, initiator, type) {
|
||||||
if (redditFrontend == 'teddit') return `${tedditLink}${url.pathname}${url.search}`;
|
if (redditFrontend == 'teddit') return `${tedditLink}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isReddit(url) {
|
||||||
|
return targets.includes(url.host)
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableReddit",
|
"disableReddit",
|
||||||
"redditInstance",
|
"redditInstance",
|
||||||
"redditFrontend",
|
"redditFrontend",
|
||||||
|
"redditRedirects"
|
||||||
])
|
])
|
||||||
disableReddit = result.disableReddit ?? false;
|
disableReddit = result.disableReddit ?? false;
|
||||||
redditInstance = result.redditInstance;
|
redditInstance = result.redditInstance;
|
||||||
redditFrontend = result.redditFrontend ?? 'libreddit';
|
redditFrontend = result.redditFrontend ?? 'libreddit';
|
||||||
|
if (result.redditRedirects)
|
||||||
|
redirects = result.redditRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
targets,
|
||||||
redirects,
|
getRedirects,
|
||||||
bypassPaths,
|
setTedditRedirects,
|
||||||
|
setLibredditRedirects,
|
||||||
|
|
||||||
getDisableReddit,
|
getDisableReddit,
|
||||||
setDisableReddit,
|
setDisableReddit,
|
||||||
|
|
||||||
getRedditInstance,
|
getRedditInstance,
|
||||||
setRedditInstance,
|
setRedditInstance,
|
||||||
|
|
||||||
getRedditFrontend,
|
getRedditFrontend,
|
||||||
setRedditFrontend,
|
setRedditFrontend,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
|
isReddit,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -151,6 +151,21 @@ let redirects = {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
|
||||||
|
function setSearxRedirects(val) {
|
||||||
|
redirects.searx = val;
|
||||||
|
browser.storage.sync.set({ searchRedirects: redirects })
|
||||||
|
console.log("searxRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setWhoogleRedirects(val) {
|
||||||
|
redirects.whoogle = val;
|
||||||
|
browser.storage.sync.set({ searchRedirects: redirects })
|
||||||
|
console.log("whoogleRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let disableSearch;
|
let disableSearch;
|
||||||
const getDisableSearch = () => disableSearch;
|
const getDisableSearch = () => disableSearch;
|
||||||
|
@ -175,8 +190,7 @@ function setSearchFrontend(val) {
|
||||||
console.log("searchFrontend: ", searchFrontend)
|
console.log("searchFrontend: ", searchFrontend)
|
||||||
};
|
};
|
||||||
|
|
||||||
async function redirect(url, initiator) {
|
function redirect(url, initiator) {
|
||||||
await init();
|
|
||||||
if (disableSearch)
|
if (disableSearch)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -199,26 +213,41 @@ async function redirect(url, initiator) {
|
||||||
return `${instance}${path}?${searchQuery}`;
|
return `${instance}${path}?${searchQuery}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSearch(url) {
|
||||||
|
return targets.some((rx) => rx.test(url.href));
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableSearch",
|
"disableSearch",
|
||||||
"searchInstance",
|
"searchInstance",
|
||||||
"searchFrontend",
|
"searchFrontend",
|
||||||
|
"searchRedirects",
|
||||||
])
|
])
|
||||||
disableSearch = result.disableSearch ?? false;
|
disableSearch = result.disableSearch ?? false;
|
||||||
searchInstance = result.searchInstance;
|
searchInstance = result.searchInstance;
|
||||||
searchFrontend = result.searchFrontend ?? 'searx';
|
searchFrontend = result.searchFrontend ?? 'searx';
|
||||||
|
if (result.searchRedirects)
|
||||||
|
redirects = result.searchRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
targets,
|
||||||
redirects,
|
isSearch,
|
||||||
|
|
||||||
|
getRedirects,
|
||||||
|
setSearxRedirects,
|
||||||
|
setWhoogleRedirects,
|
||||||
|
|
||||||
getDisableSearch,
|
getDisableSearch,
|
||||||
setDisableSearch,
|
setDisableSearch,
|
||||||
|
|
||||||
getSearchInstance,
|
getSearchInstance,
|
||||||
setSearchInstance,
|
setSearchInstance,
|
||||||
|
|
||||||
getSearchFrontend,
|
getSearchFrontend,
|
||||||
setSearchFrontend,
|
setSearchFrontend,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,19 @@ let redirects = {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
|
||||||
|
function setSimplyTranslateRedirects(val) {
|
||||||
|
redirects.simplyTranslate = val;
|
||||||
|
browser.storage.sync.set({ translateRedirects: redirects })
|
||||||
|
console.log("simplyTranslateRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLingvaRedirects(val) {
|
||||||
|
redirects.lingva = val;
|
||||||
|
browser.storage.sync.set({ translateRedirects: redirects })
|
||||||
|
console.log("lingvaRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
let disableTranslate;
|
let disableTranslate;
|
||||||
const getDisableTranslate = () => disableTranslate;
|
const getDisableTranslate = () => disableTranslate;
|
||||||
|
@ -54,8 +67,7 @@ function setFrontend(val) {
|
||||||
console.log("Translate frontend: ", frontend)
|
console.log("Translate frontend: ", frontend)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function redirect(url, initiator) {
|
function redirect(url, initiator) {
|
||||||
await init()
|
|
||||||
if (disableTranslate) {
|
if (disableTranslate) {
|
||||||
console.log("SImplyTranslte disabled")
|
console.log("SImplyTranslte disabled")
|
||||||
return null
|
return null
|
||||||
|
@ -81,29 +93,43 @@ async function redirect(url, initiator) {
|
||||||
else
|
else
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isTranslate(url) {
|
||||||
|
return targets.includes(url.host)
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableTranslate",
|
"disableTranslate",
|
||||||
"simplyTranslateInstance",
|
"simplyTranslateInstance",
|
||||||
"translateFrontend"
|
"translateFrontend",
|
||||||
|
"translateRedirects"
|
||||||
]);
|
]);
|
||||||
disableTranslate = result.disableTranslate ?? false;
|
disableTranslate = result.disableTranslate ?? false;
|
||||||
simplyTranslateInstance = result.simplyTranslateInstance;
|
simplyTranslateInstance = result.simplyTranslateInstance;
|
||||||
translateFrontend = result.translateFrontend ?? "simplyTransalte";
|
translateFrontend = result.translateFrontend ?? "simplyTransalte";
|
||||||
|
if (result.translateRedirects)
|
||||||
|
redirects = result.translateRedirects
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
getRedirects,
|
||||||
redirects,
|
setSimplyTranslateRedirects,
|
||||||
|
setLingvaRedirects,
|
||||||
|
|
||||||
|
isTranslate,
|
||||||
|
|
||||||
getDisableTranslate,
|
getDisableTranslate,
|
||||||
setDisableTranslate,
|
setDisableTranslate,
|
||||||
|
|
||||||
getSimplyTranslateInstance,
|
getSimplyTranslateInstance,
|
||||||
setSimplyTranslateInstance,
|
setSimplyTranslateInstance,
|
||||||
|
|
||||||
getFrontend,
|
getFrontend,
|
||||||
setFrontend,
|
setFrontend,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,6 +43,12 @@ let redirects = {
|
||||||
"http://npf37k3mtzwxreiw52ccs5ay4e6qt2fkcs2ndieurdyn2cuzzsfyfvid.onion",
|
"http://npf37k3mtzwxreiw52ccs5ay4e6qt2fkcs2ndieurdyn2cuzzsfyfvid.onion",
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
function setRedirects(val) {
|
||||||
|
redirects = val;
|
||||||
|
browser.storage.sync.set({ twitterRedirects: val })
|
||||||
|
console.log("twitterRedirects:", val)
|
||||||
|
}
|
||||||
|
|
||||||
let disableTwitter;
|
let disableTwitter;
|
||||||
const getDisableTwitter = () => disableTwitter;
|
const getDisableTwitter = () => disableTwitter;
|
||||||
|
@ -58,9 +64,7 @@ function setNitterInstance(val) {
|
||||||
browser.storage.sync.set({ nitterInstance })
|
browser.storage.sync.set({ nitterInstance })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function redirect(url, initiator) {
|
||||||
async function redirect(url, initiator) {
|
|
||||||
await init();
|
|
||||||
if (disableTwitter)
|
if (disableTwitter)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -91,22 +95,33 @@ async function redirect(url, initiator) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isTwitter(url) {
|
||||||
|
return targets.includes(url.host)
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableTwitter",
|
"disableTwitter",
|
||||||
"nitterInstance"
|
"nitterInstance",
|
||||||
|
"twitterRedirects"
|
||||||
]);
|
]);
|
||||||
disableTwitter = result.disableTwitter ?? false;
|
disableTwitter = result.disableTwitter ?? false;
|
||||||
nitterInstance = result.nitterInstance;
|
nitterInstance = result.nitterInstance;
|
||||||
|
if (result.twitterRedirects)
|
||||||
|
redirects = result.twitterRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
getRedirects,
|
||||||
redirects,
|
setRedirects,
|
||||||
|
|
||||||
getDisableTwitter,
|
getDisableTwitter,
|
||||||
setDisableTwitter,
|
setDisableTwitter,
|
||||||
|
|
||||||
getNitterInstance,
|
getNitterInstance,
|
||||||
setNitterInstance,
|
setNitterInstance,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
|
isTwitter,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import commonHelper from './common.js'
|
||||||
|
|
||||||
const targets = /wikipedia.org/;
|
const targets = /wikipedia.org/;
|
||||||
|
|
||||||
let redirects = {
|
let redirects = {
|
||||||
|
@ -5,6 +7,12 @@ let redirects = {
|
||||||
"https://wikiless.org"
|
"https://wikiless.org"
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
function setRedirects(val) {
|
||||||
|
redirects = val;
|
||||||
|
browser.storage.sync.set({ wikipediaRedirects: val })
|
||||||
|
console.log("wikipediaRedirects: ", val)
|
||||||
|
}
|
||||||
|
|
||||||
let disableWikipedia;
|
let disableWikipedia;
|
||||||
const getDisableWikipedia = () => disableWikipedia;
|
const getDisableWikipedia = () => disableWikipedia;
|
||||||
|
@ -20,8 +28,7 @@ function setWikipediaInstance(val) {
|
||||||
browser.storage.sync.set({ wikipediaInstance })
|
browser.storage.sync.set({ wikipediaInstance })
|
||||||
};
|
};
|
||||||
|
|
||||||
async function redirect(url, initiator) {
|
function redirect(url, initiator) {
|
||||||
await init()
|
|
||||||
if (disableWikipedia) return null;
|
if (disableWikipedia) return null;
|
||||||
|
|
||||||
let GETArguments = [];
|
let GETArguments = [];
|
||||||
|
@ -33,7 +40,8 @@ async function redirect(url, initiator) {
|
||||||
GETArguments.push([args[0], args[1]]);
|
GETArguments.push([args[0], args[1]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let link = `${wikipediaInstance}${url.pathname}`;
|
let instance = wikipediaInstance ?? commonHelper.getRandomInstance(redirects.normal)
|
||||||
|
let link = `${instance}${url.pathname}`;
|
||||||
let urlSplit = url.host.split(".");
|
let urlSplit = url.host.split(".");
|
||||||
if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") {
|
if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") {
|
||||||
if (urlSplit[0] == "m")
|
if (urlSplit[0] == "m")
|
||||||
|
@ -55,22 +63,33 @@ async function redirect(url, initiator) {
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isWikipedia(url) {
|
||||||
|
return url.host.match(targets);
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
let result = await browser.storage.sync.get([
|
let result = await browser.storage.sync.get([
|
||||||
"disableWikipedia",
|
"disableWikipedia",
|
||||||
"wikipediaInstance",
|
"wikipediaInstance",
|
||||||
|
"wikipediaRedirects"
|
||||||
]);
|
]);
|
||||||
disableWikipedia = result.disableWikipedia ?? false;
|
disableWikipedia = result.disableWikipedia ?? false;
|
||||||
wikipediaInstance = result.wikipediaInstance;
|
wikipediaInstance = result.wikipediaInstance;
|
||||||
|
if (result.wikipediaRedirects)
|
||||||
|
redirects = result.wikipediaRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
getRedirects,
|
||||||
redirects,
|
setRedirects,
|
||||||
|
|
||||||
setDisableWikipedia,
|
setDisableWikipedia,
|
||||||
getDisableWikipedia,
|
getDisableWikipedia,
|
||||||
|
|
||||||
setWikipediaInstance,
|
setWikipediaInstance,
|
||||||
getWikipediaInstance,
|
getWikipediaInstance,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
|
isWikipedia,
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,6 +49,12 @@ let redirects = {
|
||||||
"http://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion",
|
"http://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion",
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
const getRedirects = () => redirects;
|
||||||
|
function setRedirects(val) {
|
||||||
|
redirects = val;
|
||||||
|
browser.storage.sync.set({ youtubeRedirects: val })
|
||||||
|
console.log("youtubeRedirects: ", val)
|
||||||
|
}
|
||||||
|
|
||||||
let disableYoutube;
|
let disableYoutube;
|
||||||
const getDisableYoutube = () => disableYoutube;
|
const getDisableYoutube = () => disableYoutube;
|
||||||
|
@ -106,7 +112,6 @@ function setInvidiousVolume(val) {
|
||||||
console.log("invidiousVolume: ", invidiousVolume)
|
console.log("invidiousVolume: ", invidiousVolume)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let invidiousPlayerStyle;
|
let invidiousPlayerStyle;
|
||||||
const getInvidiousPlayerStyle = () => invidiousPlayerStyle;
|
const getInvidiousPlayerStyle = () => invidiousPlayerStyle;
|
||||||
function setInvidiousPlayerStyle(val) {
|
function setInvidiousPlayerStyle(val) {
|
||||||
|
@ -139,7 +144,6 @@ function setUseFreeTube(val) {
|
||||||
}
|
}
|
||||||
const getUseFreeTube = () => useFreeTube;
|
const getUseFreeTube = () => useFreeTube;
|
||||||
|
|
||||||
|
|
||||||
let persistInvidiousPrefs;
|
let persistInvidiousPrefs;
|
||||||
function setPersistInvidiousPrefs(val) {
|
function setPersistInvidiousPrefs(val) {
|
||||||
persistInvidiousPrefs = val;
|
persistInvidiousPrefs = val;
|
||||||
|
@ -149,8 +153,7 @@ function setPersistInvidiousPrefs(val) {
|
||||||
}
|
}
|
||||||
const getPersistInvidiousPrefs = () => persistInvidiousPrefs;
|
const getPersistInvidiousPrefs = () => persistInvidiousPrefs;
|
||||||
|
|
||||||
async function redirect(url, initiator, type) {
|
function redirect(url, initiator, type) {
|
||||||
await init();
|
|
||||||
if (disableYoutube)
|
if (disableYoutube)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -193,6 +196,9 @@ async function redirect(url, initiator, type) {
|
||||||
return `${randomInstance}${url.pathname.replace("/shorts", "")}${url.search}`;
|
return `${randomInstance}${url.pathname.replace("/shorts", "")}${url.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isYoutube(url) {
|
||||||
|
return targets.includes(url.host);
|
||||||
|
}
|
||||||
|
|
||||||
function getCookie() {
|
function getCookie() {
|
||||||
let ca = document.cookie.split(";");
|
let ca = document.cookie.split(";");
|
||||||
|
@ -233,6 +239,7 @@ async function init() {
|
||||||
"invidiousSubtitles",
|
"invidiousSubtitles",
|
||||||
"invidiousAutoplay",
|
"invidiousAutoplay",
|
||||||
"useFreeTube",
|
"useFreeTube",
|
||||||
|
"youtubeRedirects"
|
||||||
]);
|
]);
|
||||||
disableYoutube = result.disableYoutube ?? false;
|
disableYoutube = result.disableYoutube ?? false;
|
||||||
invidiousInstance = result.invidiousInstance;
|
invidiousInstance = result.invidiousInstance;
|
||||||
|
@ -246,13 +253,17 @@ async function init() {
|
||||||
invidiousAutoplay = result.invidiousAutoplay ?? true;
|
invidiousAutoplay = result.invidiousAutoplay ?? true;
|
||||||
useFreeTube = result.useFreeTube ?? false;
|
useFreeTube = result.useFreeTube ?? false;
|
||||||
|
|
||||||
|
if (result.youtubeRedirects)
|
||||||
|
redirects = result.youtubeRedirects
|
||||||
|
|
||||||
if (result.persistInvidiousPrefs) initInvidiousCookie();
|
if (result.persistInvidiousPrefs) initInvidiousCookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
targets,
|
getRedirects,
|
||||||
redirects,
|
setRedirects,
|
||||||
redirect,
|
redirect,
|
||||||
|
isYoutube,
|
||||||
|
|
||||||
getDisableYoutube,
|
getDisableYoutube,
|
||||||
setDisableYoutube,
|
setDisableYoutube,
|
||||||
|
|
|
@ -12,6 +12,7 @@ import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
||||||
|
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
|
function wholeInit() {
|
||||||
mapsHelper.init()
|
mapsHelper.init()
|
||||||
searchHelper.init()
|
searchHelper.init()
|
||||||
translateHelper.init()
|
translateHelper.init()
|
||||||
|
@ -21,7 +22,11 @@ redditHelper.init()
|
||||||
twitterHelper.init()
|
twitterHelper.init()
|
||||||
wikipediaHelper.init()
|
wikipediaHelper.init()
|
||||||
youtubeHelper.init()
|
youtubeHelper.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
wholeInit();
|
||||||
|
|
||||||
|
browser.storage.onChanged.addListener(wholeInit);
|
||||||
|
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
async (details) => {
|
async (details) => {
|
||||||
|
@ -34,23 +39,23 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
|
|
||||||
var newUrl;
|
var newUrl;
|
||||||
|
|
||||||
if (youtubeHelper.targets.includes(url.host)) newUrl = await youtubeHelper.redirect(url, initiator, details.type)
|
if (youtubeHelper.isYoutube(url)) newUrl = youtubeHelper.redirect(url, initiator, details.type)
|
||||||
|
|
||||||
else if (twitterHelper.targets.includes(url.host)) newUrl = await twitterHelper.redirect(url, initiator);
|
else if (twitterHelper.isTwitter(url)) newUrl = twitterHelper.redirect(url, initiator);
|
||||||
|
|
||||||
else if (instagramHelper.targets.includes(url.host)) newUrl = await instagramHelper.redirect(url, initiator, details.type);
|
else if (instagramHelper.isInstagram(url)) newUrl = instagramHelper.redirect(url, initiator, details.type);
|
||||||
|
|
||||||
else if (url.href.match(mapsHelper.targets)) newUrl = await mapsHelper.redirect(url, initiator);
|
else if (mapsHelper.isMaps(url)) newUrl = mapsHelper.redirect(url, initiator);
|
||||||
|
|
||||||
else if (redditHelper.targets.includes(url.host)) newUrl = await redditHelper.redirect(url, initiator, details.type);
|
else if (redditHelper.isReddit(url)) newUrl = redditHelper.redirect(url, initiator, details.type);
|
||||||
|
|
||||||
else if (mediumHelper.targets.some((rx) => rx.test(url.host))) newUrl = await mediumHelper.redirect(url, initiator);
|
else if (mediumHelper.isMedium(url)) newUrl = mediumHelper.redirect(url, initiator);
|
||||||
|
|
||||||
else if (translateHelper.targets.includes(url.host)) newUrl = await translateHelper.redirect(url, initiator);
|
else if (translateHelper.isTranslate(url)) newUrl = translateHelper.redirect(url, initiator);
|
||||||
|
|
||||||
else if (searchHelper.targets.some((rx) => rx.test(url.href))) newUrl = await searchHelper.redirect(url, initiator)
|
else if (searchHelper.isSearch(url)) newUrl = searchHelper.redirect(url, initiator)
|
||||||
|
|
||||||
else if (url.host.match(wikipediaHelper.targets)) newUrl = await wikipediaHelper.redirect(url, initiator);
|
else if (wikipediaHelper.isWikipedia(url)) newUrl = wikipediaHelper.redirect(url, initiator);
|
||||||
|
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
console.info("Redirecting", url.href, "=>", newUrl);
|
console.info("Redirecting", url.href, "=>", newUrl);
|
||||||
|
@ -62,7 +67,6 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
["blocking"]
|
["blocking"]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
browser.tabs.onUpdated.addListener((tabId, changeInfo, _) => {
|
browser.tabs.onUpdated.addListener((tabId, changeInfo, _) => {
|
||||||
let url;
|
let url;
|
||||||
try {
|
try {
|
||||||
|
@ -73,19 +77,19 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, _) => {
|
||||||
var protocolHost = `${url.protocol}//${url.host}`;
|
var protocolHost = `${url.protocol}//${url.host}`;
|
||||||
var mightyList = [];
|
var mightyList = [];
|
||||||
mightyList.push(
|
mightyList.push(
|
||||||
...youtubeHelper.redirects.normal,
|
...youtubeHelper.getRedirects().normal,
|
||||||
...twitterHelper.redirects.normal,
|
...twitterHelper.getRedirects().normal,
|
||||||
...instagramHelper.redirects.normal,
|
...instagramHelper.getRedirects().normal,
|
||||||
...redditHelper.redirects.libreddit.normal,
|
...redditHelper.getRedirects().libreddit.normal,
|
||||||
...redditHelper.redirects.teddit.normal,
|
...redditHelper.getRedirects().teddit.normal,
|
||||||
redditHelper.redirects.desktop,
|
redditHelper.getRedirects().desktop,
|
||||||
redditHelper.redirects.mobile,
|
redditHelper.getRedirects().mobile,
|
||||||
...searchHelper.redirects.searx.normal,
|
...searchHelper.getRedirects().searx.normal,
|
||||||
...searchHelper.redirects.whoogle.normal,
|
...searchHelper.getRedirects().whoogle.normal,
|
||||||
...translateHelper.redirects.simplyTranslate.normal,
|
...translateHelper.getRedirects().simplyTranslate.normal,
|
||||||
...translateHelper.redirects.lingva.normal,
|
...translateHelper.getRedirects().lingva.normal,
|
||||||
...mediumHelper.redirects.normal,
|
...mediumHelper.getRedirects().normal,
|
||||||
...wikipediaHelper.redirects.normal
|
...wikipediaHelper.getRedirects().normal
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mightyList.includes(protocolHost)) browser.pageAction.show(tabId);
|
if (mightyList.includes(protocolHost)) browser.pageAction.show(tabId);
|
||||||
|
@ -96,14 +100,14 @@ browser.pageAction.onClicked.addListener((tab) => {
|
||||||
var tabUrl = new URL(tab.url);
|
var tabUrl = new URL(tab.url);
|
||||||
var protocolHost = `${tabUrl.protocol}//${tabUrl.host}`;
|
var protocolHost = `${tabUrl.protocol}//${tabUrl.host}`;
|
||||||
var newUrl;
|
var newUrl;
|
||||||
if (youtubeHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://youtube.com';
|
|
||||||
|
|
||||||
if (twitterHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://twitter.com';
|
if (youtubeHelper.getRedirects().normal.includes(protocolHost)) newUrl = 'https://youtube.com';
|
||||||
|
|
||||||
if (instagramHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://instagram.com';
|
if (twitterHelper.getRedirects().normal.includes(protocolHost)) newUrl = 'https://twitter.com';
|
||||||
|
|
||||||
|
if (instagramHelper.getRedirects().normal.includes(protocolHost)) newUrl = 'https://instagram.com';
|
||||||
|
|
||||||
if (redditHelper.redirects.libreddit.normal.includes(protocolHost) || redditHelper.redirects.teddit.normal.includes(protocolHost)) {
|
if (redditHelper.getRedirects().libreddit.normal.includes(protocolHost) || redditHelper.getRedirects().teddit.normal.includes(protocolHost)) {
|
||||||
if (tabUrl.pathname.startsWith('/img')) {
|
if (tabUrl.pathname.startsWith('/img')) {
|
||||||
newUrl = "https://i.redd.it"
|
newUrl = "https://i.redd.it"
|
||||||
tabUrl.href = tabUrl.href.replace("/img", "")
|
tabUrl.href = tabUrl.href.replace("/img", "")
|
||||||
|
@ -113,18 +117,18 @@ browser.pageAction.onClicked.addListener((tab) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
searchHelper.redirects.searx.normal.includes(protocolHost) ||
|
searchHelper.getRedirects().searx.normal.includes(protocolHost) ||
|
||||||
searchHelper.redirects.whoogle.normal.includes(protocolHost)
|
searchHelper.getRedirects().whoogle.normal.includes(protocolHost)
|
||||||
) newUrl = 'https://google.com';
|
) newUrl = 'https://google.com';
|
||||||
|
|
||||||
if (
|
if (
|
||||||
translateHelper.redirects.simplyTranslate.normal.includes(protocolHost) ||
|
translateHelper.getRedirects().simplyTranslate.normal.includes(protocolHost) ||
|
||||||
translateHelper.redirects.lingva.normal.includes(protocolHost)
|
translateHelper.getRedirects().lingva.normal.includes(protocolHost)
|
||||||
) newUrl = 'https://translate.google.com';
|
) newUrl = 'https://translate.google.com';
|
||||||
|
|
||||||
if (mediumHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://medium.com';
|
if (mediumHelper.getRedirects().normal.includes(protocolHost)) newUrl = 'https://medium.com';
|
||||||
|
|
||||||
if (wikipediaHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://wikipedia.com';
|
if (wikipediaHelper.getRedirects().normal.includes(protocolHost)) newUrl = 'https://wikipedia.com';
|
||||||
|
|
||||||
if (newUrl) browser.tabs.update({ url: tabUrl.href.replace(protocolHost, newUrl) });
|
if (newUrl) browser.tabs.update({ url: tabUrl.href.replace(protocolHost, newUrl) });
|
||||||
});
|
});
|
|
@ -54,9 +54,9 @@ function addToExceptions() {
|
||||||
try {
|
try {
|
||||||
let value = input.value;
|
let value = input.value;
|
||||||
new RegExp(input.value);
|
new RegExp(input.value);
|
||||||
if (type === "URL") {
|
if (type === "URL")
|
||||||
value = value.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
value = value.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
||||||
}
|
|
||||||
exceptions.push(value);
|
exceptions.push(value);
|
||||||
browser.storage.sync.set({
|
browser.storage.sync.set({
|
||||||
exceptions: exceptions,
|
exceptions: exceptions,
|
||||||
|
|
Loading…
Reference in New Issue