Add eslint
All checks were successful
Build / build (push) Successful in 33s

This commit is contained in:
Mathieu Strypsteen 2024-02-18 14:10:13 +01:00
parent 8c50b3a9aa
commit 7f52254c6b
9 changed files with 1635 additions and 14 deletions

6
common.ts Normal file
View file

@ -0,0 +1,6 @@
export interface Storage {
active: boolean,
host: string,
port: number,
bypass: string[];
}

18
eslint.config.js Normal file
View 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,
}
);

View file

@ -6,7 +6,8 @@
"default_popup": "options.html" "default_popup": "options.html"
}, },
"background": { "background": {
"service_worker": "worker.js" "service_worker": "worker.js",
"type": "module"
}, },
"permissions": [ "permissions": [
"proxy", "proxy",

View file

@ -3,7 +3,7 @@
<head> <head>
<title>Proxy Settings</title> <title>Proxy Settings</title>
<script src="options.js"></script> <script src="options.js" type="module"></script>
</head> </head>
<body> <body>

View file

@ -1,17 +1,21 @@
function saveProxy() { import { Storage } from './common';
async function saveProxy() {
let active = (document.getElementById("proxyActive") as HTMLInputElement).checked; let active = (document.getElementById("proxyActive") as HTMLInputElement).checked;
const host = (document.getElementById("proxyHost") as HTMLInputElement).value; 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; const bypass = (document.getElementById("proxyBypass") as HTMLInputElement).value;
if (!host || !port) { if (!host || !port) {
active = false; active = false;
(document.getElementById("proxyActive") as HTMLInputElement).checked = 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 () => { async function fillForm() {
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", saveProxy); (document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", () => {
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]); void saveProxy();
});
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]) as Storage;
if (active) { if (active) {
(document.getElementById("proxyActive") as HTMLInputElement).checked = active; (document.getElementById("proxyActive") as HTMLInputElement).checked = active;
} }
@ -19,9 +23,12 @@ window.addEventListener("DOMContentLoaded", async () => {
(document.getElementById("proxyHost") as HTMLInputElement).value = host; (document.getElementById("proxyHost") as HTMLInputElement).value = host;
} }
if (port) { if (port) {
(document.getElementById("proxyPort") as HTMLInputElement).value = port; (document.getElementById("proxyPort") as HTMLInputElement).valueAsNumber = port;
} }
if (bypass) { if (bypass) {
(document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n"); (document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n");
} }
}
window.addEventListener("DOMContentLoaded", () => {
void fillForm();
}); });

1585
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,12 @@
{ {
"name": "chromium-proxy-settings", "name": "chromium-proxy-settings",
"version": "0.0.1", "version": "0.0.1",
"type": "module",
"devDependencies": { "devDependencies": {
"@types/chrome": "^0.0.260", "@types/chrome": "^0.0.260",
"crx3": "^1.1.3", "crx3": "^1.1.3",
"typescript": "^5.3.3" "eslint": "^8.56.0",
"typescript": "^5.3.3",
"typescript-eslint": "^7.0.1"
} }
} }

View file

@ -1,6 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es2022", "target": "es2022",
"module": "es2022",
"outDir": "out", "outDir": "out",
"strict": true "strict": true
} }

View file

@ -1,5 +1,7 @@
import { Storage } from './common';
async function applyProxy() { 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) { if (!active) {
chrome.proxy.settings.clear({ scope: "regular" }, function () { }); chrome.proxy.settings.clear({ scope: "regular" }, function () { });
return; return;
@ -17,5 +19,5 @@ async function applyProxy() {
}; };
chrome.proxy.settings.set({ value: config, scope: "regular" }, function () { }); chrome.proxy.settings.set({ value: config, scope: "regular" }, function () { });
} }
chrome.storage.onChanged.addListener(applyProxy); chrome.storage.onChanged.addListener(() => { void applyProxy(); });
applyProxy(); void applyProxy();