From 3d14936a998ac694a959a1ad606a7806ab1cc2ee Mon Sep 17 00:00:00 2001 From: badcold Date: Sun, 21 Apr 2024 10:22:43 +0200 Subject: [PATCH] convert to ts --- .gitignore | 3 ++- index.js => index.ts | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) rename index.js => index.ts (79%) diff --git a/.gitignore b/.gitignore index 723ef36..88af965 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +index.js \ No newline at end of file diff --git a/index.js b/index.ts similarity index 79% rename from index.js rename to index.ts index 8b362f3..bddd083 100644 --- a/index.js +++ b/index.ts @@ -8,20 +8,20 @@ function init() { .then(response => response.json()) .then(json => { contracts = json; - for (contract of contracts) { + for (const contract of contracts) { contract.discarded = false; } update(); }) .catch(error => console.error('Error:', error)); - for (cost of costs) { - checkBox = document.getElementById(cost); + for (const cost of costs) { + let checkBox = document.getElementById(cost); checkBox.addEventListener('change', function () { update(); }); } - for (reward of rewards) { - checkBox = document.getElementById(reward); + for (const reward of rewards) { + let checkBox = document.getElementById(reward); checkBox.addEventListener('change', function () { update(); }); @@ -31,7 +31,7 @@ function init() { function update() { let includedContracts = ""; let excludedContracts = ""; - for (contract of contracts) { + for (const contract of contracts) { if (isIncluded(contract)) { includedContracts += generateContractHtml(contract); } else { @@ -44,14 +44,14 @@ function update() { function isIncluded(contract) { let included = true; - for (cost of costs) { - checkBox = document.getElementById(cost); + for (const cost of costs) { + let checkBox = document.getElementById(cost) as HTMLInputElement; if (!checkBox.checked && (contract.costs[cost] > 0)) { included = false; } } - for (reward of rewards) { - checkBox = document.getElementById(reward); + for (const reward of rewards) { + let checkBox = document.getElementById(reward) as HTMLInputElement; if (!checkBox.checked && (contract.rewards[reward] > 0)) { included = false; } @@ -69,7 +69,7 @@ function generateContractHtml(contract) { } function toggleDiscard(id) { - for (contract of contracts) { + for (const contract of contracts) { if (contract.id === id) { contract.discarded = !contract.discarded; }