-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
325 lines (292 loc) Β· 9.29 KB
/
Copy pathscript.js
File metadata and controls
325 lines (292 loc) Β· 9.29 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
// CLOCK
function updateTime(){
document.querySelector("#timeElement").innerHTML = new Date().toLocaleString();
}
setInterval(updateTime,1000);
// WINDOWS
var biggestIndex=1;
var topBar = document.querySelector("#top");
function openWindow(element){
element.style.display="flex";
biggestIndex++;
element.style.zIndex=biggestIndex;
topBar.style.zIndex=biggestIndex+1;
}
function closeWindow(element){
element.style.display="none";
}
function addWindowTapHandling(element){
element.addEventListener("mousedown",()=>{
biggestIndex++;
element.style.zIndex=biggestIndex;
topBar.style.zIndex=biggestIndex+1;
});
}
// DRAG
function dragElement(element){
let startX=0;
let startY=0;
document.getElementById(element.id+"header").onmousedown=startDrag;
function startDrag(e){
startX=e.clientX;
startY=e.clientY;
document.onmousemove=drag;
document.onmouseup=stop;
}
function drag(e){
let x=startX-e.clientX;
let y=startY-e.clientY;
startX=e.clientX;
startY=e.clientY;
let newTop = element.offsetTop-y;
let newLeft = element.offsetLeft-x;
if(newTop < 70){ newTop=70; }
element.style.top=newTop+"px";
element.style.left=newLeft+"px";
}
function stop(){
document.onmousemove=null;
}
}
// SELECT WINDOWS
var welcome = document.querySelector("#welcome");
var notes = document.querySelector("#notes");
var terminal = document.querySelector("#terminal");
var photos = document.querySelector("#photos");
dragElement(welcome);
dragElement(notes);
dragElement(terminal);
dragElement(photos);
addWindowTapHandling(welcome);
addWindowTapHandling(notes);
addWindowTapHandling(terminal);
addWindowTapHandling(photos);
// BUTTONS
document.querySelector("#welcomeclose").onclick=()=>{ closeWindow(welcome); };
document.querySelector("#notesclose").onclick=()=>{ closeWindow(notes); };
document.querySelector("#terminalclose").onclick=()=>{ closeWindow(terminal); };
document.querySelector("#photosclose").onclick=()=>{ closeWindow(photos); };
document.querySelector("#welcomeopen").onclick=()=>{ openWindow(welcome); };
// APP ICONS
document.querySelector("#notesIcon").onclick=()=>{ openWindow(notes); };
document.querySelector("#terminalIcon").onclick=()=>{
openWindow(terminal);
document.querySelector("#terminalInput").focus();
};
document.querySelector("#photosIcon").onclick=()=>{ openWindow(photos); };
// NOTES DATA
var content=[
{
title:"Welcome",
date:"21-06-2026",
color:"linear-gradient(135deg,#050505,#14213d)",
content:`
<h2>Welcome to Noid Notes π</h2>
<p>This is my first app inside Noid OS.</p>
<p>Ideas, projects and thoughts.</p>
<p>If you like it, star the repo on github! (see the Me page for the github)</p>
<p>Or if you don't wanna do that, see the project on stardance!</h>
`
},
{
title:"Me",
date:"21-06-2026",
color:"linear-gradient(135deg,#330033,#660066)",
content:`
<h2>Hi I am Noid DEV π¨βπ»</h2>
<p>I create websites and open source software.</p>
<a href="https://github.com/its-noid-dev"> My github </a>
<a href="https://github.com/its-noid-dev/noidwebos"> This project </a>
`
},
{
title:"Why",
date:"11-06-2026",
color:"linear-gradient(135deg,#003333,#006666)",
content:`
<h2>Why Noid OS?</h2>
<p>Made for Hack Club Stardance.</p>
<p>Built with HTML CSS and JavaScript.</p>
`
}
];
// NOTES SYSTEM
var sidebar = document.querySelector("#sidebar");
var noteText = document.querySelector("#noteText");
function setNotesContent(index){
noteText.innerHTML = content[index].content;
document.body.style.background = content[index].color;
document.querySelector("#appStatus").innerHTML = "π "+content[index].title;
}
function addToSidebar(index){
let note=content[index];
let div=document.createElement("div");
div.innerHTML=`<b>${note.title}</b><br><small>${note.date}</small>`;
div.onclick=()=>{ setNotesContent(index); };
sidebar.appendChild(div);
}
for(let i=0;i<content.length;i++){
addToSidebar(i);
}
setNotesContent(0);
// =====================
// TERMINAL APP
// =====================
var terminalOutput = document.querySelector("#terminalOutput");
var terminalInput = document.querySelector("#terminalInput");
var terminalWindow = document.querySelector("#terminalWindow");
// site files this "open source" terminal can show
var siteFiles = {
"index.html": "<!-- The main HTML structure of Noid OS -->",
"style.css": "/* All styling for windows, icons and apps */",
"script.js": "// All the JavaScript logic that powers Noid OS",
"image1.jpeg": "[binary image file]",
"terminal.png": "[binary image file]",
"pic1.png": "[binary image file]",
"pic2.png": "[binary image file]",
"pic3.png": "[binary image file]",
"pic4.png": "[binary image file]",
"pic5.png": "[binary image file]",
"pic6.png": "[binary image file]",
"pic7.png": "[binary image file]",
"pic8.png": "[binary image file]",
"pic9.png": "[binary image file]",
"pic10.png": "[binary image file]"
};
function printLine(text){
let line = document.createElement("div");
line.className="terminalEntry";
line.innerHTML = text;
terminalOutput.appendChild(line);
terminalWindow.scrollTop = terminalWindow.scrollHeight;
}
function printCommandEcho(cmd){
printLine(`<span class="prompt">noid@noidOS:~$</span> ${cmd}`);
}
var steamTrainFrames = [
`
==== ________ ___________
_D _| |_______/ \\__I_I_____===__|_________|
|(_)--- | H\\________/ | | =|___ ___|
/ | | H | | | | ||_| |_||
| | | H |__--------------------| [___] |
| ________|___H__/__|_____/[][]~\\_______| |
|/ | |-----------I_____I [][] [] D |=======|
__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__
|/-=|___|= || || || |_____/~\\___/
\\_/ \\__/ \\__/ \\__/ \\__/ \\_/
`,
`
==== ________ ___________
_D _| |_______/ \\__I_I_____===__|_________|
|(_)--- | H\\________/ | | =|___ ___|
/ | | H | | | | ||_| |_||
| | | H |__--------------------| [___] |
| ________|___H__/__|_____/[][]~\\_______| |
|/ | |-----------I_____I [][] [] D |=======|
__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__
|/-=|___|= || || || |_____/~\\___/
\\_/ \\__/ \\__/ \\__/ \\__/ \\_/
`
];
function runSteamTrain(){
let trainLine = document.createElement("div");
trainLine.className="terminalEntry steamtrain";
terminalOutput.appendChild(trainLine);
let frame = 0;
let position = 60;
printLine("π choo choo! (press Ctrl+C style β it'll stop on its own)");
let interval = setInterval(()=>{
let pad = " ".repeat(Math.max(position,0));
let art = steamTrainFrames[frame % steamTrainFrames.length]
.split("\n")
.map(l => pad + l)
.join("\n");
trainLine.textContent = art;
terminalWindow.scrollTop = terminalWindow.scrollHeight;
frame++;
position -= 4;
if(position < -80){
clearInterval(interval);
printLine("");
}
},100);
}
function runCommand(raw){
let cmd = raw.trim();
printCommandEcho(cmd);
if(cmd === ""){
return;
}
let parts = cmd.split(" ");
let base = parts[0];
if(base === "help"){
printLine(
`Available commands:
help show this help message
ls list site files (open source!)
cat [file] print a short description of a file
whoami who is running Noid OS
date show current date and time
clear clear the terminal screen
sl choo choo π`
);
} else if(base === "ls"){
printLine(Object.keys(siteFiles).join(" "));
} else if(base === "cat"){
let file = parts[1];
if(!file){
printLine("usage: cat [file]");
} else if(siteFiles[file]){
printLine(siteFiles[file]);
} else {
printLine(`cat: ${file}: No such file`);
}
} else if(base === "whoami"){
printLine("noid β builder of Noid OS, open source on GitHub");
} else if(base === "date"){
printLine(new Date().toString());
} else if(base === "clear"){
terminalOutput.innerHTML="";
} else if(base === "sl"){
runSteamTrain();
} else {
printLine(`command not found: ${base} (try "help")`);
}
}
printLine("Welcome to Noid Terminal. Type \"help\" to get started.");
terminalInput.addEventListener("keydown",(e)=>{
if(e.key === "Enter"){
let val = terminalInput.value;
terminalInput.value="";
runCommand(val);
}
});
terminalWindow.addEventListener("mousedown",(e)=>{
if(e.target !== terminalInput){
terminalInput.focus();
}
});
// =====================
// PHOTOS APP
// =====================
var photoIndex = 1;
var totalPhotos = 10;
var photoDisplay = document.querySelector("#photoDisplay");
var photoCounter = document.querySelector("#photoCounter");
function setPhoto(index){
photoIndex = index;
photoDisplay.src = `./pic${photoIndex}.png`;
photoCounter.innerHTML = `${photoIndex} / ${totalPhotos}`;
}
document.querySelector("#photoPrev").onclick=()=>{
let newIndex = photoIndex - 1;
if(newIndex < 1){ newIndex = totalPhotos; }
setPhoto(newIndex);
};
document.querySelector("#photoNext").onclick=()=>{
let newIndex = photoIndex + 1;
if(newIndex > totalPhotos){ newIndex = 1; }
setPhoto(newIndex);
};
setPhoto(1);