-
Notifications
You must be signed in to change notification settings - Fork 0
/
japaclocker.html
187 lines (165 loc) · 8.01 KB
/
japaclocker.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Japa Tally Counter with Round & Mantra List</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
display: flex;
flex-direction: column;
width: 90%;
height: 90%;
}
.mantras, .rounds {
display: flex;
flex: 1;
border: 1px solid #ccc;
}
.log {
flex: 1;
display: flex;
justify-content: flex-start;
align-items: top;
padding-right: 10px;
}
.count {
flex: 1;
display: flex;
justify-content: flex-start;
align-items: center;
font-size: 80px;
}
ul {
padding: 10px;
max-height: 300px;
overflow-y: auto;
}
/* Media query for landscape mode */
@media (orientation: landscape) {
.container {
flex-direction: row;
}
}
</style>
</head>
<body>
<div class="container" id="clickableArea">
<audio id="clickSound" src="data:audio/mp3;base64,//uQxAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAAFGADS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS//////////////////////////////////////////////////////////////////8AAAA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Kp4xOzDJA1MAgsxoDzJiDNKIEycIzBwnMnEMxoPQSFiqQwEfUyEvy6yBBFNORkTAnKiqsT0yuExZ0oK+VS6tjrLK7S/lljowQGTAYGDAUmMOgIxKDB0EqymEgKvFWIwADx4KAgAoAkelVUxACCf/////4LitLNwNGJmX0bpPK8sEV2mUkqj1//////+m1l9Wlpf+tqmjVW9W3CJkA7AEQGIsTeW0gpcW8lImpLXGFOwoaffVat5olCUtgXHy72SSTbkkmxHRk+SQan0JJEkST1MCQARZL/+zDEHYPXKejuHPYACAAANIAAAASwNhGMnmSSTUMEQChSptZk59kxMT2I6EIGylMJRk9pyYmNzkxPcatq21rW+Zmcs9b5mZm1rW/WVv1rWbWtMzMzM721rNrayttta9OW/GnrbWbLuy1vmdmd6Zma1/a1rOWtNrWnZm05M702tWctb9ZW/Va7WctabW/ay0u4KeKVTEFNRTMuMTA=" preload="auto"></audio>
<!-- Rounds container -->
<div class="rounds">
<div class="log">
<ul id="roundList"></ul>
</div>
<div class="count">
<h2 id="roundDisplay">0</h2>
</div>
</div>
<!-- Mantras container -->
<div class="mantras" id="mantrasArea">
<div class="log">
<ul id="mantraList"></ul>
</div>
<div class="count">
<h2 id="mantraDisplay">0</h2>
</div>
</div>
</div>
<script>
let clickCount = 0; // Total number of clicks
let roundCount = 0; // Completed rounds
let mantraCount = 0; // Mantras in current round
let lastClickTime = null; // Time of the last click
let lastRoundTime = null; // Time of the last completed round
const mala = 108; // Number of mantras per round
const mantraLog = []; // Array to store mantra time logs
const roundLog = []; // Array to store round time logs
const clickSound = new Audio("data:audio/mp3;base64,[]");
// Handle each click
document.getElementById('clickableArea').addEventListener('click', handleClick);
function handleClick() {
document.getElementById('clickSound').play();
if (clickCount === 0 && lastClickTime === null) {
lastClickTime = new Date();
} else {
clickCount++;
roundCount = Math.floor((clickCount - 1) / mala);
mantraCount = clickCount - (roundCount * mala);
// Capture the time between clicks
currentTime = new Date();
mantraTime = ((currentTime - lastClickTime) / 1000).toFixed(1); // Time difference in seconds (ss.s)
logMantra(roundCount, mantraCount, mantraTime);
lastClickTime = currentTime;
}
// process round
if (mantraCount === 1) {
if (roundCount === 0) {
lastRoundTime = currentTime;
} else {
const roundTime = Math.floor((currentTime - lastRoundTime)/15000); // Time in quaters of a minute - 15secs
console.log(roundTime);
const roundedTime = convertToQuarterMinutes(roundTime);
logRound(roundCount - 1, roundedTime);
lastRoundTime = currentTime; // Always update the last round time
}
}
updateDisplay();
}
// Convert time to quarter minutes
function convertToQuarterMinutes(quaters) {
const wholeMinutes = Math.floor(quaters / 4);
const fraction = (quaters % 4);
let quaterStr = "";
if (fraction === 1) quaterStr = "¼";
else if (fraction === 2) quaterStr = "½";
else if (fraction === 3) quaterStr = "¾";
return `${wholeMinutes}${quaterStr ? ` ${quaterStr}` : ""}`;
}
// Reset counter
function resetCounter() {
clickCount = 0;
roundCount = 0;
mantraCount = 0;
lastClickTime = null;
lastRoundTime = null;
mantraLog.length = 0; // Clear the log
roundLog.length = 0;
document.getElementById('mantraList').innerHTML = ""; // Clear the displayed mantra list
document.getElementById('roundList').innerHTML = ""; // Clear the displayed round list
updateDisplay();
}
// Update the displayed round and mantra count
function updateDisplay() {
document.getElementById('roundDisplay').textContent = roundCount;
document.getElementById('mantraDisplay').textContent = mantraCount;
}
// Log and display the mantra time difference
function logMantra(round, mantra, time) {
mantraLog.push({ round, mantra, time });
const listItem = document.createElement('li');
listItem.textContent = `${round + 1}/${mantra} - ${time}s`;
// Prepend the new item to the top of the list
const mantraList = document.getElementById('mantraList');
mantraList.insertBefore(listItem, mantraList.firstChild); // Insert new entry at the top
}
// Log and display the time between rounds
function logRound(round, time) {
roundLog.push({ round, time });
const listItem = document.createElement('li');
listItem.textContent = `${round + 1} - ${time}m`;
// Prepend the new item to the top of the list
const roundList = document.getElementById('roundList');
roundList.insertBefore(listItem, roundList.firstChild); // Insert new entry at the top
}
</script>
</body>
</html>