From f7d6c8db1fd7fa82c7da96d0f06da4e49fbd9a05 Mon Sep 17 00:00:00 2001 From: amy Date: Thu, 16 Feb 2023 14:04:44 -0600 Subject: a certified mess --- html/display.html | 99 ++++++++++++++++++++------------ src/fs.json | 18 +++++- src/jssh.js | 12 ++++ src/window-utils.js | 159 +++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 242 insertions(+), 46 deletions(-) diff --git a/html/display.html b/html/display.html index da955dd..b9cf718 100644 --- a/html/display.html +++ b/html/display.html @@ -90,6 +90,18 @@ cursor: ns-resize; } + table { + display: table; + } + + table tr { + display: table-cell; + } + + table tr td { + display: block; + } + .resize-e { position: absolute; right: -3px; @@ -300,7 +312,17 @@ position: absolute; padding-top: 3px; background-color: #c7c7c7; + overflow: hidden; + } + .fd-bottom { + width: 100%; + height: 26px; + background-color: #b1b1b1; + position: absolute; + bottom: 0; + overflow: hidden; + white-space: nowrap; } textarea { @@ -333,7 +355,8 @@ input:hover { cursor: text; } - button{ + + button { border-radius: 0px; background-color: #c1c1c1; } @@ -435,7 +458,7 @@ let temp = [] bar.innerHTML = "" for (let i = 0; i != windows.length; i++) { - bar.innerHTML += "
" + windows.item(i).getAttribute("window-name") + "
" + bar.innerHTML += "
" + windows.item(i).getAttribute("window-name") + "
" temp.push({ left: last_left, id: windows.item(i).id, width: bar.children.item(bar.children.length - 1).clientWidth + 5 }) last_left += bar.children.item(bar.children.length - 1).clientWidth + 5 @@ -446,8 +469,9 @@ for (let i = 0; i != bar.children.length; i++) { let elemy = bar.children.item(i) for (let ii = 0; ii != windows.length; ii++) { - if (windows.item(ii).id == elemy.id) { + if (windows.item(ii).id + "-bar" == elemy.id) { //let px = 0, py = 0; + elemy.onmousedown = ((ev) => { for (let iii = 0; iii != windows.length; iii++) { windows.item(iii).style.zIndex = 0; @@ -501,44 +525,48 @@ let minx = 150; let miny = 150; function window_create(uid, name, content, options = {}) { - let lines = content.split("
").length - let a = '' - let size = (options.width != undefined && options.height != undefined) ? ("width:" + options.width + "px;height:" + options.height + "px;") : ("width:" + Math.max(document.body.clientWidth * .56, minx) + "px;height:" + Math.max(miny, document.body.clientHeight * .30) + "px;"); - let pos = (options.left != undefined && options.top != undefined) ? ("left:" + options.left + "px;top:" + options.top + "px;") : ("left:0px;top:0px;"); - a += "
" - //console.log(document.getElementById(uid).attributes["window-name"].value) - a += "
" + name + "
" - a += "
" + ` + let promise = new Promise((res, rej) => { + let lines = content.split("
").length + let a = '' + let size = (options.width != undefined && options.height != undefined) ? ("width:" + options.width + "px;height:" + options.height + "px;") : ("width:" + Math.max(document.body.clientWidth * .36, minx) + "px;height:" + Math.max(miny, document.body.clientHeight * .30) + "px;"); + let pos = (options.left != undefined && options.top != undefined) ? ("left:" + options.left + "px;top:" + options.top + "px;") : ("left:0px;top:0px;"); + a += "
" + //console.log(document.getElementById(uid).attributes["window-name"].value) + a += "
" + name + "
" + a += "
" + `
` - if (options.resize != false && options.resize != "false") { - a += "
" - a += "
" - a += "
" - a += "
" - } - a += "
" - a += "
" + if (options.resize != false && options.resize != "false") { + a += "
" + a += "
" + a += "
" + a += "
" + } + a += "
" + a += "
" - a += "
" + content + "
" - if (options.scroll != false && options.scroll != "false") { - a += "
" + a += "
" + content + "
" + if (options.scroll != false && options.scroll != "false") { + a += "
" + a += "
" + } a += "
" - } - a += "
" - if (options.resize != false && options.resize != "false") { - a += "
" - a += "
" - a += "
" - a += "
" - } - document.getElementById("root").innerHTML += a - //console.log(document.getElementById(uid + "-content-root").clientHeight / (document.getElementById(uid + "-content-content").clientHeight / document.getElementById(uid + "-content-root").clientHeight)) + if (options.resize != false && options.resize != "false") { + a += "
" + a += "
" + a += "
" + a += "
" + } + document.getElementById("root").innerHTML += a + //console.log(document.getElementById(uid + "-content-root").clientHeight / (document.getElementById(uid + "-content-content").clientHeight / document.getElementById(uid + "-content-root").clientHeight)) - //console.log(document.getElementById(uid + "-content-scrollbar-point")) - refresh_windows() + //console.log(document.getElementById(uid + "-content-scrollbar-point")) + refresh_windows() + res() + }) + return promise } function refresh_windows() { load_bar() @@ -873,7 +901,8 @@ async function main() { fs = await req('src/fs.json') - util.alert("test") + fd = await util.fd({ path: '/', filetype: '*' }) + console.log(fd) document.getElementById("bar-menu").onclick = ((ev) => { if (document.getElementById("bar-menu-root").style.display == "block") document.getElementById("bar-menu-root").style.display = "none" diff --git a/src/fs.json b/src/fs.json index b060939..2b93344 100644 --- a/src/fs.json +++ b/src/fs.json @@ -1,23 +1,35 @@ [ + { + "name": "nya", + "perms": { "r": true }, + "dir": true, + "content": [] + }, + { + "name": "file", + "perms": { "r": true }, + "dir": false, + "content": "hi" + }, { "name": "apps", "perms": { "r": true }, "dir": true, "content": [ { - "name": "notepad", + "name": "notepad.exe", "perms": { "r": true }, "dir": false, "content": "window Notepad \nmeta icon src/img/notepad.png" }, { - "name": "cmd", + "name": "cmd.exe", "perms": { "r": true }, "dir": false, "content": "window cmd
λ
\nmeta icon src/img/cmd.png" }, { - "name": "MineSweeper", + "name": "MineSweeper.exe", "perms": { "r": true }, "dir": false, "content": "window uwu nya\nmeta icon src/img/mine.png, resize false, left 250, top 250, width 144, height 210, scroll false\njs window.board#_ID_listeners = [];function lo#_ID_board() {let id = #_ID;let cont = document.getElementById(id + '-content-content');cont.innerHTML=`
`;let width = 9; let height = 10;;let board = [];let score = 0;window.time_#_ID = 0;;for(let uwu of window.board#_ID_listeners){clearInterval(uwu);clearTimeout(uwu)};window.board#_ID_listeners = []; window.pause_#_ID=false;let bombs = 0;let max_bombs=9;for(let i = 0; i!=height;i++){let temp = [];for(let i = 0; i!=width;i++){if(Math.random() < 0.13 && bombs < max_bombs){temp.push(-1);bombs++;} else {temp.push(0);}};board.push(temp);};for(let i = 0; i!= board.length; i++){for(let ii = 0; ii!=board[i].length; ii++){if(board[i][ii]!=-1){board[i][ii] = (i!=0 ? board[i-1][ii]==-1 : 0) + (i!=0 && ii!=0 ? board[i-1][ii-1]==-1 : 0) + (ii!=0 ? board[i][ii-1]==-1 : 0) + (i!=height - 1 && ii!=0 ? board[i+1][ii-1]==-1 : 0) + (i!=height - 1 ? board[i+1][ii]==-1 : 0) + (i!=height - 1 && ii!=width - 1 ? board[i+1][ii+1]==-1 : 0) + (ii!=width - 1 ? board[i][ii+1]==-1 : 0) + (i!=0 && ii!=width - 1 ?board[i-1][ii+1]==-1 : 0);}}};let tbombs = (`00` + bombs.toString()).split(``);document.getElementById(`#_ID-flags-3`).src =`src/sprites/dig-${tbombs[tbombs.length -1]}.png`;document.getElementById(`#_ID-flags-2`).src =`src/sprites/dig-${tbombs[tbombs.length -2]}.png`;document.getElementById(`#_ID-flags-1`).src =`src/sprites/dig-${tbombs[tbombs.length -3]}.png`;for(let l in board){for(let ll in board[l]){cont.innerHTML+='0){ for(let i = x-1; i>=0; i--){if(document.getElementById(`#_ID-board-${y}-${i}`).src.includes(`src/sprites/space-uncl.png`)==false){break};document.getElementById(`#_ID-board-${y}-${i}`).src=`src/sprites/space-${board[y][i]}.png`;if(board[y][i]!=0){break};rev(i,y); }; };; if(y>0){ for(let i = y-1; i>=0; i--){if(document.getElementById(`#_ID-board-${i}-${x}`).src.includes(`src/sprites/space-uncl.png`)==false){break};document.getElementById(`#_ID-board-${i}-${x}`).src=`src/sprites/space-${board[i][x]}.png`;if(board[i][x]!=0){break};rev(x,i); }; }; ;;; if(x{document.getElementById(`#_ID-face`).src = `src/sprites/smiley.png`;},700);window.board#_ID_listeners.push(t_ss); document.getElementById(this.id).src=`src/sprites/space-'+board[l][ll]+'.png`;};for(let b in board){for(let bb in board[b]){if(board[b][bb]!=-1&&(document.getElementById(`#_ID-board-${b}-${bb}`).src.includes(`space-uncl`)||document.getElementById(`#_ID-board-${b}-${bb}`).src.includes(`space-flag`))){console.log(b,bb,board[b][bb]);return false};}};for(let iii of window.board#_ID_listeners){clearInterval(iii);clearTimeout(iii)};window.board#_ID_listeners = []; document.getElementById(`#_ID-face`).src = `src/sprites/cool.png`;for(let z in board){for(let zz in board[z]){document.getElementById(`#_ID-board-${z}-${zz}`).onclick = null;document.getElementById(`#_ID-board-${z}-${zz}`).oncontextmenu = null;window.pause_#_ID = true;};}\\' oncontextmenu=\\'let b3 = document.getElementById(`#_ID-flags-3`).src; b3 = b3.split(`-`)[b3.split(`-`).length-1].split(`.`)[0];let b2 = document.getElementById(`#_ID-flags-2`).src; b2 = b2.split(`-`)[b2.split(`-`).length-1].split(`.`)[0];let b1 = document.getElementById(`#_ID-flags-1`).src; b1 = b1.split(`-`)[b1.split(`-`).length-1].split(`.`)[0];let bombs = parseInt(b1+b2+b3);if(this.src.includes(`space-flag.png`)){this.src=`src/sprites/space-uncl.png`;bombs++;}else{if(bombs>0){this.src=`src/sprites/space-flag.png`;bombs--;}};let tbombs = (`00` + bombs.toString().replace(/-/g,`0`)).split(``);document.getElementById(`#_ID-flags-3`).src =`src/sprites/dig-${tbombs[tbombs.length -1]}.png`;document.getElementById(`#_ID-flags-2`).src =`src/sprites/dig-${tbombs[tbombs.length -2]}.png`;document.getElementById(`#_ID-flags-1`).src =`src/sprites/dig-${tbombs[tbombs.length -3]}.png`;;return false;\\' src=\\'src/sprites/space-uncl.png\\'>'}}; document.getElementById(`#_ID-face`).onclick = () => {lo#_ID_board();for(let zz of window.board#_ID_listeners){clearTimeout(zz);clearInterval(zz);};window.board#_ID_listeners = [];}}lo#_ID_board();setInterval(function ughugh(){if(!window.pause_#_ID){try{window.time_#_ID+=1;let ttime = (`00` + window.time_#_ID.toString()).split(``);document.getElementById(`#_ID-time-3`).src =`src/sprites/dig-${ttime[ttime.length -1]}.png`;document.getElementById(`#_ID-time-2`).src =`src/sprites/dig-${ttime[ttime.length -2]}.png`;document.getElementById(`#_ID-time-1`).src =`src/sprites/dig-${ttime[ttime.length -3]}.png`}catch(e){}}},1000);" diff --git a/src/jssh.js b/src/jssh.js index 3a49b08..efbb78e 100644 --- a/src/jssh.js +++ b/src/jssh.js @@ -214,6 +214,18 @@ class jssh { break; } } + return id; + } + get_file(path) { + let zz = path.split("/"); + let ff = zz.splice(zz.length - 1, 1); + let ww = this.set_wd(zz.join("/")); + for (let f of ww) { + if (f.name == ff) { + //console.log(f); + return f; + } + } } ex(stdin = null) { let temp_working_dir = this.working_dir; diff --git a/src/window-utils.js b/src/window-utils.js index 7cdbd7c..2755878 100644 --- a/src/window-utils.js +++ b/src/window-utils.js @@ -1,9 +1,152 @@ let util = { - alert(inp){ - - window_create(document.getElementsByClassName("window").length, - (inp.title == undefined ? "Alert" : inp.title), - " "+ (inp.content == undefined ? "Alert" : inp.content), - {width:220,height:110,resize:false}) - } -} \ No newline at end of file + async alert(inp) { + let promise = new Promise(async (res, rej) => { + bu = []; + if (inp.buttons == undefined) { + bu = ["ok", "no"]; + } else { + bu = inp.buttons; + } + let buttons = ""; + let i = document.getElementsByClassName("window").length; + for (let b of bu) { + buttons += + ""; + } + + await window_create( + i, + inp.title == undefined ? "Alert" : inp.title, + ` + + + +
${ + inp.content == undefined ? "Alert" : inp.content + }${buttons}
`, + { width: 220, height: 110, resize: false } + ); + for (let b of bu) { + document.getElementById(i + "-content-button-" + b).onclick = () => { + res(b); + }; + } + }); + return promise; + }, + async fd(inp) { + let promise = new Promise(async (res, rej) => { + let i = document.getElementsByClassName("window").length; + let sel = []; + await window_create(i, "fs", ""); + function load() { + let ll = new jssh(fs, "/", i, "null", "null", window_create); + let tfs = ll.set_wd(ll.clean_path(inp.path)); + let files = ""; + for (let f of tfs) { + if (f.dir) { + files += + "
" + + f.name + + "
"; + } else { + files += + "
" + + f.name + + "
"; + } + } + files += + "
file/directory name:
" + + sel.join(",") + + (sel.length == 0 ? "select a file!" : "") + + "
" + + "" + + "
"; + document.getElementById(i + "-content-content").innerHTML = files; + for (let f of tfs) { + let tt = document.getElementById(i + "-id-name-" + f.name); + let dou = false; + tt.onclick = (ev) => { + if (dou) { + console.log(f, inp); + if (f.dir) { + inp.path += f.name; + } else { + if (f.name.includes(".exe")) + ll.ex_file(inp.path + "/" + f.name); + else { + if (inp.open_file == true || inp.open_file == undefined) { + let iii = ll.ex_file("/apps/notepad.exe"); + document.getElementById( + iii + "-content-content" + ).firstChild.value = ll.get_file( + inp.path + "/" + f.name + ).content; + } else { + return inp.path + "/" + f.name; + } + //console.log(); + } + } + load(); + dou = false; + } else { + dou = true; + + tt.style.backgroundColor = "blue"; + setTimeout(() => { + if (dou) { + if (ev.ctrlKey) { + if (sel.includes(f.name)) { + sel.splice(sel.indexOf(f.name), 1); + } else sel.push(f.name); + } else sel = [f.name]; + //sel = [f.name]; + document.getElementById(i + "-fd-bottom-sel").innerHTML = + sel.join(",") + (sel.length == 0 ? "select a file!" : ""); + for (let aa of tfs) { + let ttt = document.getElementById( + i + "-id-name-" + aa.name + ); + if (sel.includes(aa.name)) { + ttt.style.backgroundColor = "blue"; + } else { + ttt.style.backgroundColor = ""; + } + } + //load(); + dou = false; + } + }, 200); + } + }; + } + } + load(); + }); + return promise; + }, +}; -- cgit v1.2.3