From 8032278b5fb5a4b4e7431dcdccb0943ceb199f4b Mon Sep 17 00:00:00 2001 From: #TheDayG0ne Date: Mon, 31 Jul 2023 13:13:16 +0700 Subject: [PATCH 1/3] Add matrix command --- src/commands/General/matrix.js | 67 ++++++++++++++++++++++++++++++++++ src/registration.js | 2 + 2 files changed, 69 insertions(+) create mode 100644 src/commands/General/matrix.js diff --git a/src/commands/General/matrix.js b/src/commands/General/matrix.js new file mode 100644 index 0000000..71fa372 --- /dev/null +++ b/src/commands/General/matrix.js @@ -0,0 +1,67 @@ +export default class MatrixCommand { + execute(term, params, directory, setDirectory) { + var canvas = document.createElement("canvas"); + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; + canvas.style.position = "absolute"; + canvas.style.top = "0"; + canvas.style.left = "0"; + canvas.style.zIndex = "1"; + term.element.appendChild(canvas); + + var ctx = canvas.getContext("2d"); + var symbols = "01"; + var fontSize = 14; + var columns = canvas.width / fontSize; + var drops = []; + + for (var i = 0; i < columns; i++) { + drops[i] = Math.floor(Math.random() * canvas.height); + } + + function draw() { + ctx.fillStyle = "rgba(0, 0, 0, 0.05)"; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.font = fontSize + "px monospace"; + ctx.fillStyle = "#0F0"; + + for (var i = 0; i < columns; i++) { + var symbol = symbols[Math.floor(Math.random() * symbols.length)]; + + ctx.fillText(symbol, i * fontSize, drops[i] * fontSize); + + if (Math.random() > 0.99) { + drops[i] = 0; + } else { + drops[i]++; + } + } + + requestAnimationFrame(draw); + } + draw(); + + setTimeout(function() { + function fadeOut() { + canvas.style.opacity -= 0.01; + if (canvas.style.opacity > 0) { + setTimeout(fadeOut, 20); + } else { + term.element.removeChild(canvas); + } + } + fadeOut(); + }, 5000); + } + + description() { + return "Displays an animation of a binary rain from The Matrix"; + } + + help(term) { + term.writeln("The matrix command displays an animation of a binary rain from The Matrix on a canvas over the console for 5 seconds."); + term.writeln("The canvas fades out smoothly after the animation."); + term.writeln("To stop the animation earlier, you need to close and reopen the terminal."); + } + } + \ No newline at end of file diff --git a/src/registration.js b/src/registration.js index 47e8824..c9fb41e 100644 --- a/src/registration.js +++ b/src/registration.js @@ -27,6 +27,7 @@ import StatusCommand from "./commands/System/status"; import AboutmeCommand from "./commands/Utility/aboutme"; import DownloadCommand from "./commands/Filesystem/download"; import UploadCommand from "./commands/Filesystem/upload"; +import MatrixCommand from "./commands/General/matrix"; export const registerAllCommands = () => { let registeredCommands = {}; @@ -58,6 +59,7 @@ export const registerAllCommands = () => { registeredCommands['confetti'] = new ConfettiCommand(); registeredCommands['httpcat'] = new HttpcatCommand(); registeredCommands['httpdog'] = new HttpdogCommand(); + registeredCommands['matrix'] = new MatrixCommand(); // Utility commands registeredCommands['echo'] = new EchoCommand(); From f5c87c674999160e0544633a6bbb400dd2d51cc2 Mon Sep 17 00:00:00 2001 From: #TheDayG0ne Date: Mon, 31 Jul 2023 13:25:37 +0700 Subject: [PATCH 2/3] catch errors in index.js --- src/index.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 5119384..442c415 100644 --- a/src/index.js +++ b/src/index.js @@ -32,15 +32,31 @@ BrowserFS.configure({ window.path = window.require("path"); setTimeout(() => { - window.fs.writeFileSync(`/temp/host`, window.location.host); - window.fs.writeFileSync(`/temp/language`, window.navigator.language); - window.fs.writeFileSync(`/temp/user-agent`, window.navigator.userAgent); - window.fs.writeFileSync(`/temp/user-agent.json`, JSON.stringify(window.navigator.userAgentData, null, 2)); + try { + window.fs.writeFileSync(`/temp/host`, window.location.host); + } catch (e) { + } + + try { + window.fs.writeFileSync(`/temp/language`, window.navigator.language); + } catch (e) { + } + + try { + window.fs.writeFileSync(`/temp/user-agent`, window.navigator.userAgent); + } catch (e) { + } + + try { + window.fs.writeFileSync(`/temp/user-agent.json`, JSON.stringify(window.navigator.userAgentData, null, 2)); + } catch (e) { + } + try { const { downlink, effectiveType, rtt, saveData } = navigator.connection; window.fs.writeFileSync(`/temp/connection`, JSON.stringify({ downlink, effectiveType, rtt, saveData }, null, 2)); - } catch (_) {} + } catch (e) {} }, 100); const root = ReactDOM.createRoot(document.getElementById('root')); From 95fecbc20b294cc9a4c316dcddd38fe73ebeda3d Mon Sep 17 00:00:00 2001 From: #TheDayG0ne Date: Mon, 31 Jul 2023 14:47:02 +0700 Subject: [PATCH 3/3] Update matrix command --- src/commands/General/matrix.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/General/matrix.js b/src/commands/General/matrix.js index 71fa372..b412abc 100644 --- a/src/commands/General/matrix.js +++ b/src/commands/General/matrix.js @@ -8,6 +8,7 @@ export default class MatrixCommand { canvas.style.left = "0"; canvas.style.zIndex = "1"; term.element.appendChild(canvas); + term.writeln("Entering in The Matrix...") var ctx = canvas.getContext("2d"); var symbols = "01";