smoothretro82

Domino.OS (w.i.p) based off of e.g_OS

Dec 12th, 2025
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.78 KB | None | 0 0
  1. (() => {
  2. /* ------------------ GLOBAL FADE-IN/FADE-OUT STYLES ------------------ */
  3. const style = document.createElement('style');
  4. style.textContent = `
  5. .fade-window {
  6. opacity: 0;
  7. transition: opacity 0.25s ease-in-out;
  8. }
  9. .fade-show {
  10. opacity: 1 !important;
  11. }
  12. .fade-hide {
  13. opacity: 0 !important;
  14. }
  15. `;
  16. document.head.appendChild(style);
  17.  
  18. // ----- Persistence bootstrap -----
  19. if (!localStorage.os) localStorage.os = "{}";
  20.  
  21. // ----- Constants -----
  22. const SCREEN_WIDTH = 32;
  23. const SCREEN_HEIGHT = 16;
  24.  
  25. // ----- State -----
  26. let selected = null;
  27. let page = 1;
  28. let minimized = false;
  29.  
  30. let pixelGrid = Array.from({ length: SCREEN_HEIGHT }, () => Array(SCREEN_WIDTH).fill('#00ff00'));
  31. let currentColor = '#00ff00'; // default drawing color
  32.  
  33. // ----- Main HUD (QBasic style) -----
  34. const hud = document.createElement('div');
  35. hud.style.position = 'fixed';
  36. hud.style.top = '20px';
  37. hud.style.left = '20px';
  38. hud.style.width = '550px';
  39. hud.style.height = '450px';
  40. hud.style.background = localStorage.e_gOS_hudColor || '#C0C0C0';
  41. hud.style.border = '2px outset #808080';
  42. hud.style.fontFamily = 'monospace';
  43. hud.style.color = localStorage.e_gOS_textColor || '#0F0';
  44. hud.style.zIndex = 999999;
  45. hud.style.resize = 'both';
  46. hud.style.overflow = 'auto';
  47.  
  48. /* APPLY FADE-IN */
  49. hud.classList.add("fade-window");
  50. setTimeout(() => hud.classList.add("fade-show"), 10);
  51.  
  52. document.body.appendChild(hud);
  53.  
  54. // ----------------------------------------------------------------------
  55. // Everything from here down is your original code, with fade logic added
  56. // ----------------------------------------------------------------------
  57.  
  58. // Header
  59. const header = document.createElement('div');
  60. header.style.width = '100%';
  61. header.style.height = '20px';
  62. header.style.background = '#000080';
  63. header.style.color = '#FFFFFF';
  64. header.style.fontWeight = 'bold';
  65. header.style.borderBottom = '2px solid #808080';
  66. header.style.cursor = 'move';
  67. header.style.userSelect = 'none';
  68. header.style.display = 'flex';
  69. header.style.alignItems = 'center';
  70. header.style.justifyContent = 'space-between';
  71. header.style.padding = '0 5px';
  72. hud.appendChild(header);
  73.  
  74. const title = document.createElement('span');
  75. title.innerText = 'e_g.OS HUD';
  76. header.appendChild(title);
  77.  
  78. const controls = document.createElement('div');
  79. header.appendChild(controls);
  80.  
  81. // Minimize button
  82. const minimizeBtn = document.createElement('button');
  83. minimizeBtn.innerText = '_';
  84. minimizeBtn.title = 'Minimize';
  85. minimizeBtn.style.marginRight = '5px';
  86. minimizeBtn.style.fontSize = '12px';
  87. minimizeBtn.style.padding = '0 4px';
  88. minimizeBtn.style.width = '20px';
  89. minimizeBtn.style.background = '#C0C0C0';
  90. minimizeBtn.style.border = '2px outset #808080';
  91. minimizeBtn.style.color = '#000';
  92. minimizeBtn.style.cursor = 'pointer';
  93. controls.appendChild(minimizeBtn);
  94.  
  95. // Close button (with fade-out)
  96. const closeBtn = document.createElement('button');
  97. closeBtn.innerText = 'X';
  98. closeBtn.title = 'Close';
  99. closeBtn.style.fontSize = '12px';
  100. closeBtn.style.padding = '0 4px';
  101. closeBtn.style.width = '20px';
  102. closeBtn.style.background = '#C0C0C0';
  103. closeBtn.style.border = '2px outset #808080';
  104. closeBtn.style.color = '#000';
  105. closeBtn.style.cursor = 'pointer';
  106. controls.appendChild(closeBtn);
  107.  
  108. closeBtn.addEventListener('click', () => {
  109. hud.classList.remove("fade-show");
  110. hud.classList.add("fade-hide");
  111. setTimeout(() => {
  112. if (hud.parentNode) hud.parentNode.removeChild(hud);
  113. }, 250);
  114. });
  115.  
  116. // Pre (splash + messages)
  117. const pre = document.createElement('pre');
  118. pre.style.margin = '0';
  119. pre.style.whiteSpace = 'pre-wrap';
  120. pre.style.background = '#FFFFFF';
  121. pre.style.border = '2px inset #808080';
  122. pre.style.color = localStorage.e_gOS_textColor || '#0F0';
  123. hud.appendChild(pre);
  124.  
  125. // Text editor
  126. const editor = document.createElement('textarea');
  127. editor.style.width = '100%';
  128. editor.style.height = '120px';
  129. editor.style.display = 'none';
  130. editor.style.background = '#FFFFFF';
  131. editor.style.color = localStorage.e_gOS_textColor || '#000';
  132. editor.style.fontFamily = 'monospace';
  133. editor.style.border = '2px inset #808080';
  134. editor.style.resize = 'none';
  135. hud.appendChild(editor);
  136.  
  137. // Canvas
  138. const canvas = document.createElement('canvas');
  139. canvas.width = SCREEN_WIDTH * 15;
  140. canvas.height = SCREEN_HEIGHT * 15;
  141. canvas.style.display = 'none';
  142. canvas.style.marginTop = '5px';
  143. canvas.style.border = '2px inset #808080';
  144. hud.appendChild(canvas);
  145. const ctx = canvas.getContext('2d');
  146.  
  147. // Palette
  148. const paletteDiv = document.createElement('div');
  149. paletteDiv.style.display = 'none';
  150. paletteDiv.style.marginTop = '5px';
  151. hud.appendChild(paletteDiv);
  152.  
  153. // Buttons area
  154. const buttonsDiv = document.createElement('div');
  155. buttonsDiv.style.marginTop = '5px';
  156. hud.appendChild(buttonsDiv);
  157.  
  158. // Helper: create a HUD-style button
  159. function createButton(label, onClick) {
  160. const btn = document.createElement('button');
  161. btn.innerText = label;
  162. btn.style.marginRight = '5px';
  163. btn.style.background = '#C0C0C0';
  164. btn.style.border = '2px outset #808080';
  165. btn.style.color = '#000';
  166. btn.style.fontSize = '12px';
  167. btn.style.cursor = 'pointer';
  168. btn.addEventListener('click', onClick);
  169. buttonsDiv.appendChild(btn);
  170. }
  171.  
  172. function renderButtons(labels, callbacks) {
  173. buttonsDiv.innerHTML = '';
  174. labels.forEach((label, idx) => createButton(label, callbacks[idx]));
  175. }
  176.  
  177. /* ---------------- Dragging HUD ---------------- */
  178. let isDragging = false, offsetX = 0, offsetY = 0;
  179. header.addEventListener('mousedown', e => {
  180. if (e.target === minimizeBtn || e.target === closeBtn) return;
  181. isDragging = true;
  182. offsetX = e.clientX - hud.offsetLeft;
  183. offsetY = e.clientY - hud.offsetTop;
  184. });
  185. document.addEventListener('mouseup', () => isDragging = false);
  186. document.addEventListener('mousemove', e => {
  187. if (isDragging) {
  188. hud.style.left = (e.clientX - offsetX) + 'px';
  189. hud.style.top = (e.clientY - offsetY) + 'px';
  190. }
  191. });
  192.  
  193. // MINIMIZE
  194. minimizeBtn.addEventListener('click', () => {
  195. minimized = !minimized;
  196. pre.style.display = minimized ? 'none' : 'block';
  197. editor.style.display = minimized ? 'none' : editor.style.display;
  198. canvas.style.display = minimized ? 'none' : canvas.style.display;
  199. paletteDiv.style.display = minimized ? 'none' : paletteDiv.style.display;
  200. buttonsDiv.style.display = minimized ? 'none' : 'block';
  201. hud.style.height = minimized ? '40px' : '450px';
  202. });
  203.  
  204. /* ---------------- Canvas Logic ---------------- */
  205. function renderCanvas() {
  206. for (let y = 0; y < SCREEN_HEIGHT; y++) {
  207. for (let x = 0; x < SCREEN_WIDTH; x++) {
  208. ctx.fillStyle = pixelGrid[y][x];
  209. ctx.fillRect(x * 15, y * 15, 15, 15);
  210. }
  211. }
  212. }
  213.  
  214. function setupCanvasMouse() {
  215. paletteDiv.style.display = 'block';
  216. renderCanvas();
  217.  
  218. let isDrawing = false;
  219. function drawPixel(e) {
  220. const rect = canvas.getBoundingClientRect();
  221. const x = Math.floor((e.clientX - rect.left) / 15);
  222. const y = Math.floor((e.clientY - rect.top) / 15);
  223. if (x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT) {
  224. pixelGrid[y][x] = currentColor;
  225. renderCanvas();
  226. }
  227. }
  228.  
  229. canvas.addEventListener('mousedown', e => {
  230. isDrawing = true;
  231. drawPixel(e);
  232. });
  233. canvas.addEventListener('mousemove', e => {
  234. if (isDrawing) drawPixel(e);
  235. });
  236. document.addEventListener('mouseup', () => { isDrawing = false; });
  237. }
  238.  
  239. function setupPalette() {
  240. paletteDiv.style.display = 'block';
  241. paletteDiv.innerHTML = '';
  242. const colors = [
  243. '#FF0000', '#00FF00', '#0000FF', '#FFFF00',
  244. '#FF00FF', '#00FFFF', '#FFFFFF', '#000000',
  245. '#888888', '#FFA500'
  246. ];
  247. colors.forEach(c => {
  248. const swatch = document.createElement('div');
  249. swatch.style.display = 'inline-block';
  250. swatch.style.width = '20px';
  251. swatch.style.height = '20px';
  252. swatch.style.marginRight = '2px';
  253. swatch.style.background = c;
  254. swatch.style.cursor = 'pointer';
  255. swatch.style.border = '1px solid #808080';
  256. swatch.addEventListener('click', () => { currentColor = c; });
  257. paletteDiv.appendChild(swatch);
  258. });
  259. }
  260.  
  261. /* ---------------- HOME SCREEN ---------------- */
  262. function gohome() {
  263. editor.style.display = 'none';
  264. canvas.style.display = 'none';
  265. pre.style.display = 'none';
  266. paletteDiv.style.display = 'none';
  267.  
  268. const oldList = hud.querySelector('#file-list');
  269. if (oldList) hud.removeChild(oldList);
  270.  
  271. const listDiv = document.createElement('div');
  272. listDiv.id = 'file-list';
  273. listDiv.style.marginTop = '5px';
  274. listDiv.style.background = '#FFFFFF';
  275. listDiv.style.border = '2px inset #808080';
  276. hud.appendChild(listDiv);
  277.  
  278. const files = Object.keys(JSON.parse(localStorage.os));
  279. const pageFiles = files.slice((page - 1) * 14, page * 14);
  280. pageFiles.forEach(filename => {
  281. const fileBtn = document.createElement('div');
  282. fileBtn.innerText = filename;
  283. fileBtn.style.cursor = 'pointer';
  284. fileBtn.style.color = '#000';
  285. fileBtn.style.padding = '2px 0';
  286. fileBtn.addEventListener('click', () => {
  287. selected = filename;
  288. readFile();
  289. });
  290. listDiv.appendChild(fileBtn);
  291. });
  292.  
  293. renderButtons(['Create File', 'Page+', 'Page-', 'Options'], [
  294. createFilePrompt,
  295. () => { page++; gohome(); },
  296. () => { page = Math.max(1, page - 1); gohome(); },
  297. showOptionsMenu
  298. ]);
  299. }
  300.  
  301. /* ---------------- FILE DELETION ---------------- */
  302. function deleteFile() {
  303. if (!selected) return;
  304. if (!confirm(`Delete "${selected}"?`)) return;
  305. const os = JSON.parse(localStorage.os);
  306. delete os[selected];
  307. localStorage.os = JSON.stringify(os);
  308. selected = null;
  309. gohome();
  310. }
  311.  
  312. /* ---------------- CREATE FILE MODAL + FADE ---------------- */
  313. function createModalBase(titleText, width = "300px") {
  314. const modal = document.createElement('div');
  315. modal.style.position = 'fixed';
  316. modal.style.top = '50%';
  317. modal.style.left = '50%';
  318. modal.style.transform = 'translate(-50%, -50%)';
  319. modal.style.width = width;
  320. modal.style.background = '#C0C0C0';
  321. modal.style.border = '2px outset #808080';
  322. modal.style.zIndex = 1000000;
  323. modal.style.padding = '10px';
  324. modal.style.fontFamily = 'monospace';
  325.  
  326. // fade-in
  327. modal.classList.add("fade-window");
  328. setTimeout(() => modal.classList.add("fade-show"), 10);
  329.  
  330. // HEADER
  331. const header = document.createElement('div');
  332. header.style.display = 'flex';
  333. header.style.justifyContent = 'space-between';
  334. header.style.alignItems = 'center';
  335. header.style.background = '#000080';
  336. header.style.color = '#fff';
  337. header.style.fontWeight = 'bold';
  338. header.style.padding = '2px 5px';
  339. header.style.borderBottom = '2px solid #808080';
  340. header.style.cursor = 'move';
  341. modal.appendChild(header);
  342.  
  343. const title = document.createElement('span');
  344. title.innerText = titleText;
  345. header.appendChild(title);
  346.  
  347. const closeBtn = document.createElement('button');
  348. closeBtn.innerText = 'X';
  349. closeBtn.style.background = '#C0C0C0';
  350. closeBtn.style.border = '2px outset #808080';
  351. closeBtn.style.color = '#000';
  352. closeBtn.style.cursor = 'pointer';
  353. closeBtn.style.fontSize = '12px';
  354. closeBtn.style.padding = '0 4px';
  355. closeBtn.style.width = '20px';
  356. closeBtn.addEventListener('click', () => {
  357. modal.classList.remove("fade-show");
  358. modal.classList.add("fade-hide");
  359. setTimeout(() => modal.remove(), 250);
  360. });
  361. header.appendChild(closeBtn);
  362.  
  363. // drag logic
  364. let dragging = false, dx = 0, dy = 0;
  365. header.addEventListener('mousedown', e => {
  366. if (e.target === closeBtn) return;
  367. dragging = true;
  368. const r = modal.getBoundingClientRect();
  369. dx = e.clientX - r.left;
  370. dy = e.clientY - r.top;
  371. });
  372.  
  373. document.addEventListener('mousemove', e => {
  374. if (dragging) {
  375. modal.style.left = `${e.clientX - dx}px`;
  376. modal.style.top = `${e.clientY - dy}px`;
  377. modal.style.transform = "none";
  378. }
  379. });
  380.  
  381. document.addEventListener('mouseup', () => dragging = false);
  382.  
  383. document.body.appendChild(modal);
  384. return modal;
  385. }
  386.  
  387. function createFilePrompt() {
  388. const modal = createModalBase("Create New File");
  389.  
  390. const input = document.createElement('input');
  391. input.type = 'text';
  392. input.placeholder = 'Enter file name (txt, png, ran)';
  393. input.style.width = '100%';
  394. input.style.marginTop = '10px';
  395. input.style.padding = '2px';
  396. modal.appendChild(input);
  397.  
  398. const btnDiv = document.createElement('div');
  399. btnDiv.style.marginTop = '10px';
  400. btnDiv.style.textAlign = 'right';
  401. modal.appendChild(btnDiv);
  402.  
  403. const createBtn = document.createElement('button');
  404. createBtn.innerText = 'Create';
  405. createBtn.style.background = '#C0C0C0';
  406. createBtn.style.border = '2px outset #808080';
  407. createBtn.style.color = '#000';
  408. createBtn.style.cursor = 'pointer';
  409.  
  410. createBtn.addEventListener('click', () => {
  411. const name = input.value.trim();
  412. if (!name) return alert("Enter a name.");
  413. createFile(name);
  414.  
  415. modal.classList.remove("fade-show");
  416. modal.classList.add("fade-hide");
  417. setTimeout(() => modal.remove(), 250);
  418. });
  419.  
  420. btnDiv.appendChild(createBtn);
  421.  
  422. input.focus();
  423. }
  424.  
  425. /* ---------------- RENAME MODAL (WITH FADE) ---------------- */
  426. function renameFile() {
  427. if (!selected) return;
  428.  
  429. const modal = createModalBase("Rename File");
  430.  
  431. const input = document.createElement('input');
  432. input.type = 'text';
  433. input.value = selected;
  434. input.style.width = '100%';
  435. input.style.marginTop = '10px';
  436. input.style.padding = '2px';
  437. modal.appendChild(input);
  438.  
  439. const btnDiv = document.createElement('div');
  440. btnDiv.style.marginTop = '10px';
  441. btnDiv.style.textAlign = 'right';
  442. modal.appendChild(btnDiv);
  443.  
  444. const renameBtn = document.createElement('button');
  445. renameBtn.innerText = 'Rename';
  446. renameBtn.style.background = '#C0C0C0';
  447. renameBtn.style.border = '2px outset #808080';
  448. renameBtn.style.color = '#000';
  449. renameBtn.style.cursor = 'pointer';
  450.  
  451. renameBtn.addEventListener('click', () => {
  452. const newName = input.value.trim();
  453. if (!newName || newName === selected) return;
  454.  
  455. const os = JSON.parse(localStorage.os);
  456. if (os[newName]) return alert("File already exists.");
  457.  
  458. os[newName] = os[selected];
  459. delete os[selected];
  460. localStorage.os = JSON.stringify(os);
  461.  
  462. selected = newName;
  463. readFile();
  464.  
  465. modal.classList.remove("fade-show");
  466. modal.classList.add("fade-hide");
  467. setTimeout(() => modal.remove(), 250);
  468. });
  469.  
  470. btnDiv.appendChild(renameBtn);
  471.  
  472. input.focus();
  473. }
  474.  
  475. /* ---------------- READ FILE ---------------- */
  476. function readFile() {
  477. if (!selected) return;
  478.  
  479. const os = JSON.parse(localStorage.os);
  480. let val = os[selected];
  481.  
  482. editor.style.display = 'none';
  483. canvas.style.display = 'none';
  484. pre.style.display = 'none';
  485. paletteDiv.style.display = 'none';
  486.  
  487. if (selected.endsWith('.txt')) {
  488. editor.value = val;
  489. editor.style.display = 'block';
  490. renderButtons(['Save', 'Home', 'Delete', 'Rename'], [saveFile, gohome, deleteFile, renameFile]);
  491. }
  492.  
  493. else if (selected.endsWith('.ran')) {
  494. if (!Array.isArray(val) || !Array.isArray(val[0])) {
  495. const grid = Array.from({ length: SCREEN_HEIGHT }, () =>
  496. Array.from({ length: SCREEN_WIDTH }, () =>
  497. `#${Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0')}`
  498. )
  499. );
  500. os[selected] = grid;
  501. localStorage.os = JSON.stringify(os);
  502. val = grid;
  503. }
  504.  
  505. pixelGrid = val.map(r => r.slice());
  506. canvas.style.display = 'block';
  507. renderCanvas();
  508. setupCanvasMouse();
  509. setupPalette();
  510. renderButtons(['Save', 'Home', 'Delete', 'Rename'], [saveCanvasFile, gohome, deleteFile, renameFile]);
  511. }
  512.  
  513. else if (selected.match(/\.(png|jpg|jpeg)$/)) {
  514. if (Array.isArray(val) && Array.isArray(val[0]))
  515. pixelGrid = val.map(r => r.slice());
  516. else
  517. pixelGrid = Array.from({ length: SCREEN_HEIGHT }, () => Array(SCREEN_WIDTH).fill('#000000'));
  518.  
  519. canvas.style.display = 'block';
  520. renderCanvas();
  521. setupCanvasMouse();
  522. setupPalette();
  523. renderButtons(['Save', 'Home', 'Delete', 'Rename'], [saveCanvasFile, gohome, deleteFile, renameFile]);
  524. }
  525.  
  526. else {
  527. pre.style.display = 'block';
  528. pre.textContent = "Cannot display file.";
  529. renderButtons(['Home', 'Delete'], [gohome, deleteFile]);
  530. }
  531. }
  532.  
  533. /* ---------------- CREATE FILE ---------------- */
  534. function createFile(name) {
  535. const os = JSON.parse(localStorage.os);
  536.  
  537. if (!os[name]) {
  538. if (name.endsWith('.txt')) os[name] = "empty";
  539. else if (name.endsWith('.ran')) os[name] = 1;
  540. else os[name] = Array.from({ length: SCREEN_HEIGHT }, () =>
  541. Array(SCREEN_WIDTH).fill('#000000')
  542. );
  543. localStorage.os = JSON.stringify(os);
  544. }
  545.  
  546. selected = name;
  547. readFile();
  548. }
  549.  
  550. /* ---------------- SAVE FUNCS ---------------- */
  551. function saveFile() {
  552. const os = JSON.parse(localStorage.os);
  553. os[selected] = editor.value;
  554. localStorage.os = JSON.stringify(os);
  555. readFile();
  556. }
  557.  
  558. function saveCanvasFile() {
  559. const os = JSON.parse(localStorage.os);
  560. os[selected] = pixelGrid.map(r => r.slice());
  561. localStorage.os = JSON.stringify(os);
  562. readFile();
  563. }
  564.  
  565. /* ---------------- OPTIONS MENU (WITH FADE) ---------------- */
  566. function showOptionsMenu() {
  567. const modal = createModalBase("Options", "400px");
  568.  
  569. const content = document.createElement('div');
  570. content.style.marginTop = '10px';
  571. modal.appendChild(content);
  572.  
  573. function addLabelInput(labelText, type, val) {
  574. const l = document.createElement('label');
  575. l.textContent = labelText;
  576. l.style.display = 'block';
  577. l.style.marginTop = '5px';
  578. content.appendChild(l);
  579.  
  580. const i = document.createElement('input');
  581. i.type = type;
  582. i.value = val;
  583. if (type === 'number') i.style.width = '100%';
  584. content.appendChild(i);
  585. return i;
  586. }
  587.  
  588. const splashInput = addLabelInput('Splash Screen Text:', 'text', localStorage.e_gOS_splash || "Welcome to e_g.OS HUD Mode!");
  589. const barWidthInput = addLabelInput('Progress Bar Width:', 'number', localStorage.e_gOS_barWidth || 30);
  590. const hudColorInput = addLabelInput('HUD Background Color:', 'color', localStorage.e_gOS_hudColor || '#C0C0C0');
  591. const barColorInput = addLabelInput('Progress Bar Color:', 'color', localStorage.e_gOS_barColor || '#00FF00');
  592. const textColorInput = addLabelInput('Text Color:', 'color', localStorage.e_gOS_textColor || '#0F0');
  593. const typingSpeedInput = addLabelInput('Typing Speed (ms per char):', 'number', localStorage.e_gOS_typingSpeed || 50);
  594.  
  595. const btnDiv = document.createElement('div');
  596. btnDiv.style.marginTop = '10px';
  597. btnDiv.style.textAlign = 'right';
  598. modal.appendChild(btnDiv);
  599.  
  600. const saveBtn = document.createElement('button');
  601. saveBtn.innerText = 'Save';
  602. saveBtn.style.background = '#C0C0C0';
  603. saveBtn.style.border = '2px outset #808080';
  604. saveBtn.style.color = '#000';
  605. saveBtn.style.cursor = 'pointer';
  606.  
  607. saveBtn.addEventListener('click', () => {
  608. localStorage.e_gOS_splash = splashInput.value;
  609. localStorage.e_gOS_barWidth = parseInt(barWidthInput.value) || 30;
  610. localStorage.e_gOS_hudColor = hudColorInput.value;
  611. localStorage.e_gOS_barColor = barColorInput.value;
  612. localStorage.e_gOS_textColor = textColorInput.value;
  613. localStorage.e_gOS_typingSpeed = parseInt(typingSpeedInput.value) || 50;
  614.  
  615. hud.style.background = hudColorInput.value;
  616. pre.style.color = textColorInput.value;
  617.  
  618. modal.classList.remove("fade-show");
  619. modal.classList.add("fade-hide");
  620. setTimeout(() => modal.remove(), 250);
  621. });
  622.  
  623. btnDiv.appendChild(saveBtn);
  624. }
  625.  
  626. /* ---------------- SPLASH SCREEN ---------------- */
  627. function start() {
  628. pre.style.display = 'block';
  629. pre.style.color = localStorage.e_gOS_textColor || '#0F0';
  630.  
  631. const text = localStorage.e_gOS_splash || "Welcome to e_g.OS HUD Mode!\n";
  632. const barW = parseInt(localStorage.e_gOS_barWidth) || 30;
  633. const barColor = localStorage.e_gOS_barColor || '#00FF00';
  634. const speed = parseInt(localStorage.e_gOS_typingSpeed) || 50;
  635.  
  636. let typed = 0;
  637. let prog = 0;
  638. let cursorBlink = true;
  639.  
  640. function escapeHtml(s) {
  641. return s.replace(/[&<>"']/g, m => ({
  642. '&': '&amp;', '<': '&lt;', '>': '&gt;',
  643. '"': '&quot;', "'": '&#39;'
  644. }[m]));
  645. }
  646.  
  647. function renderBar() {
  648. const bar = "█".repeat(prog) + " ".repeat(barW - prog);
  649. const cursor = cursorBlink ? "_" : " ";
  650. pre.innerHTML =
  651. escapeHtml(text.slice(0, typed)) +
  652. `<span style="color:${barColor}">[${bar}]</span>` +
  653. cursor;
  654.  
  655. cursorBlink = !cursorBlink;
  656. }
  657.  
  658. const typingInterval = setInterval(() => {
  659. if (typed < text.length) {
  660. typed++;
  661. renderBar();
  662. } else {
  663. clearInterval(typingInterval);
  664.  
  665. const progressInterval = setInterval(() => {
  666. if (prog < barW) {
  667. prog++;
  668. renderBar();
  669. } else {
  670. clearInterval(progressInterval);
  671. pre.innerHTML =
  672. escapeHtml(text) +
  673. `<span style="color:${barColor}">[${"█".repeat(barW)}]</span>`;
  674.  
  675. setTimeout(gohome, 300);
  676. }
  677. }, 100);
  678. }
  679. }, Math.max(10, speed));
  680. }
  681.  
  682. /* ---------------- INIT ---------------- */
  683. function init() {
  684. hud.style.background = localStorage.e_gOS_hudColor || hud.style.background;
  685. pre.style.color = localStorage.e_gOS_textColor || pre.style.color;
  686.  
  687. if (!window.e_gOS) window.e_gOS = { gohome, readFile, createFile };
  688. start();
  689. }
  690.  
  691. init();
  692.  
  693. })();
  694.  
Advertisement
Add Comment
Please, Sign In to add comment