-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·173 lines (161 loc) · 5.5 KB
/
script.js
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
const contextMenu = document.querySelector(".contextMenu");
const backgroundArea = document.querySelector(".backgroundArea");
const taskbarDate = document.querySelector(".taskbarDate");
const taskbarTime = document.querySelector(".taskbarTime");
const selection = document.querySelector(".selection");
const updateDate = () => {
let date = new Date();
let hours = date.getHours().toLocaleString("en-US", {
minimumIntegerDigits: 2,
useGrouping: false,
});
let minutes = date.getMinutes().toLocaleString("en-US", {
minimumIntegerDigits: 2,
useGrouping: false,
});
let seconds = date.getSeconds().toLocaleString("en-US", {
minimumIntegerDigits: 2,
useGrouping: false,
});
taskbarDate.textContent = date.toLocaleDateString();
taskbarTime.textContent = `${hours}:${minutes}:${seconds}`;
};
const createMenu = (location, items) => {
contextMenu.replaceChildren();
const ul = document.createElement("ul");
contextMenu.style.padding = "8px";
contextMenu.appendChild(ul);
const screenWidth = backgroundArea.offsetWidth;
const screenHeight = backgroundArea.offsetHeight;
const computedStyle = window.getComputedStyle(contextMenu);
const width = parseFloat(computedStyle.width);
const height = Object.keys(items.list).length * 33 + 16;
contextMenu.style.left = `${location[0]}px`;
contextMenu.style.top = `${location[1]}px`;
if (screenWidth - location[0] < width) {
contextMenu.style.left = `${location[0] - width - 16}px`;
contextMenu.style.top = `${location[1] - height}px`;
}
if (screenHeight - location[1] < height) {
contextMenu.style.left = `${location[0] - width - 16}px`;
contextMenu.style.top = `${location[1] - height}px`;
}
for (const key in items.list) {
const li = document.createElement("li");
const p = document.createElement("p");
const img = document.createElement("img");
p.textContent = items.list[key];
ul.appendChild(li);
p.textContent = key;
img.setAttribute("src", items.list[key].icon);
img.setAttribute("Alt", `${key} Icon`);
li.appendChild(img);
li.appendChild(p);
if (items.list[key].submenu != null) {
const img = document.createElement("img");
img.setAttribute("src", items.arrow);
img.setAttribute("Alt", `Arrow Icon`);
img.setAttribute("class", `rightArrow`);
li.appendChild(img);
}
}
};
let items = {
list: {
View: {
icon: "icons/views.png",
submenu: [
"Large icons",
"Medium icons",
"Small icons",
"Auto arrange icons",
"Align icons to grid",
"Show desktop icons",
],
},
"Sort by": {
icon: "icons/sortby.png",
submenu: ["Date modified", "Name", "Type", "Date added"],
},
Refresh: { icon: "icons/refresh.png", submenu: null },
"More Options": {
icon: "icons/moreoptions.png",
submenu: ["IDK", "I don't Fucking Know"],
},
New: {
icon: "icons/new.png",
submenu: [
"Folder",
"Image",
"Text Document",
"Word Document",
"Exel File",
"PDF Document",
],
},
Paste: {
icon: "icons/paste.png",
submenu: null,
},
"Display Setting": {
icon: "icons/display.png",
submenu: null,
},
Personalize: {
icon: "icons/personalize.png",
submenu: null,
},
},
arrow: "icons/arrowright.png",
};
const disableRightClick = (event) => {
event.preventDefault();
};
const handleRightClick = (event) => {
const location = [event.clientX, event.clientY];
createMenu(location, items);
};
const handleClick = (event) => {
contextMenu.replaceChildren();
contextMenu.style.padding = "0";
};
const drawSelection = (startCord, endCord) => {
selection.style.display = "block";
selection.style.left = startCord[0] + "px";
selection.style.top = startCord[1] + "px";
selection.style.width = endCord[0] - startCord[0] + "px";
selection.style.height = endCord[1] - startCord[1] + "px";
};
let isMouseDown = false;
let mouseDownLocation = [0, 0];
const mouseUp = (event) => {
selection.style.display = "none";
isMouseDown = false;
};
const mouseDown = (event) => {
isMouseDown = true;
mouseDownLocation = [event.clientX, event.clientY];
};
const mouseMove = (event) => {
if (isMouseDown == false) return;
mouseMoveLocation = [event.clientX, event.clientY];
let startCord = [
Math.min(mouseDownLocation[0], mouseMoveLocation[0]) - 3,
Math.min(mouseDownLocation[1], mouseMoveLocation[1]) - 3,
];
let endCord = [
Math.max(mouseDownLocation[0], mouseMoveLocation[0]) - 3,
Math.max(mouseDownLocation[1], mouseMoveLocation[1]) - 3,
];
drawSelection(startCord, endCord);
};
document.addEventListener("contextmenu", disableRightClick);
backgroundArea.addEventListener("contextmenu", handleRightClick);
backgroundArea.addEventListener("click", handleClick);
backgroundArea.addEventListener("mousedown", mouseDown);
document.addEventListener("mouseup", mouseUp);
backgroundArea.addEventListener("mousemove", mouseMove);
updateDate();
setInterval(() => {
updateDate();
}, 1000);