Hiding pageAction btn when not in instances
This commit is contained in:
parent
ee3e611bd6
commit
05453901f2
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "LibRedirect",
|
||||
"description": "Redirects Twitter, YouTube, Instagram and more to privacy friendly alternatives.",
|
||||
"name": "libredirect",
|
||||
"description": "Redirects YouTube, Twitter, Instagram and more to privacy friendly frontends.",
|
||||
"engines": {
|
||||
"node": ">=10.0.0",
|
||||
"npm": ">=5.6.0"
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
"<all_urls>"
|
||||
],
|
||||
"page_action": {
|
||||
"show_matches": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"default_title": "Change Instance",
|
||||
"default_icon": {
|
||||
"16": "assets/images/libredirect.svg",
|
||||
|
|
|
@ -547,8 +547,7 @@ function redirectMedium(url, initiator) {
|
|||
});
|
||||
return null;
|
||||
}
|
||||
return `${
|
||||
scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
|
||||
return `${scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
|
||||
}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
|
@ -616,8 +615,8 @@ function redirectWikipedia(url, initiator) {
|
|||
else return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var tabList = []
|
||||
var redirecting = false;
|
||||
browser.webRequest.onBeforeRequest.addListener(
|
||||
(details) => {
|
||||
const url = new URL(details.url);
|
||||
|
@ -674,6 +673,10 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
};
|
||||
}
|
||||
if (redirect && redirect.redirectUrl) {
|
||||
redirecting = true;
|
||||
if (!tabList.includes(details.tabId))
|
||||
tabList.push(details.tabId);
|
||||
|
||||
console.info(
|
||||
"Redirecting",
|
||||
`"${url.href}"`,
|
||||
|
@ -681,6 +684,9 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
`"${redirect.redirectUrl}"`
|
||||
);
|
||||
console.info("Details", details);
|
||||
} else {
|
||||
if (!redirecting)
|
||||
tabList = tabList.filter((val) => val != details.tabId);
|
||||
}
|
||||
return redirect;
|
||||
},
|
||||
|
@ -690,6 +696,14 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
["blocking"]
|
||||
);
|
||||
|
||||
browser.tabs.onUpdated.addListener((tabId, _, __) => {
|
||||
if (tabList.includes(tabId))
|
||||
browser.pageAction.show(tabId);
|
||||
})
|
||||
|
||||
browser.webRequest.onCompleted.addListener(() => {
|
||||
redirecting = false;
|
||||
}, { urls: ["<all_urls>"] });
|
||||
|
||||
|
||||
browser.runtime.onInstalled.addListener((details) => {
|
||||
|
|
Loading…
Reference in New Issue