-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
160 lines (145 loc) · 5.41 KB
/
index.html
File metadata and controls
160 lines (145 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Strompreisrechner</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.container {
background: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
}
h1 {
text-align: center;
font-size: 1.5em;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input {
width: calc(100% - 16px); /* Adjust width to account for padding */
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1em;
}
.output {
margin-top: 20px;
font-size: 1em;
background: #f9f9f9;
padding: 15px;
border-radius: 4px;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}
.reset-button {
display: flex;
justify-content: flex-end;
margin-top: -10px;
}
.reset-button button {
background: none;
border: none;
font-size: 1.2em;
cursor: pointer;
}
.reset-button button:hover {
color: #ff5733;
}
</style>
</head>
<body>
<div class="container">
<h1>Strompreisrechner</h1>
<div class="reset-button">
<button id="reset-button" title="Zurücksetzen">🔄</button>
</div>
<label for="watt">Wattzahl (W):</label>
<input type="number" id="watt" value="10" min="0" step="1">
<label for="price">Strompreis (€ pro kWh):</label>
<input type="number" id="price" value="0.3000" min="0" step="0.0001">
<label for="hours">Laufzeit pro Tag (Stunden):</label>
<input type="number" id="hours" value="24" min="0" max="24" step="1">
<div class="output">
<p id="daily">Tägliche Kosten: 0 kWh / 0.0000 €</p>
<p id="monthly">Monatliche Kosten: 0 kWh / 0.0000 €</p>
<p id="yearly">Jährliche Kosten: 0 kWh / 0.0000 €</p>
</div>
</div>
<script>
const wattInput = document.getElementById('watt');
const priceInput = document.getElementById('price');
const hoursInput = document.getElementById('hours');
const dailyOutput = document.getElementById('daily');
const monthlyOutput = document.getElementById('monthly');
const yearlyOutput = document.getElementById('yearly');
const resetButton = document.getElementById('reset-button');
// Load values from localStorage
const loadLocalValues = () => {
const savedPrice = localStorage.getItem('strompreis');
const savedHours = localStorage.getItem('laufzeit');
if (savedPrice) priceInput.value = parseFloat(savedPrice).toFixed(4);
if (savedHours) hoursInput.value = parseInt(savedHours, 10);
};
// Save values to localStorage
const saveLocalValues = () => {
localStorage.setItem('strompreis', priceInput.value);
localStorage.setItem('laufzeit', hoursInput.value);
};
// Calculate and display costs
const calculateCosts = () => {
const watt = parseFloat(wattInput.value) || 0;
const price = parseFloat(priceInput.value) || 0;
const hours = parseFloat(hoursInput.value) || 0;
const dailyConsumption = (watt * hours) / 1000; // in kWh
const dailyCost = dailyConsumption * price;
const monthlyConsumption = dailyConsumption * 30; // in kWh
const monthlyCost = monthlyConsumption * price;
const yearlyConsumption = dailyConsumption * 365; // in kWh
const yearlyCost = yearlyConsumption * price;
dailyOutput.textContent = `Tägliche Kosten: ${dailyConsumption.toFixed(2)} kWh / ${dailyCost.toFixed(4)} €`;
monthlyOutput.textContent = `Monatliche Kosten: ${monthlyConsumption.toFixed(2)} kWh / ${monthlyCost.toFixed(4)} €`;
yearlyOutput.textContent = `Jährliche Kosten: ${yearlyConsumption.toFixed(2)} kWh / ${yearlyCost.toFixed(4)} €`;
};
// Reset watt and hours to default
const resetInputs = () => {
wattInput.value = 10;
hoursInput.value = 24;
calculateCosts();
};
// Event listeners
wattInput.addEventListener('input', calculateCosts);
priceInput.addEventListener('input', () => {
saveLocalValues();
calculateCosts();
});
hoursInput.addEventListener('input', () => {
saveLocalValues();
calculateCosts();
});
resetButton.addEventListener('click', resetInputs);
// Initialize
loadLocalValues();
calculateCosts();
</script>
</body>
</html>