aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-21 17:14:56 +0800
committercrupest <crupest@outlook.com>2020-10-21 17:14:56 +0800
commit4e24defd1b658dbfb85320e23b09dc1c0b6ad87b (patch)
treeda68d7565454bae54b12153db4badb839c806640
parentf16c2ceeda27989f40379f2993fa8eac896637d1 (diff)
downloadcrupest-4e24defd1b658dbfb85320e23b09dc1c0b6ad87b.tar.gz
crupest-4e24defd1b658dbfb85320e23b09dc1c0b6ad87b.tar.bz2
crupest-4e24defd1b658dbfb85320e23b09dc1c0b6ad87b.zip
import(ProxyChanger): Allow to set proxy url.
-rw-r--r--works/ProxyChanger/manifest.json6
-rw-r--r--works/ProxyChanger/popup/popup.html2
-rw-r--r--works/ProxyChanger/popup/popup.js53
-rw-r--r--works/ProxyChanger/settings/settings.css9
-rw-r--r--works/ProxyChanger/settings/settings.html30
-rw-r--r--works/ProxyChanger/settings/settings.js14
6 files changed, 92 insertions, 22 deletions
diff --git a/works/ProxyChanger/manifest.json b/works/ProxyChanger/manifest.json
index b2f1be5..d37af97 100644
--- a/works/ProxyChanger/manifest.json
+++ b/works/ProxyChanger/manifest.json
@@ -3,10 +3,14 @@
"name": "Proxy Changer",
"version": "1.0",
"description": "A proxy changer.",
- "permissions": ["proxy"],
+ "permissions": ["proxy", "storage"],
"browser_action": {
"default_icon": "icons/black_circle.png",
"default_title": "Change proxy.",
"default_popup": "popup/popup.html"
+ },
+ "options_ui": {
+ "page": "settings/settings.html",
+ "browser_style": true
}
}
diff --git a/works/ProxyChanger/popup/popup.html b/works/ProxyChanger/popup/popup.html
index 8f082df..16e4bd0 100644
--- a/works/ProxyChanger/popup/popup.html
+++ b/works/ProxyChanger/popup/popup.html
@@ -10,6 +10,8 @@
<div id="direct_button" class="button">Direct</div>
<div id="system_button" class="button">System</div>
<div id="proxy_button" class="button">Proxy</div>
+ <hr />
+ <div id="settings_button" class="button">Settings</div>
<script src="popup.js"></script>
</body>
</html>
diff --git a/works/ProxyChanger/popup/popup.js b/works/ProxyChanger/popup/popup.js
index 31c1384..0615035 100644
--- a/works/ProxyChanger/popup/popup.js
+++ b/works/ProxyChanger/popup/popup.js
@@ -22,26 +22,37 @@ browser.proxy.settings.get({}).then(({ value }) => {
}
});
-const proxyConfigs = {
- direct: {
- proxyType: "none",
- },
- system: {
- proxyType: "system",
- },
- proxy: {
- proxyType: "manual",
- http: "http://localhost:8888",
- httpProxyAll: true,
- },
-};
+browser.storage.local.get("proxyUrl").then(({ proxyUrl }) => {
+ console.log("Saved proxy url is ", proxyUrl);
+
+ const proxyConfigs = {
+ direct: {
+ proxyType: "none",
+ },
+ system: {
+ proxyType: "system",
+ },
+ proxy: {
+ proxyType: "manual",
+ http: proxyUrl,
+ httpProxyAll: true,
+ },
+ };
-for (const key in buttons) {
- buttons[key].addEventListener("click", () => {
- browser.proxy.settings.set({ value: proxyConfigs[key] }).then((success) => {
- if (success) {
- setSelectedButton(key);
- }
+ for (const key in buttons) {
+ buttons[key].addEventListener("click", () => {
+ console.log("Try to set proxy to ", proxyConfigs[key]);
+ browser.proxy.settings
+ .set({ value: proxyConfigs[key] })
+ .then((success) => {
+ if (success) {
+ setSelectedButton(key);
+ }
+ });
});
- });
-}
+ }
+});
+
+document.getElementById("settings_button").addEventListener("click", () => {
+ browser.runtime.openOptionsPage();
+});
diff --git a/works/ProxyChanger/settings/settings.css b/works/ProxyChanger/settings/settings.css
new file mode 100644
index 0000000..50ee923
--- /dev/null
+++ b/works/ProxyChanger/settings/settings.css
@@ -0,0 +1,9 @@
+.proxy-url-div {
+ display: flex;
+ align-items: center;
+}
+
+.proxy-url-div input {
+ margin-left: 1em;
+ flex: 1 1 auto;
+}
diff --git a/works/ProxyChanger/settings/settings.html b/works/ProxyChanger/settings/settings.html
new file mode 100644
index 0000000..1883a2a
--- /dev/null
+++ b/works/ProxyChanger/settings/settings.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <link rel="stylesheet" href="settings.css" />
+ <link rel="stylesheet" href="chrome://browser/content/extension.css" />
+ </head>
+
+ <body>
+ <p>
+ If this proxy does not work, go to settings page and allow it to access
+ private windows. That is a must for setting proxy for extensions.
+ </p>
+ <p>
+ Input your custom manual proxy server. Feel free to make a XSS attack. If
+ you succeed to do that, report a bug to me, or maybe mozilla!
+ </p>
+ <p>
+ After input, re-click the button in popup in toolbar to activate it! I bet
+ you don't change this frequently so it's not a pain.
+ </p>
+ <p>Do at your own risk if you input an invalid url!</p>
+ <div class="browser-style proxy-url-div">
+ <label for="proxy_url">http_proxy</label>
+ <input id="proxy_url" type="text" />
+ </div>
+ <script src="settings.js"></script>
+ </body>
+</html>
diff --git a/works/ProxyChanger/settings/settings.js b/works/ProxyChanger/settings/settings.js
new file mode 100644
index 0000000..ec10c0c
--- /dev/null
+++ b/works/ProxyChanger/settings/settings.js
@@ -0,0 +1,14 @@
+browser.storage.local.get("proxyUrl").then(({ proxyUrl }) => {
+ console.log("Saved proxy url is", proxyUrl);
+ document.getElementById("proxy_url").value = proxyUrl;
+ document.getElementById("proxy_url").addEventListener("input", (e) => {
+ const { value } = e.currentTarget;
+ browser.storage.local
+ .set({
+ proxyUrl: value,
+ })
+ .then(() => {
+ console.log("New proxy url saved!", value);
+ });
+ });
+});