From 02f787e2a6e347faa6349e1c82eaf29602befca0 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Mon, 30 Nov 2020 23:48:16 +0100 Subject: [PATCH] Working browser --- mbrow.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 mbrow.sh diff --git a/mbrow.sh b/mbrow.sh new file mode 100755 index 0000000..c4a3871 --- /dev/null +++ b/mbrow.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +url=$(echo ${1} | sed -e s'/^http:/https:/' -e'/^http/! s_\(.*\)_https://\1_') # https everywhere plugin +htmlfile="$(mktemp -u)" #Save the file here +wget -q "${url}" -O "${htmlfile}" # Get the file +function print_img { + tempfile="$(mktemp -u)" + wget -q "${1}" -O "${tempfile}" + ~/.cargo/bin/viu "${tempfile}" 2>/dev/null # cargo install viu + rm "${tempfile}" +} +function display_text { + OLDIFS=${IFS} + IFS=$'\n' + for line in $(cat "${htmlfile}" | \ + html2markdown --no-wrap-links --no-skip-internal-links) ; do # sudo apt install python3-html2text + echo "${line}" | egrep -q '!\[.*\]\(http.*\)' + if [[ "${?}" == "0" ]]; then + img=$(echo "${line}"|sed 's/.*!\[.*\](\(.*\)).*(.*/\1/g') + print_img "${img}" + else + echo "${line}" | egrep -q '\]\(/.*\)' + if [[ "${?}" == "0" ]]; then + echo "${line}" | sed 's_\](/_]('${url}'/_' + else + echo "${line}" + fi + fi + done + IFS="${OLDIFS}" +} +echo "$(display_text)" | less -R +rm "${htmlfile}"