make it a toolbar button
This commit is contained in:
parent
06865c4283
commit
02734b5d76
2 changed files with 26 additions and 30 deletions
|
@ -1,41 +1,36 @@
|
|||
let currentTab;
|
||||
let currentOrigin;
|
||||
let supportedProtocols = ["https:", "http:"];
|
||||
|
||||
/*
|
||||
* Switches currentTab to reflect the currently active tab
|
||||
* source: https://github.com/mdn/webextensions-examples/blob/91c8d7e7086fbc7bdb3032a217e63cc44a3b9320/bookmark-it/background.js
|
||||
*/
|
||||
function updateActiveTab(tabs) {
|
||||
let supportedProtocols = ["https:", "http:"];
|
||||
|
||||
function updateTab(tabs) {
|
||||
if (tabs[0]) {
|
||||
currentTab = tabs[0];
|
||||
let urla = document.createElement('a');
|
||||
urla.href = currentTab.url;
|
||||
let newOrigin = urla.origin;
|
||||
if (supportedProtocols.indexOf(urla.protocol) != -1 && currentOrigin != newOrigin) {
|
||||
currentOrigin = newOrigin;
|
||||
fetch(newOrigin + "/.env", {
|
||||
// based upon examples in https://github.com/mdn/webextensions-examples
|
||||
function updateActiveTab(tab, ocl) {
|
||||
if (tab) {
|
||||
let urla = document.createElement('a');
|
||||
urla.href = tab.url;
|
||||
let newOrigin = urla.origin;
|
||||
if (supportedProtocols.indexOf(urla.protocol) != -1 /* && currentOrigin != newOrigin */) {
|
||||
currentOrigin = newOrigin;
|
||||
(async () => {
|
||||
let resp = await fetch(newOrigin + "/.env", {
|
||||
"credentials": "omit",
|
||||
"redirect": "error",
|
||||
"referrerPolicy": "no-referrer"
|
||||
})
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
console.log(".env contains:\n" + text);
|
||||
storage.local.set({ `${newOrigin}`: text });
|
||||
});
|
||||
}
|
||||
});
|
||||
if (resp.ok) {
|
||||
let text = await resp.text();
|
||||
console.log(".env contains:\n" + text);
|
||||
let tmp = {};
|
||||
tmp[newOrigin] = text;
|
||||
browser.storage.local.set(tmp);
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
|
||||
gettingActiveTab.then(updateTab);
|
||||
}
|
||||
|
||||
// listen to tab URL changes
|
||||
browser.tabs.onUpdated.addListener(updateActiveTab);
|
||||
//browser.tabs.onUpdated.addListener(updateActiveTab);
|
||||
|
||||
// listen to tab switching
|
||||
browser.tabs.onActivated.addListener(updateActiveTab);
|
||||
//browser.tabs.onActivated.addListener(updateActiveTab);
|
||||
|
||||
browser.browserAction.onClicked.addListener(updateActiveTab);
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"version": "0.1",
|
||||
"description": "fetches .env for every visited website and records successfully fetched ones",
|
||||
"permissions": [
|
||||
"activeTab",
|
||||
"storage",
|
||||
"tabs",
|
||||
"*://*/*"
|
||||
],
|
||||
"background": {
|
||||
|
|
Loading…
Reference in a new issue