commit 7a2bf53a77b9dfe809cfe289ae66f10ab8b5d764 Author: Mathieu Strypsteen Date: Sun Feb 18 08:28:00 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..23a608b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*.js diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..0398786 --- /dev/null +++ b/manifest.json @@ -0,0 +1,15 @@ +{ + "manifest_version": 3, + "name": "Proxy Settings", + "version": "0.0.1", + "action": { + "default_popup": "options.html" + }, + "background": { + "service_worker": "worker.js" + }, + "permissions": [ + "proxy", + "storage" + ] +} diff --git a/options.html b/options.html new file mode 100644 index 0000000..303fabc --- /dev/null +++ b/options.html @@ -0,0 +1,23 @@ + + + + + Proxy Settings + + + + +
+ + +
+ + + + +
+ +
+ + + diff --git a/options.ts b/options.ts new file mode 100644 index 0000000..7226eee --- /dev/null +++ b/options.ts @@ -0,0 +1,23 @@ +function setProxy() { + let active = (document.getElementById('proxyActive') as HTMLInputElement).checked; + const host = (document.getElementById('proxyHost') as HTMLInputElement).value; + const port = (document.getElementById('proxyPort') as HTMLInputElement).value; + if (!host || !port) { + active = false; + (document.getElementById('proxyActive') as HTMLInputElement).checked = false; + } + chrome.storage.local.set({ active: active, host: host, port: Number(port) }); +} +window.addEventListener('DOMContentLoaded', async () => { + (document.getElementById("proxySettings") as HTMLInputElement).addEventListener('submit', setProxy); + const { active, host, port } = await chrome.storage.local.get(["active", "host", "port"]); + if (active) { + (document.getElementById("proxyActive") as HTMLInputElement).checked = active; + } + if (host) { + (document.getElementById("proxyHost") as HTMLInputElement).value = host; + } + if (port) { + (document.getElementById("proxyPort") as HTMLInputElement).value = port; + } +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..34d651a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,60 @@ +{ + "name": "chromium-proxy-settings", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "chromium-proxy-settings", + "version": "0.0.1", + "devDependencies": { + "@types/chrome": "^0.0.260", + "typescript": "^5.3.3" + } + }, + "node_modules/@types/chrome": { + "version": "0.0.260", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.260.tgz", + "integrity": "sha512-lX6QpgfsZRTDpNcCJ+3vzfFnFXq9bScFRTlfhbK5oecSAjamsno+ejFTCbNtc5O/TPnVK9Tja/PyecvWQe0F2w==", + "dev": true, + "dependencies": { + "@types/filesystem": "*", + "@types/har-format": "*" + } + }, + "node_modules/@types/filesystem": { + "version": "0.0.35", + "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.35.tgz", + "integrity": "sha512-1eKvCaIBdrD2mmMgy5dwh564rVvfEhZTWVQQGRNn0Nt4ZEnJ0C8oSUCzvMKRA4lGde5oEVo+q2MrTTbV/GHDCQ==", + "dev": true, + "dependencies": { + "@types/filewriter": "*" + } + }, + "node_modules/@types/filewriter": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.33.tgz", + "integrity": "sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g==", + "dev": true + }, + "node_modules/@types/har-format": { + "version": "1.2.15", + "resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.15.tgz", + "integrity": "sha512-RpQH4rXLuvTXKR0zqHq3go0RVXYv/YVqv4TnPH95VbwUxZdQlK1EtcMvQvMpDngHbt13Csh9Z4qT9AbkiQH5BA==", + "dev": true + }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..37ac343 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "chromium-proxy-settings", + "version": "0.0.1", + "devDependencies": { + "@types/chrome": "^0.0.260", + "typescript": "^5.3.3" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a699872 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "target": "es2022", + "strict": true + } +} diff --git a/worker.ts b/worker.ts new file mode 100644 index 0000000..b8c5bc1 --- /dev/null +++ b/worker.ts @@ -0,0 +1,20 @@ +async function apply_proxy() { + const { active, host, port } = await chrome.storage.local.get(["active", "host", "port"]); + if (!active) { + chrome.proxy.settings.clear({ scope: 'regular' }, function () { }); + return; + } + const config = { + mode: "fixed_servers", + rules: { + singleProxy: { + scheme: "socks5", + host: host, + port: port + } + } + }; + chrome.proxy.settings.set({ value: config, scope: 'regular' }, function () { }); +} +apply_proxy(); +chrome.storage.onChanged.addListener(apply_proxy);