-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (115 loc) · 3.9 KB
/
script.js
File metadata and controls
133 lines (115 loc) · 3.9 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
const UI = {
form: document.querySelector('#taskForm'),
input: document.querySelector('#taskInput'),
addBtn: document.querySelector('#addBtn'),
taskList: document.querySelector('#taskList'),
empty: document.querySelector('#emptyState'),
count: document.querySelector('#activeCount'),
perc: document.querySelector('#progressPercent'),
arc: document.querySelector('#progressArc'),
orb: document.querySelector('#light-orb'),
time: document.querySelector('#liveTime'),
reset: document.querySelector('#resetBtn'),
status: document.querySelector('#statusLabel')
};
/**
* Uygulamayı başlatan ana fonksiyon
*/
const init = () => {
// 1. Saat fonksiyonunu her saniye güncelle
updateClock();
setInterval(updateClock, 1000);
// 2. Mouse hareketini dinleyerek arka plan orbu hareket ettir (Parallax)
document.addEventListener('mousemove', (e) => {
const x = e.clientX - 175;
const y = e.clientY - 175;
UI.orb.style.transform = `translate(${x}px, ${y}px)`;
});
// 3. Event Listener'lar
UI.addBtn.onclick = addTask;
UI.form.onsubmit = (e) => { e.preventDefault(); addTask(); };
UI.reset.onclick = resetData;
// 4. İlk yüklemede verileri getir
render();
};
const updateClock = () => {
const now = new Date();
UI.time.innerText = now.toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' });
};
/**
* LocalStorage'dan görevleri çekme
*/
const getTasks = () => JSON.parse(localStorage.getItem('semantic_tasks_v2')) || [];
/**
* Yeni görev ekleme mantığı
*/
function addTask() {
const text = UI.input.value.trim();
if (!text) {
UI.input.placeholder = "Lütfen bir şeyler yazın...";
return;
}
const tasks = getTasks();
tasks.unshift(text); // Yeni görevi en başa ekle
localStorage.setItem('semantic_tasks_v2', JSON.stringify(tasks));
UI.input.value = '';
UI.input.placeholder = "Sıradaki büyük adım nedir?";
render();
}
/**
* Belirli bir görevi silme
* (Window objesine bağlayarak inline onclick çalışmasını sağlıyoruz)
*/
window.deleteTask = (index) => {
const tasks = getTasks();
tasks.splice(index, 1);
localStorage.setItem('semantic_tasks_v2', JSON.stringify(tasks));
render();
};
/**
* Tüm sistemi sıfırlama
*/
function resetData() {
if (confirm('Dikkat! Tüm görevleriniz kalıcı olarak silinecektir. Onaylıyor musunuz?')) {
localStorage.removeItem('semantic_tasks_v2');
render();
}
}
/**
* Arayüzü güncelleyen ana render fonksiyonu
*/
function render() {
const tasks = getTasks();
UI.taskList.innerHTML = '';
// Empty State Kontrolü
if (tasks.length === 0) {
UI.empty.classList.add('show');
UI.status.innerText = "Sistem Hazır";
} else {
UI.empty.classList.remove('show');
UI.status.innerText = "Odaklanıldı";
// Görevleri listeye ekle
tasks.forEach((task, i) => {
const li = document.createElement('li');
li.innerHTML = `
<span>${task}</span>
<button onclick="deleteTask(${i})" title="Sil">
<i class="fas fa-trash-can"></i>
</button>
`;
UI.taskList.appendChild(li);
});
}
// İstatistik ve Progress Güncelleme
const taskCount = tasks.length;
UI.count.innerText = taskCount;
// Progress Hesapla (Limit: 10 görevde %100)
let progress = Math.min((taskCount / 10) * 100, 100);
UI.perc.innerText = Math.round(progress) + '%';
// SVG Dashoffset (Çevre = 2 * PI * 45 ≈ 283)
const circumference = 283;
const offset = (progress / 100) * circumference;
UI.arc.style.strokeDasharray = `${offset} ${circumference}`;
}
// Başlat!
init();