Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
disable the pageshot button on about,data,moz-extension pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Mar 20, 2017
1 parent 0c94071 commit 4caf735
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion addon/webextension/background/main.js
Expand Up @@ -40,8 +40,12 @@ window.main = (function () {
});
}

function opensMyShots(url) {
return /^about:(?:newtab|blank)/i.test(url) || /^resource:\/\/activity-streams\//i.test(url);
}

browser.browserAction.onClicked.addListener(catcher.watchFunction((tab) => {
if (tab.url.match(/about:(newtab|blank)/i)) {
if (opensMyShots(tab.url)) {
catcher.watchPromise(analytics.refreshTelemetryPref().then(() => {
sendEvent("goto-myshots", "about-newtab");
}));
Expand Down Expand Up @@ -77,6 +81,26 @@ window.main = (function () {
.then(() => sendEvent("start-shot", "context-menu")));
}));

function urlEnabled(url) {
if (opensMyShots(url)) {
return true;
}
if (url.startsWith(backend) || /^(?:about|data|moz-extension):/i.test(url)) {
return false;
}
return true;
}

browser.tabs.onUpdated.addListener((id, info, tab) => {
if (info.url && tab.selected) {
if (urlEnabled(info.url)) {
browser.browserAction.enable(tab.id);
}
else {
browser.browserAction.disable(tab.id);
}
}
});

communication.register("sendEvent", (sender, ...args) => {
catcher.watchPromise(sendEvent(...args));
Expand Down
1 change: 1 addition & 0 deletions addon/webextension/manifest.json.template
Expand Up @@ -57,6 +57,7 @@
],
"permissions": [
"activeTab",
"tabs",
"storage",
"notifications",
"clipboardWrite",
Expand Down

0 comments on commit 4caf735

Please sign in to comment.