From ba5973bd966112d973eeb05dda47d65bbef8b0dc Mon Sep 17 00:00:00 2001 From: badcold Date: Sun, 21 Apr 2024 10:22:43 +0200 Subject: [PATCH] extract css and js to separated files --- .gitignore | 1 + index.html | 138 +++++------------------------------------------------ index.js | 78 ++++++++++++++++++++++++++++++ style.css | 32 +++++++++++++ 4 files changed, 124 insertions(+), 125 deletions(-) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 style.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/index.html b/index.html index 4556c38..a9c5036 100644 --- a/index.html +++ b/index.html @@ -2,127 +2,15 @@ - - ClansOfContracts - + + ClansOfContracts + - - let costs=["sheep", "cow", "wool", "bread", "cheese", "whisky"] - let rewards=["cotton", "tobacco", "sugarCane", "upgrade", "expansion", "gold", "hops"] - - function init() { - fetch('contracts.json') - .then(response => response.json()) - .then(json => { - contracts = json; - for (contract of contracts) { - contract.discarded = false; - } - update(); - }) - .catch(error => console.error('Error:', error)); - for (cost of costs) { - checkBox = document.getElementById(cost); - checkBox.addEventListener('change', function() { - update(); - }); - } - for (reward of rewards) { - checkBox = document.getElementById(reward); - checkBox.addEventListener('change', function() { - update(); - }); - } - } - - function update() { - let includedContracts = ""; - let excludedContracts = ""; - for (contract of contracts) { - if (isIncluded(contract)) { - includedContracts += generateContractHtml(contract); - } else { - excludedContracts += generateContractHtml(contract); - } - } - document.getElementById("included").innerHTML = includedContracts; - document.getElementById("excluded").innerHTML = excludedContracts; - } - - function isIncluded(contract) { - let included = true; - for (cost of costs) { - checkBox = document.getElementById(cost); - if (!checkBox.checked && (contract.costs[cost] > 0)) { - included = false; - } - } - for (reward of rewards) { - checkBox = document.getElementById(reward); - if (!checkBox.checked && (contract.rewards[reward] > 0)) { - included = false; - } - } - return included; - } - - function generateContractHtml(contract) { - let position = -(contract.id * 194); - if (contract.discarded) { - return "
X
"; - } else { - return "
"; - } - } - - function toggleDiscard(id) { - for (contract of contracts) { - if (contract.id === id) { - contract.discarded = !contract.discarded; - } - } - update(); - } - - -
+
Costs: @@ -130,8 +18,8 @@ -
-
+
+
Rewards: @@ -140,13 +28,13 @@ -
+
-
-
-
-
-
+
+
+
+
+