let util = { context_menu(opt){ /* opt = {"menu":[ {"name":string, "callback": function} ],!"settings":{ x:int, y:int, height:int, width:int }} ! is optional */ }, 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 = []; let sel_t_n = 0 let sel_t = fs_types[sel_t_n] l_b_width = 80 await window_create(i, "fs", ""); 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 = ""; files += "
" //left bar //console.log(inp.path) let ppp = inp.path.split("/").filter(function (e) { return e !== ""; }) function rec_bar_fun(cdir,target_full,target_ind,padding,patt){ let ret = "" for(let f of cdir){ if(f.dir){ //console.log(f.name,target_full,target_ind) let t_ret = '' let ttu = false if(f.name==target_full[target_ind]){ ttu = true t_ret += rec_bar_fun(f.content,target_full,target_ind+1,padding+5,patt+"/"+f.name) } ret += "
"+(ttu?"v ":"> ")+f.name+"
" + t_ret //console.log(false,f.name) } } return ret } let bar_opt = "
v /
" + (rec_bar_fun(fs,ppp,0,5,'')) /* for(let dd of ppp){ paa+=5 cur_pat.push(dd) console.log(cur_pat,dd) tt_ppp = "/" + cur_pat.join("/") console.log(dd) let ttwd = (ll.set_wd(tt_ppp)) for(let ff of ttwd){ if(ff.dir){ bar_opt+="
"+ff.name+"
" } } }*/ console.log(inp.path) files+= "
"+bar_opt+"
" files += "
" files += "
" for (let f of tfs) { if (f.dir) { files += "
" + f.name + "
"; fil.push(f) } else { if(RegExp(sel_t.regex,"g").test(f.name)){ files += "
" + f.name + "
"; fil.push(f) } } } files+="
" let opts = ""; for (let uwu of fs_types) { let aad = "" if(uwu==sel_t) aad = "selected" opts += ""; } files += "
File name:
" + "
" + "
File type:
" + "
" + ""; document.getElementById(i + "-content-content").innerHTML = files; //console.log(tfs) //util.scrollbar(document.getElementById(i+"-fs-inner-cont")) 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() } document.getElementById(i +"-content-button2-sub").onclick = () => { rej("canceled by user") document.getElementById(i+"-root").remove() } document.getElementById(i+"-left-pane-resize-e").onmousedown = (ev) => { let elep = document.getElementById(i+"-fs-left-bar") let px = ev.clientX document.body.style.cursor = "ew-resize" document.body.style.userSelect = "none" document.onmouseup = (() => { document.body.style.userSelect = "" document.onmousemove = null document.onmouseup = null document.body.style.cursor = '' }) document.onmousemove = (ev) => { elep.style.width = (parseInt(elep.clientWidth) + (ev.clientX - px)) + "px" px = (ev.clientX) } } let aaaa = document.getElementById(i+"-fs-left-bar").children //console.log(aaaa) for(let zz = 0; zz!=aaaa.length; zz++){ //console.log(zz) aaaa.item(zz).onclick = (()=>{ inp.path = aaaa.item(zz).id load() }) } for (let f of fil) { let tt = document.getElementById(i + "-id-name-" + f.name); //console.log(tt,f) 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 { //console.log(inp.path,'/',f.name) inp.path = inp.path + f.name + "/"; return } //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").value = sel.join(",") + (sel.length == 0 ? "Untitled" : ""); 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); } }; } document.getElementById(i +"-fd-bottom2-sel").onchange = (ev) => { sel_t = fs_types[ev.target.selectedIndex] load() }; } load(); }); return promise; }, };