-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
520 lines (468 loc) · 20.3 KB
/
script.js
File metadata and controls
520 lines (468 loc) · 20.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
(function(){
"use strict";
const K="dc_",g=(k,d)=>{try{const v=localStorage.getItem(K+k);return v?JSON.parse(v):d}catch{return d}},s=(k,v)=>localStorage.setItem(K+k,JSON.stringify(v)),$=s=>document.getElementById(s);
// --- SVG Icons (compact inline) ---
const IC={
github:'<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.3 3.44 9.8 8.2 11.39.6.11.82-.26.82-.58v-2.23c-3.34.73-4.04-1.42-4.04-1.42-.55-1.39-1.34-1.76-1.34-1.76-1.09-.74.08-.73.08-.73 1.2.09 1.84 1.24 1.84 1.24 1.07 1.84 2.81 1.31 3.5 1 .1-.78.42-1.31.76-1.61-2.66-.3-5.47-1.33-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.13-.3-.54-1.52.12-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6.02 0c2.28-1.55 3.29-1.23 3.29-1.23.66 1.66.25 2.88.12 3.18.77.84 1.24 1.91 1.24 3.22 0 4.61-2.81 5.63-5.48 5.92.43.37.82 1.1.82 2.22v3.29c0 .32.21.7.82.58A12 12 0 0 0 12 0Z"/></svg>',
play:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>',
globe:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M2 12h20M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>',
code:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
book:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/></svg>',
chat:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
star:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>',
bolt:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>',
sport:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 2a10 10 0 0 1 0 20M2 12h20"/></svg>',
link:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>'
};
const DEF_LINKS=[
{n:"GitHub",u:"https://github.com",i:"github"},
{n:"AI Arena",u:"https://lmarena.ai",i:"bolt"},
{n:"Gemini",u:"https://gemini.google.com",i:"star"},
{n:"Localhost",u:"http://localhost:3000",i:"code"},
{n:"ChatGPT",u:"https://chat.openai.com",i:"chat"},
{n:"YouTube",u:"https://youtube.com",i:"play"},
{n:"StackOverflow",u:"https://stackoverflow.com",i:"code"},
{n:"Dev.to",u:"https://dev.to",i:"globe"},
{n:"HuggingFace",u:"https://huggingface.co",i:"star"},
{n:"ESPN",u:"https://espn.com",i:"sport"},
{n:"MDN",u:"https://developer.mozilla.org",i:"book"},
{n:"Reddit",u:"https://reddit.com",i:"chat"}
];
const QT=[
["First, solve the problem. Then, write the code.","John Johnson"],
["Code is like humor. When you have to explain it, it's bad.","Cory House"],
["Make it work, make it right, make it fast.","Kent Beck"],
["Clean code always looks like it was written by someone who cares.","Robert C. Martin"],
["Programming isn't about what you know; it's about what you can figure out.","Chris Pine"],
["The best error message is the one that never shows up.","Thomas Fuchs"],
["Talk is cheap. Show me the code.","Linus Torvalds"],
["Good programmers write code that humans can understand.","Martin Fowler"],
["Simplicity is the soul of efficiency.","Austin Freeman"],
["Before software can be reusable it first has to be usable.","Ralph Johnson"],
["It's not a bug — it's an undocumented feature.","Anonymous"],
["We've always done it this way — the most dangerous phrase.","Grace Hopper"],
["Debugging is twice as hard as writing the code.","Brian Kernighan"],
["Good software makes the complex appear simple.","Grady Booch"],
["Testing leads to failure, and failure leads to understanding.","Burt Rutan"],
["The only way to learn a new language is by writing programs in it.","Dennis Ritchie"],
["Perfection is when there is nothing more to take away.","Saint-Exupéry"],
["Experience is the name everyone gives to their mistakes.","Oscar Wilde"],
["Java is to JavaScript what car is to carpet.","Chris Heilmann"],
["In order to be irreplaceable, one must always be different.","Coco Chanel"]
];
const ENG={
google:["https://www.google.com/search?q=","Google"],
bing:["https://www.bing.com/search?q=","Bing"],
ddg:["https://duckduckgo.com/?q=","DuckDuckGo"],
chatgpt:["https://chat.openai.com/","ChatGPT"],
gemini:["https://gemini.google.com/app","Gemini"],
perplexity:["https://www.perplexity.ai/search?q=","Perplexity"]
};
let S=g("settings",{name:"",city:"",accent:"#8b5cf6",engine:"google",theme:"dark"});
let sessionStart=Date.now();
// --- Accent ---
function setAc(c){
const r=document.documentElement.style;
r.setProperty("--ac",c);
const[rv,gv,bv]=[parseInt(c.slice(1,3),16),parseInt(c.slice(3,5),16),parseInt(c.slice(5,7),16)];
r.setProperty("--a1",`rgba(${rv},${gv},${bv},.1)`);
r.setProperty("--a2",`rgba(${rv},${gv},${bv},.2)`);
}
// --- Extract dominant color from image ---
function extractColor(imgSrc,cb){
const img=new Image();
img.crossOrigin="anonymous";
img.onload=function(){
const c=document.createElement("canvas"),ctx=c.getContext("2d");
c.width=c.height=50;
ctx.drawImage(img,0,0,50,50);
const d=ctx.getImageData(0,0,50,50).data;
let rT=0,gT=0,bT=0,count=0;
for(let i=0;i<d.length;i+=16){
const r=d[i],g=d[i+1],b=d[i+2];
// Skip very dark and very light pixels
if(r+g+b>80 && r+g+b<650){rT+=r;gT+=g;bT+=b;count++}
}
if(count>0){
let r=Math.round(rT/count),gv=Math.round(gT/count),b=Math.round(bT/count);
// Boost saturation for a vivid accent
const max=Math.max(r,gv,b),min=Math.min(r,gv,b);
if(max-min<40){cb(null);return}
const factor=1.4;
r=Math.min(255,Math.round(((r-128)*factor)+128));
gv=Math.min(255,Math.round(((gv-128)*factor)+128));
b=Math.min(255,Math.round(((b-128)*factor)+128));
cb("#"+[r,gv,b].map(x=>Math.max(0,Math.min(255,x)).toString(16).padStart(2,"0")).join(""));
}else cb(null);
};
img.onerror=()=>cb(null);
img.src=imgSrc;
}
// --- Toast ---
function toast(msg){
const t=$("toast");
t.textContent=msg;t.classList.remove("hidden");
setTimeout(()=>t.classList.add("hidden"),2500);
}
// --- Theme ---
function setTh(t){
document.body.classList.toggle("light",t==="light");
$("b-th").textContent=t==="light"?"☀":"🌙";
}
// --- Background ---
function setBg(){
const bg=localStorage.getItem(K+"bg");
if(bg)$("bg").style.background=`url(${bg}) center/cover no-repeat fixed`;
}
// --- Clock ---
function tick(){
const now=new Date(),h=now.getHours(),h12=h%12||12;
const m=String(now.getMinutes()).padStart(2,"0"),s=String(now.getSeconds()).padStart(2,"0");
$("clock").textContent=`${String(h12).padStart(2,"0")}:${m}:${s}`;
const days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
const ap=h>=12?"PM":"AM";
$("date").textContent=`${days[now.getDay()]}, ${months[now.getMonth()]} ${now.getDate()}, ${now.getFullYear()} · ${ap}`;
const nm=S.name?`, ${S.name}`:"";
let gr;
if(h>=5&&h<12)gr=`Good Morning${nm} ☀`;
else if(h>=12&&h<17)gr=`Good Afternoon${nm} 🌤`;
else if(h>=17&&h<21)gr=`Good Evening${nm} 🌇`;
else gr=`Good Night${nm} 🌙`;
$("greet").textContent=gr;
$("fn").textContent=S.name||"Your";
// Session timer
const elapsed=Math.floor((Date.now()-sessionStart)/60000);
$("session").textContent=`🕐 ${elapsed}m`;
}
// --- Weather ---
async function weather(){
const city=S.city||"New York";
try{
const r=await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=j1`);
const d=await r.json(),c=d.current_condition[0];
const desc=c.weatherDesc[0].value.toLowerCase();
let ic="🌤";
if(desc.includes("clear")||desc.includes("sunny"))ic="☀";
else if(desc.includes("rain")||desc.includes("drizzle"))ic="🌧";
else if(desc.includes("snow"))ic="❄";
else if(desc.includes("thunder"))ic="⛈";
else if(desc.includes("cloud")||desc.includes("overcast"))ic="☁";
else if(desc.includes("fog")||desc.includes("mist"))ic="🌫";
$("weather").textContent=`${ic} ${c.temp_C}°C · ${c.weatherDesc[0].value} · Feels ${c.FeelsLikeC}°C · 💧${c.humidity}% · ${city}`;
}catch{$("weather").textContent=`🌤 ${city} — unavailable`}
}
// --- Activity Log ---
function addLog(text){
const logs=g("logs",[]);
const now=new Date();
const time=now.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"});
logs.unshift({time,text});
if(logs.length>50)logs.length=50; // Keep last 50
s("logs",logs);
renderLogs();
}
function renderLogs(){
const logs=g("logs",[]);
const el=$("log");
el.innerHTML="";
logs.slice(0,15).forEach(l=>{
const d=document.createElement("div");
d.className="le";
d.innerHTML=`<span class="lt">${l.time}</span><span class="ll">${esc(l.text)}</span>`;
el.appendChild(d);
});
if(!logs.length) el.innerHTML='<div class="le"><span class="ll" style="color:var(--t3)">No activity yet</span></div>';
}
// --- Search ---
function initSearch(){
const eng=S.engine||"google";
const[,name]=ENG[eng]||ENG.google;
$("badge").textContent=name;
$("search").placeholder=`Search ${name} or type URL...`;
$("search").onkeydown=function(e){
if(e.key!=="Enter")return;
const q=this.value.trim();if(!q)return;
if(/^(https?:\/\/|localhost)/.test(q)){
addLog(`Opened: ${q}`);
window.location.href=q.startsWith("localhost")?"http://"+q:q;
return;
}
// Log the search
addLog(`Searched "${q}" via ${name}`);
// Handle engines that don't support ?q= parameter
if(eng==="gemini"){
navigator.clipboard.writeText(q).then(()=>{
toast("📋 Query copied! Paste it in Gemini.");
setTimeout(()=>{window.open(ENG.gemini[0],"_blank")},800);
}).catch(()=>{window.open(ENG.gemini[0],"_blank")});
return;
}
if(eng==="chatgpt"){
navigator.clipboard.writeText(q).then(()=>{
toast("📋 Query copied! Paste it in ChatGPT.");
setTimeout(()=>{window.open(ENG.chatgpt[0],"_blank")},800);
}).catch(()=>{window.open(ENG.chatgpt[0],"_blank")});
return;
}
window.location.href=(ENG[eng]||ENG.google)[0]+encodeURIComponent(q);
};
}
// --- Voice Search (Mic) ---
function initMic(){
$("b-mic").onclick=()=>{
const SR=window.SpeechRecognition||window.webkitSpeechRecognition;
if(!SR){toast("Voice search not supported in this browser");return}
const rec=new SR();
rec.lang="en-US";
rec.interimResults=false;
$("b-mic").style.background="var(--a2)";
toast("🎤 Listening...");
rec.onresult=(e)=>{
$("search").value=e.results[0][0].transcript;
$("b-mic").style.background="";
toast("✅ Got it! Press Enter to search.");
};
rec.onerror=()=>{$("b-mic").style.background="";toast("❌ Could not hear. Try again.")};
rec.onend=()=>{$("b-mic").style.background=""};
rec.start();
};
}
// --- Google Lens ---
function initLens(){
$("b-lens").onclick=()=>{
addLog("Opened Google Lens");
window.open("https://lens.google.com/","_blank");
};
}
// --- Quick Links ---
function renderLinks(){
const links=g("links",DEF_LINKS);
const el=$("links");
el.innerHTML="";
links.forEach((l,i)=>{
const a=document.createElement("a");
a.className="lc";a.href=l.u;a.target="_blank";a.rel="noopener";
a.innerHTML=`<button class="ld" data-i="${i}">✕</button>${IC[l.i]||IC.link}<span>${l.n}</span>`;
el.appendChild(a);
});
el.onclick=(e)=>{
const d=e.target.closest(".ld");
if(d){e.preventDefault();e.stopPropagation();
const links=g("links",DEF_LINKS);
links.splice(parseInt(d.dataset.i),1);
s("links",links);renderLinks()}
};
}
function initAddLink(){
$("b-al").onclick=()=>$("lm").classList.remove("hidden");
$("cn-l").onclick=()=>$("lm").classList.add("hidden");
$("sv-l").onclick=()=>{
const n=$("nl-n").value.trim(),u=$("nl-u").value.trim(),i=$("nl-i").value;
if(!n||!u)return toast("Enter both name and URL");
const links=g("links",DEF_LINKS);
links.push({n,u,i});s("links",links);renderLinks();
$("lm").classList.add("hidden");
$("nl-n").value="";$("nl-u").value="";
toast(`✅ ${n} added!`);
};
}
// --- Focus ---
function initFocus(){
const inp=$("focus"),today=new Date().toDateString();
const sv=g("focus",{d:"",t:""});
inp.value=sv.d===today?sv.t:"";
inp.oninput=()=>s("focus",{d:today,t:inp.value});
}
// --- To-Do ---
function renderTodos(){
const todos=g("todos",[]),list=$("tl");
list.innerHTML="";
todos.forEach((t,i)=>{
const li=document.createElement("li");
li.className=`ti${t.done?" done":""}`;
li.innerHTML=`<span class="tc" data-i="${i}">${t.done?"✅":"⬜"}</span><span class="tt">${esc(t.text)}</span><button class="tx" data-i="${i}">✕</button>`;
list.appendChild(li);
});
}
function initTodos(){
const inp=$("ti");
const add=()=>{const t=inp.value.trim();if(!t)return;const todos=g("todos",[]);todos.unshift({text:t,done:false});s("todos",todos);inp.value="";renderTodos();addLog(`Task added: "${t}"`)};
$("a-td").onclick=add;
inp.onkeydown=e=>{if(e.key==="Enter")add()};
$("cl-d").onclick=()=>{s("todos",g("todos",[]).filter(t=>!t.done));renderTodos()};
$("tl").onclick=e=>{
const ch=e.target.closest(".tc"),dl=e.target.closest(".tx");
if(ch){const todos=g("todos",[]),i=+ch.dataset.i;todos[i].done=!todos[i].done;s("todos",todos);renderTodos()}
if(dl){const todos=g("todos",[]);todos.splice(+dl.dataset.i,1);s("todos",todos);renderTodos()}
};
renderTodos();
}
// --- Notes ---
function initNotes(){
const ta=$("notes"),st=$("ns");
ta.value=g("notes","");
let tm;
ta.oninput=()=>{
st.textContent="Saving...";st.style.color="#eab308";
clearTimeout(tm);
tm=setTimeout(()=>{s("notes",ta.value);st.textContent="Saved ✓";st.style.color="#10b981"},400);
};
}
// --- Pomodoro ---
function initPomo(){
let total=25*60,remain=total,iv=null,running=false;
let sess=g("pomo",{d:new Date().toDateString(),c:0});
if(sess.d!==new Date().toDateString()){sess={d:new Date().toDateString(),c:0};s("pomo",sess)}
$("p-ct").textContent=sess.c;
const upd=()=>{$("pt").textContent=`${String(Math.floor(remain/60)).padStart(2,"0")}:${String(remain%60).padStart(2,"0")}`};
$("p-go").onclick=()=>{
if(running)return;running=true;
$("ps").textContent="⏳ Focusing...";
addLog("Focus session started");
iv=setInterval(()=>{
remain--;upd();
if(remain<=0){
clearInterval(iv);running=false;
$("ps").textContent="🎉 Complete!";
sess.c++;s("pomo",sess);$("p-ct").textContent=sess.c;
addLog("Focus session completed!");
if(Notification.permission==="granted")new Notification("⏰ Focus complete!",{body:"Great work! Take a break."});
}
},1000);
};
$("p-pa").onclick=()=>{clearInterval(iv);running=false;$("ps").textContent="⏸ Paused"};
$("p-re").onclick=()=>{clearInterval(iv);running=false;remain=total;upd();$("ps").textContent="Ready"};
document.querySelectorAll(".pp").forEach(b=>{
b.onclick=function(){
document.querySelectorAll(".pp").forEach(x=>x.classList.remove("active"));
this.classList.add("active");
total=+this.dataset.m*60;remain=total;
clearInterval(iv);running=false;$("ps").textContent="Ready";upd()};
});
// Custom time
$("p-set").onclick=()=>{
const v=parseInt($("p-custom").value);
if(!v||v<1||v>180)return toast("Enter 1-180 minutes");
document.querySelectorAll(".pp").forEach(x=>x.classList.remove("active"));
total=v*60;remain=total;
clearInterval(iv);running=false;$("ps").textContent=`Ready (${v}m custom)`;upd();
toast(`Timer set to ${v} minutes`);
};
upd();
if(Notification.permission==="default")Notification.requestPermission();
}
// --- Calendar ---
let cY,cM;
function initCal(){
const now=new Date();cY=now.getFullYear();cM=now.getMonth();
renderCal();
$("c-p").onclick=()=>{cM--;if(cM<0){cM=11;cY--}renderCal()};
$("c-n").onclick=()=>{cM++;if(cM>11){cM=0;cY++}renderCal()};
}
function renderCal(){
const months=["January","February","March","April","May","June","July","August","September","October","November","December"];
$("c-t").textContent=`${months[cM]} ${cY}`;
const el=$("cal");el.innerHTML="";
["Su","Mo","Tu","We","Th","Fr","Sa"].forEach(d=>{
const e=document.createElement("div");e.className="dn";e.textContent=d;el.appendChild(e)});
const first=new Date(cY,cM,1).getDay(),dim=new Date(cY,cM+1,0).getDate(),today=new Date();
for(let i=0;i<first;i++){const e=document.createElement("div");e.className="dy em";el.appendChild(e)}
for(let d=1;d<=dim;d++){
const e=document.createElement("div");e.className="dy";
if(d===today.getDate()&&cM===today.getMonth()&&cY===today.getFullYear())e.classList.add("td");
e.textContent=d;el.appendChild(e);
}
}
// --- Quotes (auto-rotate) ---
let qIdx=Math.floor(Math.random()*QT.length);
function showQuote(){
const q=QT[qIdx];
$("qt").textContent=`"${q[0]}"`;
$("qa").textContent=`— ${q[1]}`;
qIdx=(qIdx+1)%QT.length;
}
// --- Settings ---
function initSettings(){
$("b-st").onclick=()=>{
$("settings").classList.remove("hidden");
$("s-n").value=S.name;$("s-c").value=S.city;$("s-ac").value=S.accent;$("s-e").value=S.engine;
};
$("x-set").onclick=()=>$("settings").classList.add("hidden");
document.addEventListener("click",e=>{
const p=$("settings");
if(!p.classList.contains("hidden")&&!p.contains(e.target)&&e.target!==$("b-st")&&!$("b-st").contains(e.target))
p.classList.add("hidden");
});
document.querySelectorAll(".pr").forEach(p=>{
p.onclick=function(){
document.querySelectorAll(".pr").forEach(x=>x.classList.remove("active"));
this.classList.add("active");$("s-ac").value=this.dataset.c};
});
$("save-s").onclick=()=>{
S.name=$("s-n").value.trim();S.city=$("s-c").value.trim();
S.accent=$("s-ac").value;S.engine=$("s-e").value;
s("settings",S);setAc(S.accent);initSearch();tick();weather();
$("settings").classList.add("hidden");
toast("✅ Settings saved!");
addLog("Settings updated");
};
$("s-bg").onchange=function(){
const file=this.files[0];if(!file)return;
const reader=new FileReader();
reader.onload=(e)=>{
localStorage.setItem(K+"bg",e.target.result);
setBg();
// Auto-extract accent color from image
extractColor(e.target.result,(color)=>{
if(color){
S.accent=color;s("settings",S);setAc(color);
$("s-ac").value=color;
document.querySelectorAll(".pr").forEach(x=>x.classList.remove("active"));
toast(`🎨 Accent color auto-adapted: ${color}`);
}
});
};
reader.readAsDataURL(file);
};
$("r-bg").onclick=()=>{localStorage.removeItem(K+"bg");location.reload()};
}
// --- Theme ---
function initTheme(){
$("b-th").onclick=()=>{
S.theme=S.theme==="dark"?"light":"dark";
s("settings",S);setTh(S.theme);
addLog(`Theme: ${S.theme}`);
};
}
// --- Clear Log ---
function initClearLog(){
$("cl-log").onclick=()=>{s("logs",[]);renderLogs();toast("Log cleared")};
}
// --- Keyboard Shortcuts ---
function initKeys(){
document.onkeydown=(e)=>{
if(e.ctrlKey&&e.key==="k"){e.preventDefault();$("search").focus()}
if(e.ctrlKey&&e.key===","){e.preventDefault();$("settings").classList.toggle("hidden")}
if(e.ctrlKey&&e.key==="."){e.preventDefault();$("b-th").click()}
if(e.key==="Escape"){$("settings").classList.add("hidden");$("lm").classList.add("hidden")}
};
}
// --- Utility ---
function esc(s){const d=document.createElement("div");d.textContent=s;return d.innerHTML}
// --- BOOT ---
function boot(){
setAc(S.accent);setTh(S.theme);setBg();
tick();setInterval(tick,1000);
weather();setInterval(weather,18e5);
initSearch();initMic();initLens();
renderLinks();initAddLink();
initFocus();initTodos();initNotes();initPomo();
initCal();showQuote();setInterval(showQuote,30000);
initSettings();initTheme();initClearLog();initKeys();
renderLogs();
addLog("Dashboard opened");
}
if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",boot);
else boot();
})();