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 currentOrigin;
|
||||||
|
let supportedProtocols = ["https:", "http:"];
|
||||||
|
|
||||||
/*
|
// based upon examples in https://github.com/mdn/webextensions-examples
|
||||||
* Switches currentTab to reflect the currently active tab
|
function updateActiveTab(tab, ocl) {
|
||||||
* source: https://github.com/mdn/webextensions-examples/blob/91c8d7e7086fbc7bdb3032a217e63cc44a3b9320/bookmark-it/background.js
|
if (tab) {
|
||||||
*/
|
let urla = document.createElement('a');
|
||||||
function updateActiveTab(tabs) {
|
urla.href = tab.url;
|
||||||
let supportedProtocols = ["https:", "http:"];
|
let newOrigin = urla.origin;
|
||||||
|
if (supportedProtocols.indexOf(urla.protocol) != -1 /* && currentOrigin != newOrigin */) {
|
||||||
function updateTab(tabs) {
|
currentOrigin = newOrigin;
|
||||||
if (tabs[0]) {
|
(async () => {
|
||||||
currentTab = tabs[0];
|
let resp = await fetch(newOrigin + "/.env", {
|
||||||
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", {
|
|
||||||
"credentials": "omit",
|
"credentials": "omit",
|
||||||
"redirect": "error",
|
"redirect": "error",
|
||||||
"referrerPolicy": "no-referrer"
|
"referrerPolicy": "no-referrer"
|
||||||
})
|
});
|
||||||
.then(r => r.text())
|
if (resp.ok) {
|
||||||
.then(text => {
|
let text = await resp.text();
|
||||||
console.log(".env contains:\n" + text);
|
console.log(".env contains:\n" + text);
|
||||||
storage.local.set({ `${newOrigin}`: 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
|
// listen to tab URL changes
|
||||||
browser.tabs.onUpdated.addListener(updateActiveTab);
|
//browser.tabs.onUpdated.addListener(updateActiveTab);
|
||||||
|
|
||||||
// listen to tab switching
|
// 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",
|
"version": "0.1",
|
||||||
"description": "fetches .env for every visited website and records successfully fetched ones",
|
"description": "fetches .env for every visited website and records successfully fetched ones",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"activeTab",
|
"storage",
|
||||||
|
"tabs",
|
||||||
"*://*/*"
|
"*://*/*"
|
||||||
],
|
],
|
||||||
"background": {
|
"background": {
|
||||||
|
|
Loading…
Reference in a new issue