Merge pull request #3 from ManeraKai/change-instance-btn
Change instance btn
This commit is contained in:
commit
5fa9ff1de3
|
@ -14,7 +14,25 @@
|
|||
"48": "assets/images/icon48.png",
|
||||
"128": "assets/images/icon128.png"
|
||||
},
|
||||
"permissions": ["storage", "webRequest", "webRequestBlocking", "<all_urls>"],
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"storage",
|
||||
"webRequest",
|
||||
"webRequestBlocking",
|
||||
"<all_urls>"
|
||||
],
|
||||
"page_action": {
|
||||
"show_matches": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"default_title": "Change Instance",
|
||||
"default_icon": {
|
||||
"16": "assets/images/icon16.png",
|
||||
"32": "assets/images/icon32.png",
|
||||
"48": "assets/images/icon48.png",
|
||||
"128": "assets/images/icon128.png"
|
||||
}
|
||||
},
|
||||
"browser_action": {
|
||||
"default_title": "Privacy Redirect",
|
||||
"default_popup": "pages/popup/popup.html",
|
||||
|
@ -34,7 +52,9 @@
|
|||
"*://pbs.twimg.com/*",
|
||||
"*://video.twimg.com/*"
|
||||
],
|
||||
"js": ["assets/javascripts/remove-twitter-sw.js"],
|
||||
"js": [
|
||||
"assets/javascripts/remove-twitter-sw.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
},
|
||||
{
|
||||
|
@ -63,7 +83,9 @@
|
|||
"*://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion/*",
|
||||
"*://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion/*"
|
||||
],
|
||||
"js": ["assets/javascripts/persist-invidious-prefs.js"],
|
||||
"js": [
|
||||
"assets/javascripts/persist-invidious-prefs.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
|
@ -71,11 +93,13 @@
|
|||
"page": "pages/options/options.html",
|
||||
"open_in_tab": false
|
||||
},
|
||||
"web_accessible_resources": ["assets/javascripts/helpers/*"],
|
||||
"web_accessible_resources": [
|
||||
"assets/javascripts/helpers/*"
|
||||
],
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "{b7f9d2cd-d772-4302-8c3f-eb941af36f76}",
|
||||
"strict_min_version": "67.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -138,8 +138,8 @@ browser.storage.sync.get(
|
|||
invidiousDarkMode = result.invidiousDarkMode;
|
||||
exceptions = result.exceptions
|
||||
? result.exceptions.map((e) => {
|
||||
return new RegExp(e);
|
||||
})
|
||||
return new RegExp(e);
|
||||
})
|
||||
: [];
|
||||
invidiousVolume = result.invidiousVolume;
|
||||
invidiousPlayerStyle = result.invidiousPlayerStyle;
|
||||
|
@ -323,9 +323,8 @@ function redirectYouTube(url, initiator, type) {
|
|||
url.searchParams.append("autoplay", 1);
|
||||
}
|
||||
|
||||
return `${
|
||||
invidiousInstance || commonHelper.getRandomInstance(invidiousRandomPool)
|
||||
}${url.pathname.replace("/shorts", "")}${url.search}`;
|
||||
return `${invidiousInstance || commonHelper.getRandomInstance(invidiousRandomPool)
|
||||
}${url.pathname.replace("/shorts", "")}${url.search}`;
|
||||
}
|
||||
|
||||
function redirectTwitter(url, initiator) {
|
||||
|
@ -348,17 +347,14 @@ function redirectTwitter(url, initiator) {
|
|||
return null;
|
||||
}
|
||||
if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") {
|
||||
return `${
|
||||
nitterInstance || commonHelper.getRandomInstance(nitterRandomPool)
|
||||
}/pic/${encodeURIComponent(url.href)}`;
|
||||
return `${nitterInstance || commonHelper.getRandomInstance(nitterRandomPool)
|
||||
}/pic/${encodeURIComponent(url.href)}`;
|
||||
} else if (url.pathname.split("/").includes("tweets")) {
|
||||
return `${
|
||||
nitterInstance || commonHelper.getRandomInstance(nitterRandomPool)
|
||||
}${url.pathname.replace("/tweets", "")}${url.search}`;
|
||||
return `${nitterInstance || commonHelper.getRandomInstance(nitterRandomPool)
|
||||
}${url.pathname.replace("/tweets", "")}${url.search}`;
|
||||
} else {
|
||||
return `${
|
||||
nitterInstance || commonHelper.getRandomInstance(nitterRandomPool)
|
||||
}${url.pathname}${url.search}`;
|
||||
return `${nitterInstance || commonHelper.getRandomInstance(nitterRandomPool)
|
||||
}${url.pathname}${url.search}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,14 +379,12 @@ function redirectInstagram(url, initiator, type) {
|
|||
url.pathname === "/" ||
|
||||
instagramReservedPaths.includes(url.pathname.split("/")[1])
|
||||
) {
|
||||
return `${
|
||||
bibliogramInstance || commonHelper.getRandomInstance(bibliogramRandomPool)
|
||||
}${url.pathname}${url.search}`;
|
||||
return `${bibliogramInstance || commonHelper.getRandomInstance(bibliogramRandomPool)
|
||||
}${url.pathname}${url.search}`;
|
||||
} else {
|
||||
// Likely a user profile, redirect to '/u/...'
|
||||
return `${
|
||||
bibliogramInstance || commonHelper.getRandomInstance(bibliogramRandomPool)
|
||||
}/u${url.pathname}${url.search}`;
|
||||
return `${bibliogramInstance || commonHelper.getRandomInstance(bibliogramRandomPool)
|
||||
}/u${url.pathname}${url.search}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,9 +410,8 @@ function redirectGoogleMaps(url, initiator) {
|
|||
params = "&zoom=17";
|
||||
}
|
||||
// Set map layer
|
||||
params = `${params}&layers=${
|
||||
layers[url.searchParams.get("layer")] || layers["none"]
|
||||
}`;
|
||||
params = `${params}&layers=${layers[url.searchParams.get("layer")] || layers["none"]
|
||||
}`;
|
||||
// Handle Google Maps Embed API
|
||||
if (url.pathname.split("/").includes("embed")) {
|
||||
let query = "";
|
||||
|
@ -484,9 +477,8 @@ function redirectGoogleMaps(url, initiator) {
|
|||
} else if (url.pathname.match(placeRegex)) {
|
||||
query = url.pathname.match(placeRegex)[1];
|
||||
}
|
||||
redirect = `${osmInstance}/${query ? "search?query=" + query : ""}${
|
||||
mapCentre || "#"
|
||||
}${params}`;
|
||||
redirect = `${osmInstance}/${query ? "search?query=" + query : ""}${mapCentre || "#"
|
||||
}${params}`;
|
||||
}
|
||||
|
||||
return redirect;
|
||||
|
@ -586,6 +578,8 @@ function redirectGoogleTranslate(url, initiator) {
|
|||
return `${simplyTranslateInstance}/${url.search}`;
|
||||
}
|
||||
|
||||
var oldDomain = '';
|
||||
|
||||
function redirectWikipedia(url, initiator) {
|
||||
if (disableWikipedia || isException(url, initiator)) {
|
||||
return null;
|
||||
|
@ -622,6 +616,8 @@ function redirectWikipedia(url, initiator) {
|
|||
else return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
browser.webRequest.onBeforeRequest.addListener(
|
||||
(details) => {
|
||||
const url = new URL(details.url);
|
||||
|
@ -633,22 +629,27 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
}
|
||||
let redirect;
|
||||
if (youtubeDomains.includes(url.host)) {
|
||||
oldDomain = 'https://youtube.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectYouTube(url, initiator, details.type),
|
||||
};
|
||||
} else if (twitterDomains.includes(url.host)) {
|
||||
oldDomain = 'https://twitter.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectTwitter(url, initiator),
|
||||
};
|
||||
} else if (instagramDomains.includes(url.host)) {
|
||||
oldDomain = 'https://instagram.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectInstagram(url, initiator, details.type),
|
||||
};
|
||||
} else if (url.href.match(googleMapsRegex)) {
|
||||
oldDomain = 'https://maps.google.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectGoogleMaps(url, initiator),
|
||||
};
|
||||
} else if (redditDomains.includes(url.host)) {
|
||||
oldDomain = 'https://reddit.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectReddit(url, initiator, details.type),
|
||||
};
|
||||
|
@ -657,14 +658,17 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
redirectUrl: redirectMedium(url, initiator),
|
||||
};
|
||||
} else if (url.href.match(googleSearchRegex)) {
|
||||
oldDomain = 'https://google.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectSearchEngine(url, initiator),
|
||||
};
|
||||
} else if (googleTranslateDomains.includes(url.host)) {
|
||||
oldDomain = 'https://translate.google.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectGoogleTranslate(url, initiator),
|
||||
};
|
||||
} else if (url.host.match(wikipediaRegex)) {
|
||||
oldDomain = 'https://wikipedia.com/';
|
||||
redirect = {
|
||||
redirectUrl: redirectWikipedia(url, initiator),
|
||||
};
|
||||
|
@ -686,6 +690,8 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
["blocking"]
|
||||
);
|
||||
|
||||
|
||||
|
||||
browser.runtime.onInstalled.addListener((details) => {
|
||||
browser.storage.sync.get(
|
||||
["disableSearchEngine", "disableSimplyTranslate", "disableWikipedia"],
|
||||
|
@ -729,3 +735,21 @@ browser.runtime.onInstalled.addListener((details) => {
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function changeInstance() {
|
||||
browser.tabs.query({
|
||||
active: true,
|
||||
lastFocusedWindow: true
|
||||
}, function (tabs) {
|
||||
var tabUrl = new URL(tabs[0].url);
|
||||
|
||||
if (oldDomain != '') {
|
||||
browser.tabs.update({
|
||||
url: tabUrl.href.replace(`${tabUrl.protocol}//${tabUrl.host}/`, oldDomain)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
browser.pageAction.onClicked.addListener(changeInstance);
|
Loading…
Reference in New Issue