Initial commit

This commit is contained in:
2021-07-13 23:11:58 +02:00
commit 96063abc3a
9 changed files with 228 additions and 0 deletions

31
popup/choose_url.js Normal file
View File

@@ -0,0 +1,31 @@
function listenForClicks() {
document.addEventListener("click", function (e) {
if (!e.target.classList.contains("button")) {
return;
}
browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
browser.tabs.sendMessage(tabs[0].id, {
command: "switch_base_url",
baseUrl: e.target.getAttribute("data-url"),
});
});
});
}
function setUrls(settings) {
document.querySelector("#local").setAttribute("data-url", settings.local);
document.querySelector("#test").setAttribute("data-url", settings.test);
document.querySelector("#prod").setAttribute("data-url", settings.prod);
}
function onError(e) {
console.error(e);
}
const gettingStoredSettings = browser.storage.local.get();
gettingStoredSettings.then(setUrls, onError);
browser.tabs
.executeScript({ file: "/content_scripts/base-url-switcher.js" })
.then(listenForClicks);