convert to ts

This commit is contained in:
badcold
2024-04-21 10:22:43 +02:00
parent ba5973bd96
commit 3d14936a99
2 changed files with 13 additions and 12 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.idea .idea
index.js

View File

@@ -8,20 +8,20 @@ function init() {
.then(response => response.json()) .then(response => response.json())
.then(json => { .then(json => {
contracts = json; contracts = json;
for (contract of contracts) { for (const contract of contracts) {
contract.discarded = false; contract.discarded = false;
} }
update(); update();
}) })
.catch(error => console.error('Error:', error)); .catch(error => console.error('Error:', error));
for (cost of costs) { for (const cost of costs) {
checkBox = document.getElementById(cost); let checkBox = document.getElementById(cost);
checkBox.addEventListener('change', function () { checkBox.addEventListener('change', function () {
update(); update();
}); });
} }
for (reward of rewards) { for (const reward of rewards) {
checkBox = document.getElementById(reward); let checkBox = document.getElementById(reward);
checkBox.addEventListener('change', function () { checkBox.addEventListener('change', function () {
update(); update();
}); });
@@ -31,7 +31,7 @@ function init() {
function update() { function update() {
let includedContracts = ""; let includedContracts = "";
let excludedContracts = ""; let excludedContracts = "";
for (contract of contracts) { for (const contract of contracts) {
if (isIncluded(contract)) { if (isIncluded(contract)) {
includedContracts += generateContractHtml(contract); includedContracts += generateContractHtml(contract);
} else { } else {
@@ -44,14 +44,14 @@ function update() {
function isIncluded(contract) { function isIncluded(contract) {
let included = true; let included = true;
for (cost of costs) { for (const cost of costs) {
checkBox = document.getElementById(cost); let checkBox = document.getElementById(cost) as HTMLInputElement;
if (!checkBox.checked && (contract.costs[cost] > 0)) { if (!checkBox.checked && (contract.costs[cost] > 0)) {
included = false; included = false;
} }
} }
for (reward of rewards) { for (const reward of rewards) {
checkBox = document.getElementById(reward); let checkBox = document.getElementById(reward) as HTMLInputElement;
if (!checkBox.checked && (contract.rewards[reward] > 0)) { if (!checkBox.checked && (contract.rewards[reward] > 0)) {
included = false; included = false;
} }
@@ -69,7 +69,7 @@ function generateContractHtml(contract) {
} }
function toggleDiscard(id) { function toggleDiscard(id) {
for (contract of contracts) { for (const contract of contracts) {
if (contract.id === id) { if (contract.id === id) {
contract.discarded = !contract.discarded; contract.discarded = !contract.discarded;
} }