Initial commit
This commit is contained in:
15
popup/choose_url.css
Normal file
15
popup/choose_url.css
Normal file
@@ -0,0 +1,15 @@
|
||||
html, body {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.button {
|
||||
width: 100%;
|
||||
padding: 4px;
|
||||
font-size: 1.5em;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: #CFF2F2;
|
||||
}
|
||||
18
popup/choose_url.html
Normal file
18
popup/choose_url.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="choose_url.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="popup-content">
|
||||
<div id="local" class="button" data-url="">Local</div>
|
||||
<div id="test" class="button" data-url="">Test</div>
|
||||
<div id="prod" class="button" data-url="">Production</div>
|
||||
</div>
|
||||
<script src="choose_url.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
31
popup/choose_url.js
Normal file
31
popup/choose_url.js
Normal 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);
|
||||
Reference in New Issue
Block a user