diff options
author | amy <[email protected]> | 2023-02-23 19:41:22 +0000 |
---|---|---|
committer | amy <[email protected]> | 2023-02-23 19:41:22 +0000 |
commit | 43157ec7ea571ac2836fcb44cc39088ca179330a (patch) | |
tree | 5f2c2495d4b677e59734a53b183317bb095758ef | |
parent | 279ed3d59493d2192df2fd7c797a494c8d713a53 (diff) |
uwu
-rw-r--r-- | html/display.html | 27 | ||||
-rw-r--r-- | src/common.js | 27 | ||||
-rw-r--r-- | src/fs.json | 1 | ||||
-rw-r--r-- | src/jssh.js | 7 | ||||
-rw-r--r-- | src/window-utils.js | 83 |
5 files changed, 102 insertions, 43 deletions
diff --git a/html/display.html b/html/display.html index 08d8fdb..bab394e 100644 --- a/html/display.html +++ b/html/display.html @@ -174,8 +174,9 @@ } let minx = 150; let miny = 150; + function window_create(uid, name, content, options = {}) { - let promise = new Promise((res, rej) => { + //let promise = new Promise((res, rej) => { let lines = content.split("</br>").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;"); @@ -206,7 +207,10 @@ a += "<div id='" + uid + "-resize-sw' class='resize-sw'></div>" a += "<div id='" + uid + "-resize-es' class='resize-es'></div>" } - document.getElementById("root").innerHTML += a + a += "</div>" + console.log(a) + //document.getElementById("root").append(a) + appendHtml(document.getElementById("root"),a) if (options.scroll != false && options.scroll != "false") { //a += "<div id='" + uid + "-content-scrollbar' class='scrollbar'><div id='" + uid + "-content-scrollbar-point' class='scrollbar-point'></div>" //a += "</div>" @@ -216,15 +220,18 @@ //console.log(document.getElementById(uid + "-content-scrollbar-point")) refresh_windows() - res() - }) - return promise + //res() + //}) + //return promise } function refresh_windows() { load_bar() - let elems = document.getElementsByClassName("window") + //let elems = document.getElementsByClassName("window") + let elems = document.getElementById("root").children for (let i = 0; i != elems.length; i++) { + if(elems.item(i).className!='window') + continue let uid = elems.item(i).id.split("-")[0] if(null!=procs[uid] && null!=procs[uid].refresh) procs[uid].refresh() @@ -243,6 +250,7 @@ } } } catch (e) { } + //continue //let elem = elems.item(i).children[0] let elec = elems.item(i).children let elem @@ -257,6 +265,8 @@ elem.children.item(iii).onmousedown = ((ev) => { //console.log(elems.item(i)) //onkill.apply(this) + if(null!=procs[uid] && null!=procs[uid].remove) + procs[uid].remove() delete procs[elem.id.split("-")[0]] ii.remove() load_bar() @@ -564,7 +574,7 @@ load_bar() } - + let fs_types; async function main() { fs = await req('src/fs.json') @@ -579,6 +589,7 @@ }) load_bar() } + </script> </head> @@ -655,7 +666,7 @@ src="./src/img/log-off.png"> <div class="bar-menu-text">Log Off...</div> </div> - <div class="bar-menu-item" id="bar-menu-run"><img class="bar-menu-image" style="height:24px" + <div class="bar-menu-item" id="bar-menu-run" ><img class="bar-menu-image" style="height:24px" src="./src/img/shut-down.png"> <div class="bar-menu-text">Shut Down...</div> </div> diff --git a/src/common.js b/src/common.js index 5606706..a3309d9 100644 --- a/src/common.js +++ b/src/common.js @@ -1,22 +1,11 @@ -Object.prototype.clone = Array.prototype.clone = function() //https://stackoverflow.com/questions/12690107/clone-object-without-reference-javascript -{ - if (Object.prototype.toString.call(this) === '[object Array]') - { - var clone = []; - for (var i=0; i<this.length; i++) - clone[i] = this[i].clone(); - return clone; - } - else if (typeof(this)=="object") - { - var clone = {}; - for (var prop in this) - if (this.hasOwnProperty(prop)) - clone[prop] = this[prop].clone(); - return clone; - } - else - return this; +//https://stackoverflow.com/questions/10309650/add-elements-to-the-dom-given-plain-text-html-using-only-pure-javascript-no-jqu +//lets me add elements without fucking up listeners +function appendHtml(el, str) { + var div = document.createElement('div'); + div.innerHTML = str; + while (div.children.length > 0) { + el.appendChild(div.children[0]); + } }
\ No newline at end of file diff --git a/src/fs.json b/src/fs.json index fc6a364..193819c 100644 --- a/src/fs.json +++ b/src/fs.json @@ -40,6 +40,7 @@ "dir": false, "content": "window Notepad <textarea onkeypress='auto_resize(this)' style='width:100%;overflow:visible;display:block;'></textarea>\nmeta icon src/img/notepad.png" }, + { "name": "cmd.exe", "perms": { "r": true }, diff --git a/src/jssh.js b/src/jssh.js index efbb78e..1da1f83 100644 --- a/src/jssh.js +++ b/src/jssh.js @@ -99,8 +99,8 @@ class jssh { return this.add_file(fs, path, dir); } } - document.getElementById(this.history).innerHTML += - "jssh: " + path.join("/") + ": directory not found</br>"; + this.stdout( + "jssh: " + path.join("/") + ": directory not found</br>"); } write_file(fs, path, content, append) { if (path.length == 1) { @@ -180,7 +180,8 @@ class jssh { } } } - console.log(settings); + //console.log(settings); + //console.log(id,stripped[1],t.join(" ").replace(/#_ID/g, id)) //let id = document.getElementsByClassName("window").length; //console.log(id); this.window_create( diff --git a/src/window-utils.js b/src/window-utils.js index 149b9d0..2fdf1bb 100644 --- a/src/window-utils.js +++ b/src/window-utils.js @@ -1,10 +1,10 @@ let util = { - context_menu(opt){ + context_menu(target,opt){ /* opt = {"menu":[ {"name":string, "callback": function} - + , ... ],!"settings":{ x:int, y:int, @@ -14,15 +14,38 @@ let util = { ! is optional */ + (()=>{ + target.oncontextmenu = ((ev)=>{ + console.log(ev) + try{document.getElementById(target.id+"-menu").remove()}catch(e){} + let aa = "" + + for(let op of opt.menu){ + aa+=`<div id='${target.id}-menu-${opt.menu.indexOf(op)}'>${op.name}</div>` + } + target.innerHTML += "<div id='"+target.id+"-menu' style='position:fixed;top:"+ev.clientY+";left:"+ev.clientX+"px;background-color:red'>"+aa+"</div>" + for(let op of opt.menu){ + document.getElementById(`${target.id}-menu-${opt.menu.indexOf(op)}`).onclick = (()=>{ + op.callback() + }) + } + return false + }) + })() }, scrollbar(uid,minor_uid,root,target){ + (()=>{ + //root is the base of the window, only used for measuring //-- //target is where the scrollbar will be placed, this element should be //larger than the root with scrollable overflow let scrolling = false + console.log(uid,minor_uid) + //try{document.getElementById(uid + "-" + minor_uid + "-content-scrollbar").remove()}catch(e){console.log(e)} if(undefined==procs[uid]) procs[uid] = {} + console.log("'" + uid + "-" + minor_uid + "-content-scrollbar'") target.innerHTML += "<div id='" + uid + "-" + minor_uid + "-content-scrollbar' class='scrollbar'><div id='" + uid + "-" + minor_uid + "-content-scrollbar-point' class='scrollbar-point'></div></div>" let thi_point = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar-point") let thi_base = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar") @@ -41,7 +64,7 @@ let util = { thi_point.style.top = thi_base.clientHeight-thi_point.clientHeight } } - console.log(root) + //console.log(root) root.onscroll = () => { if (false==scrolling) { @@ -57,6 +80,7 @@ let util = { thi_point.style.cursor = 'grabbing' py = ev.clientY document.body.style.userSelect = "none" + document.onmouseup = (()=>{ document.body.style.cursor = '' thi_point.style.cursor = 'grab' @@ -67,7 +91,7 @@ let util = { document.onmousemove = ((evm)=>{ scrolling = true let z = (thi_point.offsetTop - (py - evm.clientY)) - console.log(z,thi_base.clientHeight - thi_point.clientHeight) + //console.log(z,thi_base.clientHeight - thi_point.clientHeight) if(z >= 0 && z < thi_base.clientHeight - thi_point.clientHeight){ thi_point.style.top = z root.scrollTop = ((z / (thi_base.clientHeight - thi_point.clientHeight)) * (root.scrollHeight - thi_base.clientHeight + 24)) @@ -83,6 +107,7 @@ let util = { }) }) procs[uid].refresh() + })() }, async alert(inp) { let promise = new Promise(async (res, rej) => { @@ -104,8 +129,9 @@ let util = { b + "</button>"; } - - await window_create( + let r_x = inp.x | 25 + let r_y = inp.y | 25 + window_create( i, inp.title == undefined ? "Alert" : inp.title, `<table><tr><td style='padding: 5px;'><img src='./src/img/${ @@ -117,7 +143,7 @@ let util = { }</td> <td style='padding: 5px;' >${buttons}</td> </tr></table>`, - { width: 220, height: 110, resize: false } + { width: 220, height: 110, resize: false,left:r_x,top:r_y } ); for (let b of bu) { document.getElementById(i + "-content-button-" + b).onclick = () => { @@ -128,17 +154,20 @@ let util = { return promise; }, async fd(inp) { + let i = document.getElementsByClassName("window").length; let promise = new Promise(async (res, rej) => { - let i = document.getElementsByClassName("window").length; + if(undefined==procs[i]) + procs[i] = {} let sel = []; let sel_t_n = 0 let sel_t = fs_types[sel_t_n] l_b_width = 80 - await window_create(i, "fs", "",{scroll:false}); + window_create(i, "fs", "",{scroll:false}); + let ll = await new jssh(fs, "/", i, "null", "null", window_create); async function load() { let fil = [] - let ll = await new jssh(fs, "/", i, "null", "null", window_create); + let tfs = ll.set_wd(ll.clean_path(inp.path)); //console.log(sel_t) let files = ""; @@ -252,12 +281,19 @@ let util = { document.getElementById(i + "-content-content").innerHTML = files; //console.log(tfs) //util.scrollbar(document.getElementById(i+"-fs-inner-cont")) + procs[i].load_listeners = () => { + + let ele = document.getElementById(i+"-fs-inner-cont") let ele_root = document.getElementById(i+"-content-content") util.scrollbar(i,'root-bar',ele_root.parentElement,ele) - document.getElementById(i+"-fs-inner-cont").oncontextmenu = (ev) => { - return false - } + util.context_menu(ele,{menu:[ + {name:'new file',callback:()=>{console.log("copy")}}, + {name:'new directory',callback:()=>{ll.add_file(ll.fs,['untitled'],true);load()}}, + ]}) + //document.getElementById(i+"-fs-inner-cont").oncontextmenu = (ev) => { + // return false + //} document.getElementById(i +"-content-button-sub").onclick = () => { res(inp.path+document.getElementById(i +"-fd-bottom-sel").value) document.getElementById(i+"-root").remove() @@ -335,6 +371,23 @@ let util = { if (sel.includes(f.name)) { sel.splice(sel.indexOf(f.name), 1); } else sel.push(f.name); + } else if (ev.shiftKey) { + let tem = false + for (let ff of fil) { + //console.log(ff.name,sel[0]) + if(ff==f||ff.name==sel[0]){ + //console.log("uwu") + if(tem){ + sel.push(ff.name) + break + } + else + tem = true + } + if(tem){ + sel.push(ff.name) + } + } } else sel = [f.name]; //sel = [f.name]; document.getElementById(i + "-fd-bottom-sel").value = @@ -361,7 +414,11 @@ let util = { load() }; } + procs[i].load_listeners() + } + load(); + }); return promise; }, |