#!/bin/sh # this is a wget stub which directly interfaces with the browsers javascript fetch() # REASON: way less overhead / complexity compared to the v86 linux networking stack url="$1" filename="$(basename "$url")" tmp=/mnt/$$ test -z "$1" && { echo "usage: $0 [-o outfile]"; exit 0; } for arg in $*; do test $arg = "-o" && shift && filename=$* shift done echo "$url" | grep -qE '^http' && test -f ~/.config/wget/corsproxy && { proxy="$(cat ~/.config/wget/corsproxy)" url="${proxy}${url}" echo "[i] using CORS proxy: $url" 1>&2 } js '$("[isoterminal]").emit("create_file_from_url",["'$tmp'","'$url'"])' while sleep 0.5s; do printf "." 1>&2 test -f $tmp && { test "$(awk '{ print $1 }' $tmp)" = 0 && retcode=1 || retcode=0 mv $tmp "$filename" && printf "\n" && exit $retcode } done