added mime type-changing extension type

This commit is contained in:
Emma Tebibyte 2022-09-03 04:36:09 -04:00
parent 371d471349
commit 51b4ee860c
3 changed files with 41 additions and 10 deletions

View File

@ -4,26 +4,37 @@ echo "Loading extensions..."
INPUT=$(echo $1) INPUT=$(echo $1)
for EXT in /etc/xdg-sanity/extensions/*.sh for EXT in etc/xdg-sanity/extensions/*.sh
do do
echo "Found extension $EXT"
TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n') TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
echo "Modifying $INPUT..." echo "Found $TYPE extension $EXT"
if [ "$TYPE" = "pre" ]
if [ "$TYPE" = "replace" ]
then then
MOD=$($EXT "$INPUT") INPUT=$($EXT "$INPUT")
INPUT=$(echo $MOD) echo "Modifying $INPUT..."
fi
echo "Got $INPUT" echo "Got $INPUT"
fi
if [ "$TYPE" = "mime" ]
then
MIME=$($EXT "$INPUT")
echo $MIME
fi
done done
echo "Determining MIME type of $INPUT:" 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') MIME=$(curl -I -s "$INPUT" | sed -ne 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//g' | tr -d '\r')
fi
echo $MIME 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" ] if [ "$MIME" = "text/html" ]
then then

View File

@ -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

View File

@ -1,5 +1,13 @@
#!/bin/sh #!/bin/sh
# EXT-TYPE=pre # EXT-TYPE=replace
echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p' 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