Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
288 lines (252 loc) · 28.3 KB
/
Copy pathindex.html
File metadata and controls
288 lines (252 loc) · 28.3 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>Cube Timer</title>
<meta name="theme-color" content="#000000"/>
<link rel="apple-touch-icon" href="./icon-192.png">
<link rel="manifest" href="./manifest.json">
<style>
:root {
--bg-dark: #1f2023; --bg-main: #27282c; --bg-sidebar: #191a1c;
--bg-widget: #2d2e32; --text-primary: #e2e2e2; --text-secondary: #9a9a9a;
--border-color: #3a3b40; --accent-blue: #3c82f6; --accent-green: #34d399; --accent-red: #ef4444;
--list-item-odd-bg: #333438;
}
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-main); color: var(--text-primary); margin: 0;
overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.container { display: flex; height: 100vh; }
/* === MASAÜSTÜ ARAYÜZÜ (DEĞİŞTİRİLMEDİ) === */
.sidebar {
width: 260px; background-color: var(--bg-sidebar); padding: 30px 20px;
display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
height: 100%; z-index: 1001; transform: translateX(-100%);
transition: transform 0.3s ease-in-out; box-shadow: 4px 0px 15px rgba(0,0,0,0.2);
}
.sidebar.open { transform: translateX(0); }
.sidebar h1 { font-size: 1.5em; margin: 0 0 40px 10px; font-weight: 600; text-align: center; }
.sidebar nav a { display: block; color: var(--text-secondary); text-decoration: none; padding: 15px 20px; border-radius: 8px; margin-bottom: 10px; font-size: 1.1em; font-weight: 600; text-align: center; transition: all 0.2s; }
.sidebar nav a:hover { background-color: var(--bg-widget); color: var(--text-primary); }
.sidebar nav a.active { background-color: var(--accent-blue); color: white; }
#menu-toggle-btn { position: fixed; top: 20px; left: 20px; z-index: 1002; background: none; border: none; color: var(--text-primary); cursor: pointer; padding: 5px; font-size: 2em; line-height: 1; }
.overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; }
.overlay.active { display: block; }
.main-content { flex-grow: 1; display: flex; flex-direction: column; width: 100%; }
.view { display: none; height: 100%; overflow-y: auto; }
.view.active { display: flex; flex-direction: column; }
#timer-view { padding: 20px 40px; }
.timer-main { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.scramble-container { display: flex; align-items: center; justify-content: center; gap: 15px; padding: 20px 10px 10px; font-size: 1.5em; font-weight: 500; color: var(--text-secondary); line-height: 1.5; }
#new-scramble-btn { background: none; border: none; font-size: 1.2em; color: var(--text-secondary); cursor: pointer; transition: color 0.2s; }
#timer { font-size: min(12vw, 150px); font-weight: 500; color: var(--text-primary); }
.desktop-timer-details { display: grid; grid-template-columns: 2fr 1.5fr 1fr; gap: 20px; width: 100%; padding: 20px 0; }
.solves-container { background-color: var(--bg-widget); padding: 15px; border-radius: 8px; max-height: 250px; display: flex; flex-direction: column; }
.solves-container h3 { margin: 0 0 10px 0; font-weight: 600; text-align: center; }
#solves-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; font-weight: 500; }
#solves-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 5px; cursor: pointer; transition: background-color 0.2s; }
#solves-list li:nth-child(odd) { background-color: var(--list-item-odd-bg); }
.delete-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 1.2em; z-index: 5; }
.stats-box { background-color: var(--bg-widget); border-radius: 8px; padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.stat-item { text-align: center; } .stat-item .label { font-size: 0.9em; color: var(--text-secondary); font-weight: 600; } .stat-item .value { font-size: 1.3em; font-weight: 600; } .stat-item.best .value { color: var(--accent-green); }
.cube-visualization { display: grid; grid-template-columns: repeat(12, 16px); grid-template-rows: repeat(9, 16px); margin: auto; }
.sticker { width: 16px; height: 16px; border: 1.5px solid var(--bg-main); border-radius: 2px; }
#stats-view { padding: 20px 40px; }
#stats-view h2 { font-weight: 600; text-align: center; padding: 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.widget { background-color: var(--bg-widget); padding: 20px; border-radius: 8px; text-align: center; }
.widget h3 { margin-top: 0; font-weight: 600; color: var(--text-secondary); } .widget .value { font-size: 2em; font-weight: 600; } .widget.best .value { color: var(--accent-green); }
.chart-container { margin-top: 30px; height: 400px; }
/* === MOBİL ARAYÜZ === */
#bottom-nav, .mobile-timer-footer { display: none; }
body.is-mobile { background-color: #000; }
body.is-mobile .sidebar, body.is-mobile #menu-toggle-btn, body.is-mobile .desktop-timer-details { display: none; }
body.is-mobile .main-content { height: 100vh; }
body.is-mobile .view { padding: 10px; }
body.is-mobile #timer-view.active { display: flex; flex-direction: column; height: 100%; padding: 0; padding-bottom: calc(65px + 75px); }
body.is-mobile #bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; width: 100%; justify-content: space-around; background-color: #111; border-top: 1px solid var(--border-color); padding: 5px 0; padding-bottom: calc(5px + env(safe-area-inset-bottom)); z-index: 100; flex-shrink: 0; height: 65px; }
body.is-mobile #bottom-nav button { background: none; border: none; color: var(--text-secondary); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; font-weight: 500; }
body.is-mobile #bottom-nav button .icon-background { background-color: var(--bg-widget); border-radius: 8px; width: 45px; height: 32px; display: flex; justify-content: center; align-items: center; margin-bottom: 4px; }
body.is-mobile #bottom-nav button svg { width: 24px; height: 24px; fill: var(--text-primary); }
body.is-mobile #bottom-nav button.active { color: var(--text-primary); }
body.is-mobile #timer-view.active .scramble-container { flex-shrink: 0; flex-direction: column; gap: 5px; padding: 10px; }
body.is-mobile #scramble { font-size: 1em; }
body.is-mobile .timer-main { flex-grow: 1; flex-shrink: 1; min-height: 120px; }
body.is-mobile #timer { font-size: 100px; }
body.is-mobile #timer-view.active .mobile-timer-footer { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding: 10px; flex-shrink: 0; width: 100%; position: absolute; bottom: 65px; left: 0; }
body.is-mobile .stats-col { text-align: left; font-size: 0.8em; line-height: 1.5; } body.is-mobile .stats-col div { display: flex; gap: 5px; } body.is-mobile .stats-col .label { color: var(--text-secondary); } body.is-mobile .stats-col .value { font-weight: 600; }
body.is-mobile .cube-visualization { grid-template-columns: repeat(12, 11px); grid-template-rows: repeat(9, 11px); } body.is-mobile .sticker { width: 11px; height: 11px; border-width: 1px; border-color: #000; }
body.is-mobile #solves-view { padding: 10px; padding-bottom: 75px; }
body.is-mobile #solves-view .solves-header { display: none; }
body.is-mobile .solves-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
body.is-mobile .solve-card { background-color: var(--bg-widget); border-radius: 12px; padding: 15px; text-align: center; cursor: pointer; }
body.is-mobile .solve-card .date { font-size: 0.8em; color: var(--text-secondary); } body.is-mobile .solve-card .time { font-size: 1.5em; font-weight: 600; margin-top: 5px; }
body.is-mobile #stats-view { padding: 10px 0; padding-bottom: 75px; } /* YAN BOŞLUKLAR KALDIRILDI */
body.is-mobile #stats-view h2, body.is-mobile #stats-view .stats-grid { display: none; }
body.is-mobile #stats-view .chart-container { margin-top: 10px; margin-bottom: 10px; }
body.is-mobile .stats-table { background-color: var(--bg-widget); border-radius: 12px; padding: 5px 15px; margin: 0 10px; } /* İçerik için yan boşluk eklendi */
body.is-mobile .stats-table .row { display: flex; justify-content: space-between; padding: 8px 5px; border-bottom: 1px solid var(--border-color); }
body.is-mobile .stats-table .row:last-child { border-bottom: none; } body.is-mobile .stats-table .label { color: var(--text-secondary); font-weight: 500; } body.is-mobile .stats-table .value { font-weight: 600; }
/* Ortak Elemanlar */
.modal { display: none; position: fixed; z-index: 1002; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(5px); justify-content: center; align-items: center; }
.modal-content { background-color: #2d2e32; padding: 20px; border-radius: 12px; border: 1px solid var(--border-color); width: 90%; max-width: 500px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
#modal-time { font-size: 2.5em; font-weight: 600; margin-bottom: 15px; } #modal-scramble { font-size: 1.1em; color: var(--text-secondary); word-wrap: break-word; line-height: 1.6; background-color: #27282c; padding: 10px; border-radius: 5px; font-weight: 500; } #modal-date { font-size: 0.9em; color: var(--text-secondary); margin-top: 20px; font-weight: 500; }
#modal-cube-net { margin: 25px auto; } #modal-cube-net .sticker { border-color: #2d2e32; }
.modal-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: center; }
.modal-btn { padding: 10px 20px; cursor: pointer; border: none; border-radius: 5px; font-size: 1em; font-weight: 600; }
#modal-close { background-color: var(--accent-blue); color: white; }
#modal-delete-btn { background-color: var(--accent-red); color: white; display: none; }
body.is-mobile #modal-delete-btn { display: inline-block; }
</style>
</head>
<body>
<button id="menu-toggle-btn">☰</button>
<div class="overlay" id="overlay"></div>
<div class="container">
<aside class="sidebar" id="sidebar">
<nav id="sidebar-nav"><h1>Cube Timer</h1><a href="#" class="nav-link active" data-view="timer-view">Zamanlayıcı</a><a href="#" class="nav-link" data-view="stats-view">İstatistikler</a></nav>
</aside>
<main class="main-content">
<div id="timer-view" class="view active">
<div class="scramble-container"><p id="scramble">Yükleniyor...</p><button id="new-scramble-btn" title="Yeni Karıştırma">⟳</button></div>
<div class="timer-main" id="timer-touch-area"><h1 id="timer">0.00</h1></div>
<div class="mobile-timer-footer">
<div class="stats-col" id="mobile-stats-left"></div>
<div class="cube-visualization" id="mobile-cube-net"></div>
<div class="stats-col" id="mobile-stats-right" style="text-align: right;"></div>
</div>
<div class="desktop-timer-details">
<div class="solves-container"><h3>Son Çözümler</h3><ul id="solves-list"></ul></div>
<div id="desktop-stats-box" class="stats-box"></div>
<div id="desktop-cube-net" class="cube-visualization"></div>
</div>
</div>
<div id="solves-view" class="view">
<div class="solves-header"></div>
<div class="solves-grid" id="solves-grid"></div>
</div>
<div id="stats-view" class="view">
<h2 class="desktop-only">İstatistikler</h2>
<div class="stats-grid"><div class="widget best"><h3>En İyi Süre (PB)</h3><p class="value" id="stats-pb">-</p></div><div class="widget"><h3>Toplam Çözüm</h3><p class="value" id="stats-total">-</p></div><div class="widget"><h3>Ortalama Süre</h3><p class="value" id="stats-mean">-</p></div></div>
<div class="chart-container widget"><h3>Çözüm Süreleri Grafiği</h3><canvas id="solves-chart"></canvas></div>
<div class="stats-table" id="stats-table"></div>
</div>
</main>
</div>
<div id="solve-details-modal" class="modal"><div class="modal-content"><h2 id="modal-time"></h2><div class="cube-visualization" id="modal-cube-net"></div><p id="modal-scramble"></p><p id="modal-date"></p><div class="modal-actions"><button id="modal-delete-btn" class="modal-btn">Çözümü Sil</button><button id="modal-close" class="modal-btn">Kapat</button></div></div></div>
<nav id="bottom-nav">
<button class="nav-btn active" data-view="timer-view"><div class="icon-background"><svg viewBox="0 0 24 24"><path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"></path><path d="M13 7h-2v5.414l3.293 3.293 1.414-1.414L13 11.586z"></path></svg></div>Zamanlayıcı</button>
<button class="nav-btn" data-view="solves-view"><div class="icon-background"><svg viewBox="0 0 24 24"><path d="M4 6h16v2H4zm0 5h16v2H4zm0 5h16v2H4z"></path></svg></div>Çözümler</button>
<button class="nav-btn" data-view="stats-view"><div class="icon-background"><svg viewBox="0 0 24 24"><path d="M3 3v17a1 1 0 0 0 1 1h17v-2H5V3H3z"></path><path d="M21 5.414-14 18.414l-4.293-4.293-1.414 1.414L14 21.243l12-12L21 5.414z"></path></svg></div>İstatistikler</button>
</nav>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
let timerInterval, time=0, isRunning=false, readyToStart=false, solves=[], currentScramble='', chartInstance=null;
const timerEl=document.getElementById('timer'), scrambleEl=document.getElementById('scramble');
const chartCanvas=document.getElementById('solves-chart');
const timerTouchArea = document.getElementById('timer-touch-area');
const bottomNav = document.getElementById('bottom-nav'), sidebarNav = document.getElementById('sidebar-nav');
const mobileCubeNet = document.getElementById('mobile-cube-net'), desktopCubeNet = document.getElementById('desktop-cube-net');
const newScrambleBtn = document.getElementById('new-scramble-btn');
const modal=document.getElementById('solve-details-modal'), modalCloseBtn=document.getElementById('modal-close'), modalCubeNet=document.getElementById('modal-cube-net');
const modalDeleteBtn = document.getElementById('modal-delete-btn');
const sidebar = document.getElementById('sidebar'), menuToggleBtn = document.getElementById('menu-toggle-btn'), overlay = document.getElementById('overlay');
const solvesListEl = document.getElementById('solves-list');
const colors={W:'#fefefe',G:'#34d399',R:'#ef4444',B:'#3c82f6',O:'#f97316',Y:'#eab308'};
function isMobileDevice(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}
if(isMobileDevice()){document.body.classList.add('is-mobile')}
function createSolvedState(){return[...Array(9).fill('W'),...Array(9).fill('O'),...Array(9).fill('G'),...Array(9).fill('R'),...Array(9).fill('B'),...Array(9).fill('Y')]}
const stickerMap={U:[0,1,2,3,4,5,6,7,8],L:[9,10,11,12,13,14,15,16,17],F:[18,19,20,21,22,23,24,25,26],R:[27,28,29,30,31,32,33,34,35],B:[36,37,38,39,40,41,42,43,44],D:[45,46,47,48,49,50,51,52,53]};
const adjacentMap={U:[38,37,36,29,28,27,20,19,18,11,10,9],D:[15,16,17,24,25,26,33,34,35,42,43,44],F:[6,7,8,27,30,33,47,46,45,15,12,9],B:[2,1,0,17,14,11,51,52,53,29,32,35],L:[0,3,6,18,21,24,45,48,51,44,41,38],R:[8,5,2,36,39,42,53,50,47,26,23,20]};
function rotate(state,face,modifier){const fS=stickerMap[face],aS=adjacentMap[face],t=modifier==="'"?3:(modifier==="2"?2:1);for(let i=0;i<t;i++){const nF=[...fS.map(idx=>state[idx])],rF=[nF[6],nF[3],nF[0],nF[7],nF[4],nF[1],nF[8],nF[5],nF[2]];fS.forEach((idx,j)=>state[idx]=rF[j]);const nA=aS.slice(0,3).map(idx=>state[idx]);for(let j=0;j<9;j++){state[aS[j]]=state[aS[j+3]]}aS.slice(9).forEach((idx,j)=>state[idx]=nA[j])}return state}
function applyScramble(scrambleStr){let state=createSolvedState();scrambleStr.split(' ').filter(m=>m).forEach(move=>state=rotate(state,move[0],move.length>1?move[1]:''));return state}
function createCubeNetHTML(container){const l={U:{r:1,c:4,f:0},L:{r:4,c:1,f:1},F:{r:4,c:4,f:2},R:{r:4,c:7,f:3},B:{r:4,c:10,f:4},D:{r:7,c:4,f:5}};container.innerHTML='';for(const f in l){for(let i=0;i<3;i++){for(let j=0;j<3;j++){const s=document.createElement('div');s.classList.add('sticker');s.style.gridRow=l[f].r+i;s.style.gridColumn=l[f].c+j;s.id=`${container.id}-s-${l[f].f*9+(i*3+j)}`;container.appendChild(s)}}}}
function drawCubeNet(state){drawCubeNetForContainer(mobileCubeNet,state);drawCubeNetForContainer(desktopCubeNet,state);drawCubeNetForContainer(modalCubeNet,state)}
function drawCubeNetForContainer(container,state){if(!container)return;for(let i=0;i<54;i++){const s=document.getElementById(`${container.id}-s-${i}`);if(s)s.style.backgroundColor=colors[state[i]]}}
function formatTime(ms){if(ms===Infinity||isNaN(ms)||ms===null)return'--';return(ms/1000).toFixed(2)}
function startTimer(){time=0;isRunning=true;timerEl.style.color='var(--text-primary)';const sT=Date.now();timerInterval=setInterval(()=>{time=Date.now()-sT;timerEl.textContent=formatTime(time)},10)}
function stopTimer(){isRunning=false;clearInterval(timerInterval);addSolve({time,scramble:currentScramble,date:new Date().toISOString()});generateNewScramble()}
function addSolve(solveData){solves.unshift(solveData);updateAll()}
function deleteSolve(index){solves.splice(index,1);updateAll()}
function updateAll(){saveSolves();renderStats();renderSolves();if(document.getElementById('stats-view').classList.contains('active')){drawChart()}}
function calculateAverage(count,list){if(list.length<count)return null;const times=list.slice(0,count).map(s=>s.time).sort((a,b)=>a-b).slice(1,-1);return times.reduce((a,b)=>a+b,0)/times.length}
function calculateMean(list) { if(list.length === 0) return null; return list.reduce((a, b) => a + b.time, 0) / list.length; }
function calculateStdDev(list) {if(list.length < 2) return null; const mean=calculateMean(list); const times=list.map(s=>s.time); return Math.sqrt(times.map(x=>Math.pow(x - mean, 2)).reduce((a,b)=>a+b)/times.length);}
function renderStats() {
const best=solves.length?Math.min(...solves.map(s=>s.time)):null; const worst=solves.length?Math.max(...solves.map(s=>s.time)):null; const mean=calculateMean(solves); const stdDev=calculateStdDev(solves);
const count=solves.length; const ao5=calculateAverage(5, solves); const ao12=calculateAverage(12, solves); const ao50=calculateAverage(50, solves); const ao100=calculateAverage(100, solves);
document.getElementById('mobile-stats-left').innerHTML = `<div><span class="label">Sapma:</span><span class="value">${formatTime(stdDev)}</span></div><div><span class="label">Ortalama:</span><span class="value">${formatTime(mean)}</span></div><div><span class="label">En iyi:</span><span class="value">${formatTime(best)}</span></div><div><span class="label">Sayılan:</span><span class="value">${count}</span></div>`;
document.getElementById('mobile-stats-right').innerHTML = `<div><span class="label">Ao5:</span><span class="value">${formatTime(ao5)}</span></div><div><span class="label">Ao12:</span><span class="value">${formatTime(ao12)}</span></div><div><span class="label">Ao50:</span><span class="value">${formatTime(ao50)}</span></div><div><span class="label">Ao100:</span><span class="value">${formatTime(ao100)}</span></div>`;
document.getElementById('desktop-stats-box').innerHTML = `<div class="stat-item best"><div class="label">En İyi</div><div class="value">${formatTime(best)}</div></div><div class="stat-item"><div class="label">Ao5</div><div class="value">${formatTime(ao5)}</div></div><div class="stat-item"><div class="label">En Kötü</div><div class="value">${formatTime(worst)}</div></div><div class="stat-item"><div class="label">Ao12</div><div class="value">${formatTime(ao12)}</div></div>`;
document.getElementById('stats-pb').textContent = formatTime(best);
document.getElementById('stats-total').textContent = count;
document.getElementById('stats-mean').textContent = formatTime(mean);
const statsTable = document.getElementById('stats-table');
if(statsTable) { statsTable.innerHTML = `<div class="row"><span class="label">Sapma</span><span class="value">${formatTime(stdDev)}</span></div><div class="row"><span class="label">Ao12</span><span class="value">${formatTime(ao12)}</span></div><div class="row"><span class="label">Ao50</span><span class="value">${formatTime(ao50)}</span></div><div class="row"><span class="label">Ao100</span><span class="value">${formatTime(ao100)}</span></div><div class="row"><span class="label">En İyi</span><span class="value">${formatTime(best)}</span></div><div class="row"><span class="label">Sayılan</span><span class="value">${count}</span></div>`; }
}
function renderSolves() {
const solvesHTML = solves.slice(0,100).map((solve,index) => `<li data-index="${index}"><span>${solves.length-index}. ${formatTime(solve.time)}</span> <button class="delete-btn" title="Sil">🗑️</button></li>`).join('');
solvesListEl.innerHTML = solvesHTML;
document.getElementById('solves-grid').innerHTML = solves.map((solve, index) => { const date=new Date(solve.date); const formattedDate=`${date.getDate().toString().padStart(2,'0')}/${(date.getMonth()+1).toString().padStart(2,'0')}`; return`<div class="solve-card" data-index="${index}"><div class="date">${formattedDate}</div><div class="time">${formatTime(solve.time)}</div></div>`}).join('');
}
function generateNewScramble(){const m=["U","D","L","R","F","B"],d=["","'","2"];let s="",l="";for(let i=0;i<21;i++){let v,a,p=getAxis(l);do{v=m[Math.floor(Math.random()*m.length)];a=getAxis(v)}while(a===p);s+=v+d[Math.floor(Math.random()*d.length)]+" ";l=v}currentScramble=s.trim();scrambleEl.textContent=currentScramble;drawCubeNet(applyScramble(currentScramble))}
function getAxis(move){if(['U','D'].includes(move))return'Y';if(['L','R'].includes(move))return'X';if(['F','B'].includes(move))return'Z';return null}
function handleInteractionStart(){if(isRunning){stopTimer()}else if(!readyToStart){timerEl.textContent='0.00';timerEl.style.color='var(--accent-red)';readyToStart=true}}
function handleInteractionEnd(){if(!isRunning&&readyToStart){timerEl.style.color='var(--accent-green)';startTimer()}readyToStart=false}
function switchView(viewId) {
document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
document.getElementById(viewId).classList.add('active');
if (viewId === 'stats-view') drawChart();
}
function toggleMenu(){sidebar.classList.toggle('open');overlay.classList.toggle('active')}
function setupEventListeners(){
document.addEventListener('keydown',e=>{if(e.code==='Space' && !modal.style.display.includes('flex')){e.preventDefault();handleInteractionStart()}});
document.addEventListener('keyup',e=>{if(e.code==='Space' && !modal.style.display.includes('flex')){handleInteractionEnd()}});
timerTouchArea.addEventListener('touchstart',e=>{if(e.target.closest('#new-scramble-btn') || e.target.closest('.delete-btn')) return; e.preventDefault();handleInteractionStart()});
timerTouchArea.addEventListener('touchend',e=>{if(e.target.closest('#new-scramble-btn') || e.target.closest('.delete-btn')) return; e.preventDefault();handleInteractionEnd()});
newScrambleBtn.addEventListener('click', generateNewScramble);
solvesListEl.addEventListener('click', e => {
const li = e.target.closest('li'); if(!li) return;
const index = parseInt(li.dataset.index);
if (e.target.classList.contains('delete-btn')) { e.stopPropagation(); deleteSolve(index); } else { showSolveDetails(index); }
});
document.getElementById('solves-grid').addEventListener('click', e => {
const card = e.target.closest('.solve-card'); if (!card) return;
const index = parseInt(card.dataset.index);
showSolveDetails(index);
});
bottomNav.addEventListener('click', e => {
const navBtn = e.target.closest('.nav-btn'); if(!navBtn) return;
document.querySelector('#bottom-nav .nav-btn.active').classList.remove('active');
navBtn.classList.add('active'); switchView(navBtn.dataset.view);
});
sidebarNav.addEventListener('click', e => {
e.preventDefault(); const navLink = e.target.closest('.nav-link'); if(!navLink) return;
document.querySelector('#sidebar-nav .nav-link.active').classList.remove('active');
navLink.classList.add('active'); switchView(navLink.dataset.view); toggleMenu();
});
menuToggleBtn.addEventListener('click', toggleMenu);
overlay.addEventListener('click', toggleMenu);
modalCloseBtn.addEventListener('click',()=>modal.style.display='none');
modalDeleteBtn.addEventListener('click', (e) => {
const index = parseInt(e.target.dataset.index);
deleteSolve(index);
modal.style.display = 'none';
});
}
function showSolveDetails(index){const solve=solves[index];document.getElementById('modal-time').textContent=formatTime(solve.time);document.getElementById('modal-scramble').textContent=solve.scramble;document.getElementById('modal-date').textContent=new Date(solve.date).toLocaleString('tr-TR');drawCubeNetForContainer(modalCubeNet,applyScramble(solve.scramble));modalDeleteBtn.dataset.index = index; modal.style.display='flex'}
function drawChart(){if(chartInstance)chartInstance.destroy();const labels=solves.map((_,i)=>solves.length-i).reverse();const data=solves.map(s=>s.time/1000).reverse();const ao5Data = [...new Array(4).fill(null), ...solves.slice(0,solves.length > 4 ? solves.length - 4: 0).map((_,i)=>calculateAverage(5,solves.slice(i))/1000).reverse()]; const ao12Data = [...new Array(11).fill(null), ...solves.slice(0,solves.length > 11 ? solves.length - 11 : 0).map((_,i)=>calculateAverage(12,solves.slice(i))/1000).reverse()]; chartInstance=new Chart(chartCanvas,{type:'line',data:{labels,datasets:[{label:'Her şey',data,borderColor:'#FFF',tension:0.1},{label:'Ao5',data:ao5Data,borderColor:'red',tension:0.1},{label:'Ao12',data:ao12Data,borderColor:'lime',tension:0.1}]},options:{responsive:true,maintainAspectRatio:false}})}
function saveSolves(){localStorage.setItem('cubeTimerFinal',JSON.stringify(solves))}
function loadSolves(){const saved=localStorage.getItem('cubeTimerFinal');if(saved){solves=JSON.parse(saved)}}
function init(){createCubeNetHTML(mobileCubeNet);createCubeNetHTML(desktopCubeNet);createCubeNetHTML(modalCubeNet);loadSolves();generateNewScramble();updateAll();setupEventListeners()}
init();
if('serviceWorker' in navigator){window.addEventListener('load',()=>{navigator.serviceWorker.register('./sw.js').then(reg=>console.log('SW registered.')).catch(err=>console.log('SW registration failed:',err))})}
});
</script>
</body>
</html>