-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.html
More file actions
2638 lines (2190 loc) · 96.5 KB
/
cli.html
File metadata and controls
2638 lines (2190 loc) · 96.5 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<!-- Thanks for your curiosity, ya big ol' geek! CLI browsing interface by Michael Kupietz -->
<!-- Much thanks to the Indieweb Homebrew Website Club Europe/London for much inspiration and input -->
<!-- the master version of this is hosted at https://github.com/kupietools/web-CLI-browser -->
<!-- Copyright (C) 2025 Michael E Kupietz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
-->
<!-- Contact:
CLI@michaelkupietz.com
Creative arts & tech showcase: https://michaelkupietz.com
Github: https://github.com/kupietools
Consulting: https://www.kupietz.com
Seeking work as of this writing. Somebody please offer me a job.
-->
<head>
<script id="global-settings">
/*** some user-settable defaults ***/
let defaultOptions = {
/* These are the default settings used if nothing specified via url parameter or command line.
* Any parameter not listed with a default here will be ignored. */
prompt: "pet",
language: "cli-html",
flavor: "",
starturl: "",
allcaps: false,
crt: "bw",
nobeep: false
};
let githubInfo = {
updateChecking: true,
/* if updateChecking is true, this file will be checked against the master on github at startup, and you will receive an update message if the master has been updated. */
/* Following is the information for where the master of this file is hosted on Github. If you fork this, update these: */
username: "kupietools",
reponame: "web-CLI-browser",
branch: "master",
filename: "cli.html"
};
let languages = {
/* here you can define new synonyms for default commands in the form new:default, to create other languages. */
/* Defining a synonym for a command will DISABLE the default form of the command. */
"unix": {
"curl": "load",
"cat": "display",
"imagemagick": "images",
"ls": "links",
"shutdown" : "reboot",
"which": "where",
"man": "help",
"cd": "follow",
"setopt": "options",
"bell":"beep",
"nano":"source"
},
"basic": {
"load": "load",
"peek": "where",
"cls": "clear",
"run": "display",
"gr": "images",
"dir": "links",
"goto": "follow",
"poke": "options",
"restart": "reboot",
"hgr2":"image",
"list":"source",
"sysinfo":"info",
"print":"echo"
},
"pig-latin": {
"oadlay": "load",
"ackbay": "back",
"earclay": "clear",
"imagesway": "images",
"imageway":"image",
"optionsway": "options",
"erewhay": "where",
"isplayday": "display",
"exitway": "exit",
"ollowfay": "follow",
"orwardfay": "forward",
"epgray": "grep",
"elphay": "help",
"inthay": "hint",
"inkslay": "links",
"oremay": "more",
"eloadray": "reload",
"infoway": "info",
"udosay": "sudo",
"akesnay": "snake",
"ebootray": "reboot",
"eepbay":"beep",
"ourcesay":"source",
"echoway":"echo"
}
};
/* end user settings */
let info={
news:()=>`News:
• Mike is looking for work. You could have the creativity and talent that spends its spare time doing things like this working for you. Email inquiries@kupietz.com or call 415-545-8743. Resume: https://www.kupietz.com.
• The "image" and "follow" commands have been deprecated as of May '25 and folded into the '${cmdOut("images")}' and '${cmdOut("links")}' commands. See '${cmdOut("help")}'.
• You can have this front end for your own website! Grab it at https://github.com/kupietools/web-CLI-browser. With the default settings, it will check Github for updates and prompt you to redownload if the app has been updated.
`,
versions:()=> `
Version History:
2025jul10 - visual stuff: reformatted some help, added 'exit' message to startup message and "display | more" to load message.
2025jun27 - added a way to view all hints
2025may17 - add viewport meta tag to fix iOS sizing stupidity, hide '0' child div created by chToPixels, added scrollTo after first initialize to fix iOS scrolling stupidity, change info blocks to ()=> functions so can use cmdOut function defined later
2025apr30 - deprecate "image" and "follow" commands, remove from help, and set up '${cmdOut("images")} imagenumber' and '${cmdOut("links")} linknumber' instead.
2025apr29 - add 'source' and 'echo' commands, revamp 'more' to handle them correctly, get rid of ever using innertext instead of innerhtml in addOutput
2025apr23 - rename 'versions' to 'info' and allow parameters to display specific sections, update version checking to work with this, add reboot command, increase beeposity by 100%, fix click listener so allows you to select text on page to copy abd refocus command input when click to deselect
2025apr22 - change page loaded message to suggest 'display' command more clearly
2025apr20 - Add social media browsing meta tags
2025apr18 - Add hilite to url options and auto-uppercase default options in Help, fixed 'forceuppercase' option and celebrated by renaming it 'allcaps', broke up help for readability, fix so image list clears on new page load
2025apr16 - add optional version checking against Github master, added an xkcd joke (by request of capetjamesg)
2025apr15 - change css to use variables and add commandOut to add hilight color for commands, allow options to accept "default" as value, Make 'pet' default prompt. Fix regression error where PET prompt wasn't putting cursor on next line. Fix terminal padding so LPT crt looks nice. Put a little dashicons globe next to the "loaded' message but then commented it out.
2025apr14 - fix regression error introduced by using ';' instead of ',' in arrays due to terrible habits reinforced by FileMaker, refactor how commands are executed to begin allowing inclusion of manpages and other meta information, get manpages going, cause click on terminal to focus command line element, minor css color changes.
2025apr13 - add scaling to image command so ascii art doesn't wrap, add -a image option, fix event handlers so ArrowUp/ArrowDown position block cursor at end of line, add image scaling readout, add clear command
2025apr12 - update page title to reflect loaded page, add undocumented feature to let Display load other URLs or follow links, add dashicon, add redone image placeholders with saved image array and "images" commands, add image display commands
2025apr11 - add code to move cursor with arrows and clicks in command line
2025apr10 - for consistency, have it stop showing page automatically upon load and only use Display to view, add some fun display options, better formatting for help, handle invalid language selections, added a few more languages for fun.
2025apr9 - add '>' download redirect, versions command, URL parameter settings for prompts/languages/force all caps/other secret sauce, add 'option' command to manipulate settings, add message to confirm page has loaded, add case insensitivitinositude to commands.
2025apr8 - first working version
`,
bugs:()=>`Known bugs:
1.) if you scroll back the history and enter a new command, history index doesn't reset to the end.
2.) Some options don't throw errors if you give them bad values, they're just ignored.
`,
todo:()=>`To Dos:
1.) add -i flag to make image list show images.
2.) Need to test if noscript is handled correctly now
3.) add scale command to scale output
4.) Maybe try to wrap and indent long lines at #terminal width in help etc.
5.) Maybe move languages into an attribute of commands, I dunno
6.) Maybe need a better name. Clish? Wish? Wash?
7.) An option to choose the cursor: block, underscore, pipe
8.) Make the update checking just check the latest update date in versionhistory
9.) Allow choosing ascii set for ascii art? Maybe even custom set from user?
10.) Maybe a parameter to start it with an initial command, and/or without loading a page?
11.) Maybe add a 'reset' command to re-run the initialization.
12.) Breaks totally if given a bad language name. Fix that, check how it handles other wrong options.
13.) Create "help -l [language]" flag to allow viewing help for languages besides the current.
`
};
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta prefix="og: http://ogp.me/ns#" property="og:title" content="CLI Browsing Console | Kupietz ARTS+CODE">
<meta prefix="og: http://ogp.me/ns#" property="og:description" content="An advanced keyboard-controlled, command-line-based website front end. Just type your browsing command, no more tedious pointing and clicking!">
<meta prefix="og: http://ogp.me/ns#" property="og:image" content="https://michaelkupietz.com/wp-content/uploads/2025/04/Screen-Shot-2025-04-20-at-6.07.59-PM.png">
<link href="https://cdn.jsdelivr.net/npm/@icon/dashicons@0.9.0-alpha.4/dashicons.min.css" rel="stylesheet">
<meta charset="UTF-8">
<!-- link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Chivo+Mono:ital,wght@0,100..900;1,100..900&family=VT323&display=swap" rel="stylesheet" -->
<style id="bodystyle">/* styles that shouldn't be in download files go here. */
body {
margin: 0;
padding: 20px;
height: 100vh;
overflow: hidden;
/* had these, but needs more work... text input color & sizew didn't match
font-size:14px;
font-family: "Chivo Mono", monospace,"VT323";
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
*/
}
</style>
<style id="cli_doc_style">
:root {--cursorRight: 1 ;
--bgcolor: #1a1a1a;
--textcolor: #c0c0c0;
--commandcolor: #fff;}
body { background: var(--bgcolor);
color: var(--textcolor); /* #3f3;*/ /* dimmer base green */
font-family: monospace;}
.cliImgOut {
/* font-size:.5em; nah, not sure I like this. */
line-height: 1em;
}
.cliImgOutAscii {
line-height: 1em;
}
.text-title {
color: #9cf; /*#5af;*/ /* bright blue */
}
.text-header {
color: #ffc; /* #ff9; */ /* bright white for headers instead of green */
text-transform: uppercase;
}
.text-link {
color: #8af; /*#fdf;*//* #faf;*/ /* #f5f; *//* bright magenta */
font-size:10px;
}
/*.text-list {
color: #ff5; /~ bright yellow ~/
} */
.text-quote {
color: #aff; /* #5ff;*/ /* bright cyan */
}
.text-img {
color:#964; /*#960;*/
}
.text-bold {
color: #fcc; /*#f99; */ /* bright white */
}
.text-anchor {
color: #cef;/*8de;*/ /* #9ef; *//* #8ef; *//* bright white */
}
.text-summary {
color: #cfc;/* #9f9; */ /* bright white */
}
.text-summary::before {
content: "▶"; /* bright white */
}
.text-detail {
color: #cd9 /* #6c9 */; /* bright white */
}
.idSection {display:none; /* for now, just noting IDs in the code. May allow them to be shown later on by specifying an ID */ }
.mmarker-child-a ~ .dashicons {color: color: #ffb;}
.mmarker-child-a { color: #ffb; /*#ff5;*/ margin-inline: 6px;}
.screen-reader-text {display: none;}
.h6, .titleprefix {
/*text-transform: uppercase;*
/*letter-spacing: 2px;*/
/*font-size: .6875em;*/
font-variant: small-caps;
/*display: block;*/
/*color:#8bc;*//*8ac*//*#def;*/
font-weight: 400;
font-style: normal;
}
.h6:after {content:": ";}
.meta-genre-term {/*font-size: .6875em; */ color:#ccf; /*#99F;*/
/* display: inline-block !important; nah, don't think I need it*/
padding: 2px 3px !important;
line-height: 0.75em;
/* border: 1px solid #33c6ff !important; */
/* background: #ccc /~ #33c6ff ~/ !important; */
width: auto; /* won't actually work now that I've disabled inline-block display */
font-weight: 400 !important;
border-radius:3px;
/* margin-inline:2px; */
}
.meta-genre-term:before {content:'[';}
.meta-genre-term:after {content:']';}
.titleprefix {/* color:#FFC; */text-transform: capitalize;}
.titleprefix:after {content:': ';}
#terminal {
height: calc(100vh - 40px);
overflow-y: auto;
white-space: pre-wrap;
word-wrap: break-word;
padding: 0 12px 40px 12px;
}
#input-line {
display: flex;
align-items: initial ; /*center; caused problems if input wrapped*/
margin-top: 1rem;
}
/* #prompt { NO makes input text shift 8px to the right, then move left when line is entered
margin-right: 8px;
} */
#command-input {
--cursor-offset: 0px;
position: relative;
background: transparent;
border: none;
/* color: #ccc; *//* #33ff33; */
font-family: monospace;
font-size: inherit;
flex-grow: 1;
outline: none;
padding: 0;
margin: 0;
display: inline-block;
caret-color: transparent;
height:inherit;
color:var(--commandcolor);
}
.prevcommand{color:var(--commandcolor); }
#prompt {
min-width: fit-content;
}
#command-input br {
display: none; /* needed because firefox adds a <br> if you vackspace in an empty contenteditable */
}
#command-input:focus::after {
content: "█";
animation: blink 1s steps(1) infinite;
right: var(--cursor-offset);
position: relative;
}
.spacers {color:#333;}
@keyframes blink {
0% { opacity: 1; }
50% { opacity: 0.25; }
}
@keyframes rainbow {
0% { color: red; }
15% { color: orange; }
30% { color: yellow; }
45% { color: green; }
60% { color: blue; }
75% { color: indigo; }
90% { color: violet; }
}
.output {
margin: 0; /* 10px 0; left blank lines in More */
}
.error {
color: #ff3333;
}
.loading {
/* color: #ffff33; */
animation: blink 1s steps(1) infinite/*, rainbow 5s infinite */;
}
.more-prompt {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #1a1a1a;
padding: 10px 20px;
border-top: 1px solid #33ff33;
}
#input-line.hidden {
display: none;
}
</style>
</head>
<body><div id="terminal"><div class="output"> <br>*** KUPIETZ ARTS+CODE ***<p> 7167 BYTES FREE<p>
Welcome to CLI browsing mode.<p>Type '<span id="helplang" class="prevcommand">help</span>' for available commands, or '<span id="exitlang" class="prevcommand">exit</span>' to return to GUI browsing.</div><div id="input-line" class="">
<span id="prompt">$ </span>
<div id="command-input" contenteditable="true" autofocus=""></div>
</div>
</div>
<script>
async function checkForUpdates() {
try {
// Get the current version history from the page
const currentScript = document.getElementById('global-settings');
const currentVersionMatch = currentScript.textContent.match(/versions[\r\n\t ]*:[\r\n\t ]*`([\s\S]*?)`[ \r\t]*[,;]/) || currentScript.textContent.match(/versions[\r\n\t ]*:[\r\n\t ]*'([\s\S]*?)'[ \r\t]*[,;]/) || currentScript.textContent.match(/versions[\r\n\t ]*:[\r\n\t ]*"([\s\S]*?)"[ \r\t]*[,;]/);
const currentVersion = currentVersionMatch ? currentVersionMatch[1] : '';
// Fetch the latest version from GitHub
const response = await fetch(`https://raw.githubusercontent.com/${githubInfo.username}/${githubInfo.reponame}/${githubInfo.branch}/${githubInfo.filename}`);
const text = await response.text();
// Extract version history from the fetched content
const latestVersionMatch = text.match(/versions[\r\n\t ]*:[\r\n\t ]*`([\s\S]*?)`[ \r\t]*[,;]/) || text.match(/versions[\r\n\t ]*:[\r\n\t ]*'([\s\S]*?)'[ \r\t]*[,;]/) || text.match(/versions[\r\n\t ]*:[\r\n\t ]*"([\s\S]*?)"[ \r\t]*[,;]/);
const latestVersion = latestVersionMatch ? latestVersionMatch[1] : '';
// Compare versions
if (githubInfo.updateChecking && currentVersion !== latestVersion) {
/* document.getElementById('updateBanner').style.display = 'block'; */
addOutput("\nThe version of this browser on Github is different from this local version. You may want to check the repo at " + `https://github.com/${githubInfo.username}/${githubInfo.reponame}/${githubInfo.filename}` + " and download the more recent version if necessary. Set githubInfo.updateChecking to false in the app code to disable this message.\n\n");
updatePrompt();
}
}
catch (error)
{ console.log ("Error checking for github update", e);
if (githubInfo.updateChecking) {
addOutput("There was an error checking for updates: " + error + "\n");
}
}
}
checkForUpdates();
var source = "";
var audio = new Audio("data:audio/mpeg;base64,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");
audio.controls = true;
audio.style.display="none";
document.body.appendChild(audio);
const origCRT = defaultOptions["crt"];
let theseOptions = Object.assign({}, defaultOptions); /* all acceptable url parameters must be listed here or they will be ignored */
theseOptions["language"] = theseOptions["language"] || "cli-html";
languages[theseOptions["language"]] = languages[theseOptions["language"]] || {};
const urlParams = new URLSearchParams(window.location.search);
for (const key in theseOptions) {
if (urlParams.has(key)) {
/* this is where urlparams with no key above get disregarded */
theseOptions[key] = urlParams.get(key);
}
}
let prompts = {
"unix": () => {
return currentUrl ? `[${currentUrl}]$ ` : '$ ';
},
"apple": () => '] ',
"pet": () => "READY."
};
let promptLineBreak = "";
if (origCRT != theseOptions["crt"]) {
setCrt(theseOptions["crt"]);
}
const cmdDict = {};
// Process each language
languages = Object.assign(languages, addDicts());
for (const language in languages) {
cmdDict[language] = {};
// Create reverse mapping for this language
for (const key in languages[language]) {
const value = languages[language][key];
cmdDict[language][value] = key;
}
}
document.getElementById("helplang").textContent = cmdInLang("help");
document.getElementById("exitlang").textContent = cmdInLang("exit");
const commandInput = document.getElementById('command-input');
document.getElementById("terminal").addEventListener('mouseup', function() {
console.log(window.getSelection().type);
if (window.getSelection().type != "Range") {
console.log("focusing");
commandInput.focus();}
});
/* begin code to handle moving cursor with mouseclicks */
commandInput.addEventListener('input', updateCursor);
commandInput.addEventListener('click', updateCursor);
commandInput.addEventListener('keyup', updateCursor);
function updateCursor(e = {}) {
/* input = document.getElementById('command-input'); */
if (!e || !e.key || (e.key != "ArrowUp" && e.key != "ArrowDown" /* up and down arrows handle positioning the cursor after loading the next or prev history line in the keydown listener */ )) {
const text = commandInput.textContent;
const cursorPos = window.getSelection().anchorOffset;
const offset = text.length - cursorPos;
commandInput.style.setProperty('--cursor-offset', offset + 'ch');
}
}
updateCursor();
/* end code to handle moving cursor with mouseclicks */
commandInput.addEventListener('keydown', async (e) => {
if (e.key === 'Enter') {
e.preventDefault(); // Prevent default newline
const commandLine = commandInput.textContent.trim();
commandInput.textContent = ''; // Clear the input
if (commandLine) {
commandHistory.push(commandLine);
addOutput(`\n${promptSpan.textContent}${promptLineBreak}<span class="prevcommand">${commandLine}</span>`);
let result;
if (commandLine.toLowerCase().match(/sudo *make *(me *| *)a *sandwich\.*/)) {
result = "\nOkay.";
} else if (commandLine.toLowerCase().match(/make *(me *| *)a *sandwich\.*/)) {
result = "\nWhat? Make your own sandwich";
} else {
result = await executeCommand(commandLine);
}
if (result) {
addOutput(result);
}
if (!currentMoreOutput) {
terminal.scrollTop = terminal.scrollHeight;
}
}
}
});
// Optional: Prevent pasting formatted text
commandInput.addEventListener('paste', (e) => {
e.preventDefault();
const text = e.clipboardData.getData('text/plain');
document.execCommand('insertText', false, text);
});
const terminal = document.getElementById('terminal');
const input = document.getElementById('command-input');
const promptSpan = document.getElementById('prompt');
const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
const PROXY_SERVICES = [
/* a word of explanation here. These are third party CORS proxies included as a kludge, in case something needs to be fetched from another domain [wink] for [wink] some [wink] reason */
(url) => `https://api.allorigins.win/raw?url=${encodeURIComponent(url)}`,
(url) => `https://cors-anywhere.herokuapp.com/${url}`,
(url) => `https://api.codetabs.com/v1/proxy?quest=${encodeURIComponent(url)}`
];
let currentLinks = [];
let currentUrl = '';
let pageCache = new Map();
let currentMoreOutput = null;
let currentCommand = null;
let isCommandRunning = false;
let currentProxyIndex = 0;
let morePromptDiv = null;
let originalURL = "";
let chWidth = chToPixels();
let imageNum = 0;
let imageArray = [];
// New variables for history tracking
let pageHistory = [];
let currentHistoryIndex = -1;
const commandHistory = [];
let historyIndex = -1;
let currentInput = '';
let firstSudo = true;
const SIGNALS = {
SIGINT: '^C',
SIGTSTP: '^Z',
SIGQUIT: '^\\'
};
function chToPixels() {
const temp = document.createElement('span');
temp.style.font = window.getComputedStyle(document.getElementsByTagName("body")[0]).font;
temp.style.fontSize = window.getComputedStyle(document.getElementsByTagName("body")[0]).fontSize;
temp.style.position = 'absolute';
temp.style.visibility = 'hidden';
temp.textContent = '0';
document.body.appendChild(temp);
const zeroWidth = temp.offsetWidth;
document.body.removeChild(temp);
return zeroWidth;
}
function terminalCharWidth() {
return Math.floor(document.getElementsByClassName("output")[0].scrollWidth - 20) / chToPixels();
}
function decodeHtmlEntities(text) {
const textarea = document.createElement('textarea');
textarea.innerHTML = text;
return textarea.value;
}
function getTerminalDimensions() {
const lineHeight = 40;
const promptHeight = 40;
const height = Math.floor((terminal.clientHeight - promptHeight) / lineHeight);
const width = Math.floor(terminal.clientWidth / 8);
return {
height,
width
};
}
function truncateLines(text, width) {
return text.split('\n').map(line =>
line.length > width ? line.slice(0, width - 3) + '...' : line
).join('\n');
}
function updatePrompt() {
if (theseOptions["prompt"] == "pet") {
document.getElementById("input-line").style.flexDirection = "column";
promptLineBreak = "\n";
} else {
document.getElementById("input-line").style.flexDirection = "row";
promptLineBreak = "";
}
promptSpan.textContent = prompts[theseOptions.prompt](); /*was currentUrl ? `[${currentUrl}]$ ` : '$ '; */
}
function toggleInputLine(show) {
const inputLine = document.getElementById('input-line');
if (show) {
inputLine.classList.remove('hidden');
input.focus();
} else {
inputLine.classList.add('hidden');
}
}
function addOutput(text, className = 'output') {
const output = document.createElement('div');
output.className = className;
/* DON'T KNOW WHAT PURPOSE THIS SERVED if ( typeof text === 'string' && !text.includes('</') ) {
output.textContent = text;
} else { */
output.innerHTML = text;
/* } */
terminal.insertBefore(output, input.parentElement);
terminal.scrollTop = terminal.scrollHeight;
return output;
}
function showMorePrompt(text) {
if (morePromptDiv) {
morePromptDiv.remove();
}
morePromptDiv = document.createElement('div');
morePromptDiv.className = 'more-prompt';
morePromptDiv.textContent = text;
document.body.appendChild(morePromptDiv);
}
function removeMorePrompt() {
if (morePromptDiv) {
morePromptDiv.remove();
morePromptDiv = null;
}
}
function displaySignal(signal) {
const currentLine = commandInput.textContent;
commandInput.textContent = '';
addOutput(`${promptSpan.textContent}${currentLine}${signal}`);
}
function createMoreHandler(fullText) {
var dims = getTerminalDimensions();
dims.width = .99 * dims.width; /* wasn't getting it quite right, lines too long */
// Split into lines while preserving HTML tags
const lines = [];
let currentLine = '';
let inTag = false;
let tagBuffer = '';
let tagStack = [];
// First split on newlines while preserving HTML tags
for (let i = 0; i < fullText.length; i++) {
const char = fullText[i];
if (char === '<') {
inTag = true;
tagBuffer = char;
} else if (char === '>') {
inTag = false;
tagBuffer += char;
// Check if this is a closing tag
if (tagBuffer.startsWith('</')) {
tagStack.pop();
} else if (!tagBuffer.endsWith('/>')) { // Not a self-closing tag
const tagName = tagBuffer.match(/<([^\s>]+)/)?.[1];
if (tagName) tagStack.push(tagName);
}
currentLine += tagBuffer;
tagBuffer = '';
} else if (inTag) {
tagBuffer += char;
} else if (char === '\n') {
// Only split at newlines if we're not in the middle of a tag
if (!inTag) {
lines.push(currentLine);
currentLine = '';
} else {
currentLine += char;
}
} else {
currentLine += char;
}
}
if (currentLine) {
lines.push(currentLine);
}
let position = 0;
function displayMore() {
if (position >= lines.length) {
currentMoreOutput = null;
removeMorePrompt();
toggleInputLine(true);
return null;
}
let output = '';
let displayedLines = 0;
while (position < lines.length && displayedLines < dims.height - 1) {
const line = lines[position];
let startPos = 0;
let visibleCount = 0;
while (startPos < line.length && displayedLines < dims.height - 1) {
let chunkEnd = startPos;
visibleCount = 0;
while (chunkEnd < line.length && visibleCount < dims.width) {
if (line[chunkEnd] === '<' && line.indexOf('>', chunkEnd) > chunkEnd && /^<\/?[a-zA-Z][^>]*>/.test(line.slice(chunkEnd))) {
// It's a real HTML tag - skip to end
const tagEnd = line.indexOf('>', chunkEnd);
chunkEnd = tagEnd + 1;
} else {
// Regular character
visibleCount++;
chunkEnd++;
}
}
const chunk = line.slice(startPos, chunkEnd);
output += chunk + '\n';
displayedLines++;
startPos = chunkEnd;
}
position++;
}
const percentage = Math.floor((position / lines.length) * 100);
const lineInfo = `lines ${position}/${lines.length}`;
addOutput(output.trimEnd());
if (position < lines.length) {
showMorePrompt(`--Press Space For More--${lineInfo} (${percentage}%)`);
return '';
}
removeMorePrompt();
toggleInputLine(true);
return null;
}
return {
next: displayMore,
cancel: () => {
removeMorePrompt();
toggleInputLine(true);
const remainingLines = lines.length - position;
return `...output cancelled (${remainingLines} lines remaining)`;
}
};
}
/**
* Triggers browser file download with specified content
* @param {string} output - Content to be downloaded
* @param {string} filename - Name of the file to be downloaded
*/
function download_txt(output, myFile) {
// Create a blob with the output content
thisStyle = document.getElementById("cli_doc_style").innerHTML;
output = '<!doctype HTML><html><head><link href="https://cdn.jsdelivr.net/npm/@icon/dashicons@0.9.0-alpha.4/dashicons.min.css" rel="stylesheet"><style>' + thisStyle + '</style><body>' + output.replace(/(?:\r\n|\r|\n)/g, "<br>") + '</body></html>';
const blob = new Blob([output], {
type: 'text/html'
});
// Create a URL for the blob
const url = URL.createObjectURL(blob);
// Create a temporary anchor element
const a = document.createElement('a');
a.href = url;
a.download = myFile;
// Append to the document, click it, then remove it
document.body.appendChild(a);
a.click();
// Clean up
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 100);
return blob.size + " bytes written for download";
}
async function fetchWithRetry(url) {
let lastError;
const loadingIndicator = addOutput(`Loading ${url}... waiting for data (0s)`, 'loading');
let startTime = Date.now();
let waitTimer = setInterval(() => {
const seconds = Math.floor((Date.now() - startTime) / 1000);
loadingIndicator.textContent = `Loading ${url}... waiting for data (${seconds}s)`;
}, 1000);
// Check if URL is same origin and try direct fetch first
if (new URL(url).origin === window.location.origin) {
// Add mklynx parameter to URL
const modifiedUrl = new URL(url);
modifiedUrl.searchParams.append('mklynx', '1');
try {
const response = await fetch(modifiedUrl);
/* that was to add parameter. Orig was
if (new URL(url).origin === window.location.origin) {
try {
const response = await fetch(url); */
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
clearInterval(waitTimer);
const reader = response.body.getReader();
const contentLength = response.headers.get('Content-Length') || 0;
let receivedLength = 0;
let chunks = [];
while (true) {
const {
done,
value
} = await reader.read();
if (done) break;
chunks.push(value);
receivedLength += value.length;
const percent = contentLength ?
Math.round((receivedLength / contentLength) * 100) :
`${(receivedLength / 1024).toFixed(1)}KB`;
loadingIndicator.textContent = contentLength ?
`Loading ${url}... ${percent}% (${(receivedLength / 1024).toFixed(1)}KB of ${(contentLength / 1024).toFixed(1)}KB)` :
`Loading ${url}... ${percent} received`;
}
loadingIndicator.remove();
const chunksAll = new Uint8Array(receivedLength);
let position = 0;
for (let chunk of chunks) {
chunksAll.set(chunk, position);
position += chunk.length;
}
return new TextDecoder("utf-8").decode(chunksAll);
} catch (err) {
console.log('Direct fetch failed:', err);
// Fall through to proxy system
}
}
// proxy logic
for (let i = 0; i < PROXY_SERVICES.length; i++) {
const proxyUrl = PROXY_SERVICES[(currentProxyIndex + i) % PROXY_SERVICES.length](url);
try {
const response = await fetch(proxyUrl, {
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
clearInterval(waitTimer);
const reader = response.body.getReader();
const contentLength = response.headers.get('Content-Length') || 0;
let receivedLength = 0;
let chunks = [];
while (true) {
const {
done,
value
} = await reader.read();
if (done) break;
chunks.push(value);
receivedLength += value.length;
const percent = contentLength ?
Math.round((receivedLength / contentLength) * 100) :
`${(receivedLength / 1024).toFixed(1)}KB`;
loadingIndicator.textContent = contentLength ?
`Loading ${url}... ${percent}% (${(receivedLength / 1024).toFixed(1)}KB of ${(contentLength / 1024).toFixed(1)}KB)` :
`Loading ${url}... ${percent} received`;
}
currentProxyIndex = (currentProxyIndex + i) % PROXY_SERVICES.length;
loadingIndicator.remove();
const chunksAll = new Uint8Array(receivedLength);
let position = 0;
for (let chunk of chunks) {
chunksAll.set(chunk, position);
position += chunk.length;
}
return new TextDecoder("utf-8").decode(chunksAll);
} catch (err) {
console.log("Loading error, trying new proxy: ",err);
lastError = err;
loadingIndicator.textContent = `Loading ${url}... Retrying with different proxy (${err.message})`;
continue;
}
}
clearInterval(waitTimer);
loadingIndicator.remove();
/* was throw lastError; but wanted more detail */
throw new Error(`Sorry, we couldn't load ${url} right now after trying ${PROXY_SERVICES.length} different methods. This could be because the site is down, blocking access, or our connection methods aren't working. Last error was: ${lastError}. The site may be blocking proxy access. Please try again in a few minutes.`);
}
function processNode(node, linkMap, indent = 0) {
let content = '';
let spacer = '<span class="spacers">' + ('| '.repeat(indent)) + '</span>';
if (node.nodeType === Node.TEXT_NODE) {
const text = node.textContent.trim();
if (text) {
const parentAnchor = node.parentElement.closest('a');
if (parentAnchor && linkMap.has(parentAnchor)) {
if (!parentAnchor._numbered) {
content += `<span class="text-link">[${linkMap.get(parentAnchor) + 1}]</span>`;
parentAnchor._numbered = true;
}
}
content += text;
}
return content;
}