Created
August 10, 2015 06:09
-
-
Save mooyoul/11bbcbeaf27a33ec2ee2 to your computer and use it in GitHub Desktop.
Download all fonts described by @font-face directive in CSS stylesheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
COLOR_RESET="\033[30m" | |
COLOR_GREEN="\033[32m" | |
COLOR_RED="\033[31m" | |
COLOR_CYAN="\033[36m" | |
COLOR_WHITE="\033[37m" | |
sniffTarget=$1 | |
referer="--referer $2" | |
data="" | |
fonts="" | |
if [ $# -eq 0 ] || [ $# -gt 2 ] | |
then | |
echo -e "${COLOR_WHITE}Usage: font-doduk CSS_URL [CSS_REFERER]" | |
else | |
if [ -z ${referer+x} ] | |
then | |
referer="" | |
fi | |
data=$(curl $sniffTarget $referer 2>/dev/null ) | |
if [ $? -eq 0 ] | |
then | |
echo -e "${COLOR_GREEN}[SUCCESS]${COLOR_WHITE} Got Stylesheet!" | |
else | |
echo -e "${COLOR_RED}[ERROR]{COLOR_WHITE} Failed to fetch stylesheet from remote server. curl returned with exit code $?." | |
exit; | |
fi | |
fonts=$(echo $data | grep -oE "@font-face[^}]+}" | grep -oE "url\(['\"]?([^'\"#]+)['\"]?\)" | grep -oE "[^'\"]{5,}") | |
if [ $? -eq 0 ] | |
then | |
echo -e "${COLOR_GREEN}[SUCCESS]${COLOR_WHITE} Font url was parsed successfully!" | |
else | |
echo $data | |
echo -e "${COLOR_RED}[ERROR]${COLOR_WHITE} Failed to parse font url from fetched stylesheet." | |
exit; | |
fi | |
for font in $fonts | |
do | |
echo -e "${COLOR_CYAN}[INFO]${COLOR_WHITE} Downloading: $font" | |
wget --referer $sniffTarget $font | |
if [ $? -eq 0 ] | |
then | |
echo -e "${COLOR_GREEN}[SUCCESS]${COLOR_WHITE} Font downloaded successfully!" | |
else | |
echo "[ERROR] Font download failed..." | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment