-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
162 lines (147 loc) · 6.64 KB
/
index.html
File metadata and controls
162 lines (147 loc) · 6.64 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
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DS Calculator</title>
<!-- Load Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Load external var.js (assumed to contain weightboy, lengthboy, weightgirl, lengthgirl arrays) -->
<script src="var.js"></script>
</head>
<body class="bg-gray-100 flex flex-col min-h-screen items-center justify-center font-sans">
<div class="bg-white rounded-2xl shadow-xl p-8 w-full max-w-md">
<h1 class="text-2xl font-bold text-center text-gray-800 mb-6">Calculatrice de DS</h1>
<form class="space-y-6">
<!-- Date de visite -->
<div>
<label for="date" class="block text-sm font-medium text-gray-700">Date de visite</label>
<input
type="date"
id="date"
name="visitdate"
class="mt-1 block w-full px-4 py-2 bg-gray-50 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
>
</div>
<!-- Gender Selection -->
<div>
<label class="block text-sm font-medium text-gray-700">Genre</label>
<div class="mt-2 flex space-x-4">
<label class="flex items-center">
<input
type="radio"
name="gender"
id="genderboy"
value="boy"
checked
class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300"
>
<span class="ml-2 text-gray-700">Garçon</span>
</label>
<label class="flex items-center">
<input
type="radio"
name="gender"
id="gendergirl"
value="girl"
class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300"
>
<span class="ml-2 text-gray-700">Fille</span>
</label>
</div>
</div>
<!-- Date de naissance -->
<div>
<label for="birthday" class="block text-sm font-medium text-gray-700">Date de naissance</label>
<input
type="date"
id="birthday"
name="birthday"
class="mt-1 block w-full px-4 py-2 bg-gray-50 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
>
</div>
<!-- Poids -->
<div>
<label for="poids" class="block text-sm font-medium text-gray-700">Poids (kg)</label>
<input
type="number"
id="poids"
name="poids"
step="0.1"
placeholder="Entrez le poids"
class="mt-1 block w-full px-4 py-2 bg-gray-50 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
>
</div>
<!-- Taille -->
<div>
<label for="taille" class="block text-sm font-medium text-gray-700">Taille (cm)</label>
<input
type="number"
id="taille"
name="taille"
step="0.1"
placeholder="Entrez la taille"
class="mt-1 block w-full px-4 py-2 bg-gray-50 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
>
</div>
<!-- Calculate Button -->
<button
type="button"
onclick="calc()"
class="w-full bg-blue-600 text-white py-2 px-4 rounded-lg hover:bg-blue-700 transition duration-200"
>
Calculer
</button>
</form>
<!-- Results -->
<div class="mt-6 text-center space-y-2">
<p id="p" class="text-gray-600"></p>
<p id="t" class="text-gray-600"></p>
<p id="dsp" class="text-gray-600"></p>
<p id="dst" class="text-gray-600"></p>
</div>
</div>
<!-- Credits -->
<footer class="mt-6 text-gray-500 text-sm">
Made by <a href="https://www.facebook.com/so.fiz.71/" class="text-blue-600 hover:underline">Oussama Sofi</a> 💙
</footer>
<script>
// Set today's date as default for visit date
const today = new Date();
const dd = String(today.getDate()).padStart(2, '0');
const mm = String(today.getMonth() + 1).padStart(2, '0');
const yyyy = today.getFullYear();
document.getElementById("date").value = `${yyyy}-${mm}-${dd}`;
// Month difference calculation
function monthDiff(d1, d2) {
let months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth();
months += d2.getMonth();
return months <= 0 ? 0 : months;
}
// Main calculation function
function calc() {
const date1 = new Date(document.getElementById("date").value);
const date2 = new Date(document.getElementById("birthday").value);
const age = monthDiff(date2, date1);
const p = age - 1;
const genderboy = document.getElementById("genderboy").checked;
const wp = genderboy ? weightboy[p] : weightgirl[p];
const lp = genderboy ? lengthboy[p] : lengthgirl[p];
const nw = wp[1];
const wet = wp[2];
const nl = lp[1];
const letVal = lp[2];
const w = parseFloat(document.getElementById("poids").value);
const l = parseFloat(document.getElementById("taille").value);
const wds = (w - nw) / wet;
const lds = (l - nl) / letVal;
// Update results
document.getElementById("p").innerHTML = `Poids normal : ${nw} kg`;
document.getElementById("t").innerHTML = `Taille normale : ${nl} cm`;
document.getElementById("dsp").innerHTML = `DS du poids : ${wds.toFixed(2)}`;
document.getElementById("dst").innerHTML = `DS de taille : ${lds.toFixed(2)}`;
}
</script>
</body>
</html>