From 51b4ee860c9e326e10a0371da7c490b6cb300984 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 3 Sep 2022 04:36:09 -0400 Subject: [PATCH] added mime type-changing extension type --- xdg-sanity.sh | 27 ++++++++++++++------ xdg-sanity/extensions/teddit-mime.sample | 12 +++++++++ xdg-sanity/extensions/youtube-replace.sample | 12 +++++++-- 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100755 xdg-sanity/extensions/teddit-mime.sample diff --git a/xdg-sanity.sh b/xdg-sanity.sh index 90d55f8..05c630f 100755 --- a/xdg-sanity.sh +++ b/xdg-sanity.sh @@ -4,26 +4,37 @@ echo "Loading extensions..." INPUT=$(echo $1) -for EXT in /etc/xdg-sanity/extensions/*.sh +for EXT in etc/xdg-sanity/extensions/*.sh do -echo "Found extension $EXT" + TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n') -echo "Modifying $INPUT..." -if [ "$TYPE" = "pre" ] +echo "Found $TYPE extension $EXT" + +if [ "$TYPE" = "replace" ] then -MOD=$($EXT "$INPUT") -INPUT=$(echo $MOD) -fi +INPUT=$($EXT "$INPUT") +echo "Modifying $INPUT..." echo "Got $INPUT" +fi + +if [ "$TYPE" = "mime" ] +then +MIME=$($EXT "$INPUT") +echo $MIME +fi + done echo "Determining MIME type of $INPUT:" +if [ "$MIME" = "$1" ] +then MIME=$(curl -I -s "$INPUT" | sed -ne 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//g' | tr -d '\r') +fi echo $MIME -BROWSER=$(cat /etc/xdg-sanity.conf | sed -ne 's/^browser = //p' ) +BROWSER=$(cat /etc/xdg-sanity/xdg-sanity.conf | sed -ne 's/^browser = //p' ) if [ "$MIME" = "text/html" ] then diff --git a/xdg-sanity/extensions/teddit-mime.sample b/xdg-sanity/extensions/teddit-mime.sample new file mode 100755 index 0000000..22e5171 --- /dev/null +++ b/xdg-sanity/extensions/teddit-mime.sample @@ -0,0 +1,12 @@ +#!/bin/sh + +# EXT-TYPE=mime + +TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -ne 's/\/.*\+//p') + +if [ $TEST = "teddit.net" ] +then +echo "text/html" +else +echo $1 +fi \ No newline at end of file diff --git a/xdg-sanity/extensions/youtube-replace.sample b/xdg-sanity/extensions/youtube-replace.sample index 96fe8da..70921be 100755 --- a/xdg-sanity/extensions/youtube-replace.sample +++ b/xdg-sanity/extensions/youtube-replace.sample @@ -1,5 +1,13 @@ #!/bin/sh -# EXT-TYPE=pre +# EXT-TYPE=replace -echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p' \ No newline at end of file +TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -ne 's/\/.*\+//p') + + +if [ $TEST = "youtube.com" ] +then +echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p' +else +echo $1 +fi