- 5.4.3Latest
- 5.4.2
- 5.4.1
- 5.4
- 5.3.9
- 5.3.8
- 5.3.7
- 5.3.6
- 5.3.5
- 5.3.4
- 5.3.3
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.9
- 5.2.8
- 5.2.7
- 5.2.6
- 2.5.6
- 5.2.5
- 5.2.4
- 5.2.3
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.9-9
- 5.1.99
- 5.1.98
- 5.1.97
- 5.1.96
- 5.1.95
- 5.1.94
- 5.1.93
- 5.1.92
- 5.1.91
- 5.1.90
- 5.1.87
- 5.1.86
- 5.1.85
- 5.1.84
- 5.1.83
- 5.1.82
- 5.1.81
- 5.1.8
- 5.1.7
- 5.1.6
- 5.1.5
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.9
- 5.0.8
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.1.6
- 4.1.5
- 4.1.4
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0
- 3.9
- 3.8
- 3.7
- 3.6
- 3.5
- 3.4
- 3.3
- 3.2
- 3.1
- 3.0
- 2.9
- 2.8
- 2.7
- 2.6
- 2.5
- 2.4
- 2.3
- 2.2
- 1.5
- 1.4
- 1.3
- 1.2
- 1.1
- 0.9
- 1.0
- 0.8
- 0.7
- 0.6
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1

Handy Helpers
this is a collection of useful functions
f_b_deno
check if script is running with https://deno.com/
f_assert_equals(f_b_denojs(), ("Deno" in window))f_o_html_element__from_s_tag
returns a html element browser: document.createElement denojs: using /x/deno_dom
f_assert_equals((await f_o_html_element__from_s_tag('h1')).tagName, 'H1');f_o_html__from_s_html
returns a html element browser: div.innerHTML = s_html denojs: using /x/deno_dom
f_assert_equals(
(await f_o_html__from_s_html('<div><h1>hello</h1><h1>world</h1></div>')).querySelectorAll('h1')[1].innerText,
'world'
);f_download_file__from_s_url
download a file, pass an optional callback, or let log the download state by default
await f_download_file__from_s_url(
// 'https://www.dwsamplefiles.com/?dl_id=409'
// 'https://images.unsplash.com/photo-1533144188434-eb0442504392?auto=format&fit=crop&q=80&w=3948&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
// 'a_picture_in_bird_perspective.png'
'https://www.w3schools.com/html/pic_trulli.jpg',
'./lol/test.jpg'//if denojs we can pass a path
)
f_a_n_u8__from_s_url_with_download_speed_easy
get the response body as Uint8array (a_n_u8) from an url, while the download is pending a callback will be executed every nth millisecond in this callback one can print download speed, if the response header ‘content-length’ is present and its value is legit one can also print the download percentage
let a_n_u8 = await f_a_n_u8__from_s_url_with_download_speed_easy(
'https://www.dwsamplefiles.com/?dl_id=409',
function(
n_mb_downloaded,
n_mb_per_sec_domwnload_speed,
n_mb_to_download_total
){
let s_from_total = ''
if(n_mb_to_download_total != -1){
s_from_total = (`/${(n_mb_to_download_total).toFixed(0)}`)
}
console.log(`downloaded ${(n_mb_downloaded).toFixed(0)}${s_from_total}(MB) @ ${n_mb_per_sec_domwnload_speed.toFixed(2)} MB/s`)
},
555// callback gets called every 555 milliseconds
)
f_assert_equals(a_n_u8.length, 80118331)
f_monkey_patch_fetch__easy
replace the original fetch function, with a custom fetch function, for example to change
var o_data = await (await fetch('https://httpbin.org/headers')).json();
f_assert_equals(
o_data.headers['User-Agent'].includes('Deno/'),
true
)
f_monkey_patch_fetch__easy(
function(o_options_passed_to_fetch){
// this function must return an object,
// the second options object wich is used in the fetc function (fetch(url, options))
// will get assigned this object, so headers could be overwritten for example
return {
headers: {
'User-Agent': [
`Gozilla/${(Math.random()*5+1).toFixed(1)}`,
`(Dingos TN 2.1; Din64; x128; rv:27.0)`,
`Lizzard/20100101 Waterwhale/42.0`
].join(' ')
}
}
}
);
// test the custom function
var o_data = await (await fetch('https://httpbin.org/headers')).json();
f_assert_equals(
o_data.headers['User-Agent'].includes('Gozilla/'),
true
)
// restore the default fetch function
f_monkey_patch_fetch(
null,
true// restore original fetch
)
// test the restored function
var o_data = await (await fetch('https://httpbin.org/headers')).json();
f_assert_equals(
o_data.headers['User-Agent'].includes('Deno/'),
true
)
f_promise_all_numloop_with_callback
a handy function to iterate over things and download stuff for example
let a_o_result = await f_promise_all_numloop_with_callback(
3,
4,
async function(n_num){
let s_url_base = `https://www.tutti.ch`
let o_doc = await f_o_html__from_s_url(
`https://www.tutti.ch/de/q/suche/Ak6dnaXRhcnJlwJTAwMDA?sorting=newest&page=${n_num}&query=gitarre`
);
// console.log(Array.from(o_doc.querySelectorAll('[data-testid="link-to-image"]')))
let a_s_url = Array.from(o_doc.querySelectorAll('[data-testid="link-to-image"]'))
.map(o=>`${s_url_base}${o.getAttribute('href')}`)
a_s_url = [a_s_url[0]]
return Promise.all(
a_s_url.map(async s=>{
let o_doc2 = await f_o_html__from_s_url(s);
await f_download_file__from_s_url(o_doc2.querySelector('img').getAttribute('src'))
return true
})
)
}
)
return true