This commit is contained in:
parent
8c50b3a9aa
commit
7f52254c6b
9 changed files with 1635 additions and 14 deletions
6
common.ts
Normal file
6
common.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface Storage {
|
||||
active: boolean,
|
||||
host: string,
|
||||
port: number,
|
||||
bypass: string[];
|
||||
}
|
18
eslint.config.js
Normal file
18
eslint.config.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import eslint from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
{
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['*.js'],
|
||||
...tseslint.configs.disableTypeChecked,
|
||||
}
|
||||
);
|
|
@ -6,7 +6,8 @@
|
|||
"default_popup": "options.html"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "worker.js"
|
||||
"service_worker": "worker.js",
|
||||
"type": "module"
|
||||
},
|
||||
"permissions": [
|
||||
"proxy",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<head>
|
||||
<title>Proxy Settings</title>
|
||||
<script src="options.js"></script>
|
||||
<script src="options.js" type="module"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
21
options.ts
21
options.ts
|
@ -1,17 +1,21 @@
|
|||
function saveProxy() {
|
||||
import { Storage } from './common';
|
||||
|
||||
async function saveProxy() {
|
||||
let active = (document.getElementById("proxyActive") as HTMLInputElement).checked;
|
||||
const host = (document.getElementById("proxyHost") as HTMLInputElement).value;
|
||||
const port = (document.getElementById("proxyPort") as HTMLInputElement).value;
|
||||
const port = (document.getElementById("proxyPort") as HTMLInputElement).valueAsNumber;
|
||||
const bypass = (document.getElementById("proxyBypass") 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), bypass: bypass.split("\n") });
|
||||
await chrome.storage.local.set({ active: active, host: host, port: port, bypass: bypass.split("\n") });
|
||||
}
|
||||
window.addEventListener("DOMContentLoaded", async () => {
|
||||
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", saveProxy);
|
||||
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]);
|
||||
async function fillForm() {
|
||||
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", () => {
|
||||
void saveProxy();
|
||||
});
|
||||
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]) as Storage;
|
||||
if (active) {
|
||||
(document.getElementById("proxyActive") as HTMLInputElement).checked = active;
|
||||
}
|
||||
|
@ -19,9 +23,12 @@ window.addEventListener("DOMContentLoaded", async () => {
|
|||
(document.getElementById("proxyHost") as HTMLInputElement).value = host;
|
||||
}
|
||||
if (port) {
|
||||
(document.getElementById("proxyPort") as HTMLInputElement).value = port;
|
||||
(document.getElementById("proxyPort") as HTMLInputElement).valueAsNumber = port;
|
||||
}
|
||||
if (bypass) {
|
||||
(document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n");
|
||||
}
|
||||
}
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
void fillForm();
|
||||
});
|
||||
|
|
1585
package-lock.json
generated
1585
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,12 @@
|
|||
{
|
||||
"name": "chromium-proxy-settings",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/chrome": "^0.0.260",
|
||||
"crx3": "^1.1.3",
|
||||
"typescript": "^5.3.3"
|
||||
"eslint": "^8.56.0",
|
||||
"typescript": "^5.3.3",
|
||||
"typescript-eslint": "^7.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"module": "es2022",
|
||||
"outDir": "out",
|
||||
"strict": true
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { Storage } from './common';
|
||||
|
||||
async function applyProxy() {
|
||||
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]);
|
||||
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]) as Storage;
|
||||
if (!active) {
|
||||
chrome.proxy.settings.clear({ scope: "regular" }, function () { });
|
||||
return;
|
||||
|
@ -17,5 +19,5 @@ async function applyProxy() {
|
|||
};
|
||||
chrome.proxy.settings.set({ value: config, scope: "regular" }, function () { });
|
||||
}
|
||||
chrome.storage.onChanged.addListener(applyProxy);
|
||||
applyProxy();
|
||||
chrome.storage.onChanged.addListener(() => { void applyProxy(); });
|
||||
void applyProxy();
|
||||
|
|
Loading…
Add table
Reference in a new issue