diff options
Diffstat (limited to 'works/ProxyChanger/popup')
| -rw-r--r-- | works/ProxyChanger/popup/popup.css | 28 | ||||
| -rw-r--r-- | works/ProxyChanger/popup/popup.html | 15 | ||||
| -rw-r--r-- | works/ProxyChanger/popup/popup.js | 47 | 
3 files changed, 90 insertions, 0 deletions
| diff --git a/works/ProxyChanger/popup/popup.css b/works/ProxyChanger/popup/popup.css new file mode 100644 index 0000000..97601c2 --- /dev/null +++ b/works/ProxyChanger/popup/popup.css @@ -0,0 +1,28 @@ +html,
 +body {
 +  width: 200px;
 +}
 +
 +body {
 +  margin: 0;
 +}
 +
 +.button {
 +  margin: 0;
 +  padding: 4px 20px;
 +  text-align: center;
 +  font-size: 1.5em;
 +  cursor: pointer;
 +}
 +
 +.button:hover {
 +  background: #97c4ff;
 +}
 +
 +.selected {
 +  background: #4294ff;
 +}
 +
 +.selected:hover {
 +  background: #4294ff;
 +}
 diff --git a/works/ProxyChanger/popup/popup.html b/works/ProxyChanger/popup/popup.html new file mode 100644 index 0000000..8f082df --- /dev/null +++ b/works/ProxyChanger/popup/popup.html @@ -0,0 +1,15 @@ +<!DOCTYPE html>
 +
 +<html>
 +  <head>
 +    <meta charset="utf-8" />
 +    <link rel="stylesheet" href="popup.css" />
 +  </head>
 +
 +  <body>
 +    <div id="direct_button" class="button">Direct</div>
 +    <div id="system_button" class="button">System</div>
 +    <div id="proxy_button" class="button">Proxy</div>
 +    <script src="popup.js"></script>
 +  </body>
 +</html>
 diff --git a/works/ProxyChanger/popup/popup.js b/works/ProxyChanger/popup/popup.js new file mode 100644 index 0000000..31c1384 --- /dev/null +++ b/works/ProxyChanger/popup/popup.js @@ -0,0 +1,47 @@ +const buttons = {
 +  direct: document.getElementById("direct_button"),
 +  system: document.getElementById("system_button"),
 +  proxy: document.getElementById("proxy_button"),
 +};
 +
 +function setSelectedButton(button) {
 +  for (const key in buttons) {
 +    buttons[key].classList.remove("selected");
 +  }
 +  buttons[button].classList.add("selected");
 +}
 +
 +browser.proxy.settings.get({}).then(({ value }) => {
 +  console.log("current proxy settings: ", value);
 +  if (value.proxyType === "none") {
 +    setSelectedButton("direct");
 +  } else if (value.proxyType === "system") {
 +    setSelectedButton("system");
 +  } else if (value.proxyType === "manual") {
 +    setSelectedButton("proxy");
 +  }
 +});
 +
 +const proxyConfigs = {
 +  direct: {
 +    proxyType: "none",
 +  },
 +  system: {
 +    proxyType: "system",
 +  },
 +  proxy: {
 +    proxyType: "manual",
 +    http: "http://localhost:8888",
 +    httpProxyAll: true,
 +  },
 +};
 +
 +for (const key in buttons) {
 +  buttons[key].addEventListener("click", () => {
 +    browser.proxy.settings.set({ value: proxyConfigs[key] }).then((success) => {
 +      if (success) {
 +        setSelectedButton(key);
 +      }
 +    });
 +  });
 +}
 | 
