-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
130 lines (100 loc) · 3.54 KB
/
Copy pathscript.js
File metadata and controls
130 lines (100 loc) · 3.54 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
const clockEl = document.getElementById('clock');
function updateClock(){
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
clockEl.textContent = `${hours}:${minutes}:${seconds}`;
}
updateClock();
setInterval(updateClock, 1000);
let highestZIndex = 10;
function bringToFront(windowEl) {
highestZIndex++;
windowEl.style.zIndex = highestZIndex;
}
function makeDrag(windowEl) {
const header = windowEl.querySelector('.window-header');
if (!header) return;
let isDrag = false;
let offsetX = 0;
let offsetY = 0;
header.addEventListener('mousedown', (event) => {
isDrag = true;
offsetX = event.clientX - windowEl.offsetLeft;
offsetY = event.clientY - windowEl.offsetTop;
header.style.cursor = 'grabbing';
bringToFront(windowEl);
event.preventDefault();
});
document.addEventListener('mousemove', (event) => {
if (!isDrag) return;
const newX = event.clientX - offsetX;
const newY = event.clientY - offsetY;
windowEl.style.left = newX + 'px';
windowEl.style.top = newY + 'px';
});
document.addEventListener('mouseup', () => {
if (!isDrag) return;
isDrag = false;
header.style.cursor = 'grab';
});
}
const windowAbout = document.getElementById('window-about');
const windowNotepad = document.getElementById('window-notepad');
if (windowAbout) makeDrag(windowAbout);
if (windowNotepad) makeDrag(windowNotepad);
function setWinCtrl(shortcutId, windowEl, closeBtnID) {
const shortcut = document.getElementById(shortcutId);
const closeBtn = document.getElementById(closeBtnID);
if (!shortcut || !closeBtn || !windowEl) return;
closeBtn.addEventListener('click', () => {
windowEl.style.display = 'none';
});
shortcut.addEventListener('dblclick', () => {
windowEl.style.display = 'flex';
bringToFront(windowEl);
});
}
setWinCtrl('shortcut-about', windowAbout, 'close-about');
setWinCtrl('shortcut-notepad', windowNotepad, 'close-notepad');
const windowPlayer = document.getElementById('window-player');
makeDrag(windowPlayer);
setWinCtrl('shortcut-player', windowPlayer, 'close-player');
const audioEl=document.getElementById('audio-element');
const playBtn = document.getElementById('btn-play');
const pauseBtn = document.getElementById('btn-pause');
const playerScreen = document.getElementById('player-screen');
const playlistItems = document.querySelectorAll('.playlist-item');
let currActiveSong = null;
playlistItems.forEach(item => {
item.addEventListener('click', () => {
if (currActiveSong) {
currActiveSong.classList.remove('active');
}
currActiveSong = item;
item.classList.add('active');
const songUrl = item.getAttribute('data-src');
audioEl.src = songUrl;
audioEl.play();
playerScreen.textContent = 'Playing: ' + item.textContent;
});
});
playBtn.addEventListener('click', () => {
if (audioEl.src){
audioEl.play();
if (currActiveSong){
playerScreen.textContent = "Playing: " + currActiveSong.textContent;
}
else{
playerScreen.textContent = "Select a song first!";
}
}
});
pauseBtn.addEventListener('click', () => {
audioEl.pause();
playerScreen.textContent = "Paused";
});