diff options
author | crupest <crupest@outlook.com> | 2020-10-21 16:28:59 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-21 16:28:59 +0800 |
commit | f16c2ceeda27989f40379f2993fa8eac896637d1 (patch) | |
tree | fc13eabb5c954415fa6167909d21512072f3e251 | |
download | crupest-f16c2ceeda27989f40379f2993fa8eac896637d1.tar.gz crupest-f16c2ceeda27989f40379f2993fa8eac896637d1.tar.bz2 crupest-f16c2ceeda27989f40379f2993fa8eac896637d1.zip |
import(ProxyChanger): Init.
-rw-r--r-- | works/ProxyChanger/icons/black_circle.png | bin | 0 -> 16533 bytes | |||
-rw-r--r-- | works/ProxyChanger/manifest.json | 12 | ||||
-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 |
5 files changed, 102 insertions, 0 deletions
diff --git a/works/ProxyChanger/icons/black_circle.png b/works/ProxyChanger/icons/black_circle.png Binary files differnew file mode 100644 index 0000000..311762a --- /dev/null +++ b/works/ProxyChanger/icons/black_circle.png diff --git a/works/ProxyChanger/manifest.json b/works/ProxyChanger/manifest.json new file mode 100644 index 0000000..b2f1be5 --- /dev/null +++ b/works/ProxyChanger/manifest.json @@ -0,0 +1,12 @@ +{
+ "manifest_version": 2,
+ "name": "Proxy Changer",
+ "version": "1.0",
+ "description": "A proxy changer.",
+ "permissions": ["proxy"],
+ "browser_action": {
+ "default_icon": "icons/black_circle.png",
+ "default_title": "Change proxy.",
+ "default_popup": "popup/popup.html"
+ }
+}
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);
+ }
+ });
+ });
+}
|