Skip to content

Instantly share code, notes, and snippets.

@jonasfrey
Created October 26, 2023 12:49
Show Gist options
  • Save jonasfrey/f529529052fd67059dd4d2c06d83cb80 to your computer and use it in GitHub Desktop.
Save jonasfrey/f529529052fd67059dd4d2c06d83cb80 to your computer and use it in GitHub Desktop.
recursive load webserver serving direcories
let f_a_o_from_o_doc = function(o_doc){
let a_o = Array.from(o_doc.querySelectorAll('a')).filter(v=>v.innerText.includes('/'))
return a_o
}
let f_recursive_show_direcotries = async function(
o_doc,
n_it_max_recursion = 1,
n_it_recursion = 0,
s_url=window.location.href
){
if(n_it_recursion > n_it_max_recursion){
console.log(`max level of recursion reached ${n_it_max_recursion}`)
return false
}
let a_o = f_a_o_from_o_doc(o_doc);
for(let o of a_o){
let s_path = o.getAttribute("href")
let s_url2 = s_url+s_path;
let o_doc2 = new DOMParser().parseFromString((await(await fetch(s_url2)).text()), 'text/html');
let o_doc2_clone = new DOMParser().parseFromString((await(await fetch(s_url2)).text()), 'text/html');
let o_table_clone = o_doc2_clone.querySelector("table")
let o_div = document.createElement('div');
o_div.innerText = s_url;
o.parentElement.appendChild(o_div)
o.parentElement.appendChild(o_table_clone)
await f_recursive_show_direcotries(
o_table_clone,
n_it_max_recursion,
n_it_recursion+1,
s_url2
)
// console.log(o_doc.body)
}
return true
}
await f_recursive_show_direcotries(document,2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment