#!/bin/bash if [[ ! $(find ./js/betterfox.js -cmin -10080 -print 2>/dev/null) ]]; then if curl 'https://raw.githubusercontent.com/yokoffing/Betterfox/main/user.js' > 'betterfox.js.part'; then printf 'successfully downloaded latest betterfox user.js\n' mv betterfox.js.part ./js/betterfox.js else printf 'failed to download latest betterfox user.js\n' rm betterfox.js.part # exit 1 fi fi rgba_to_hex(){ r="${1}" g="${2}" b="${3}" a="${4}" aa=$(echo "${a}*255"|bc) printf '#%x%x%x%x\n' "${r}" "${g}" "${b}" "${aa%.*}" } #rgba_to_hex 100 150 200 0.5 jq_parse(){ json_file="${1}" jq_query="${2}" jq -r "${2}" "${1}" } #jq_parse ./profiles/penelope/vars.json '.color.r' #exit 1 gen_hex(){ json="${1}" colorvar="${2}" r=$(jq_parse "${json}" ".${colorvar}.r") g=$(jq_parse "${json}" ".${colorvar}.g") b=$(jq_parse "${json}" ".${colorvar}.b") a=$(jq_parse "${json}" ".${colorvar}.a") rgba_to_hex "${r}" "${g}" "${b}" "${a}" } for profile in ./profiles/*/;do profile="${profile%/}" profile_name=$(basename "${profile}") mkdir -p "../${profile_name}" browser_profile_dir=$(realpath "../${profile_name}") mkdir -p "${browser_profile_dir}" if [[ -L "${browser_profile_dir}/chrome" ]];then rm "${browser_profile_dir}/chrome" fi if [[ -f "${profile}/vars.json" ]];then mkdir -p "${browser_profile_dir}/chrome" json="${profile}/vars.json" # bg_r=$(jq_parse "${json}" '.background_color.r') # bg_g=$(jq_parse "${json}" '.background_color.g') # bg_b=$(jq_parse "${json}" '.background_color.b') # bg_a=$(jq_parse "${json}" '.background_color.a') # css_bg_rgba=$(printf 'rgba(%s,%s,%s,%s)' "${bg_r}" "${bg_g}" "${bg_b}" "${bg_a}") # css_bg_hex=$(rgba_to_hex "${bg_r}" "${bg_g}" "${bg_b}" "${bg_a}") # p_r=$(jq_parse "${json}" '.color.r') # p_g=$(jq_parse "${json}" '.color.g') # p_b=$(jq_parse "${json}" '.color.b') # p_a=$(jq_parse "${json}" '.color.a') # css_bg_rgba=$(printf 'rgba(%s,%s,%s,%s)' "${p_r}" "${p_g}" "${p_b}" "${p_a}") # css_p_hex=$(rgba_to_hex "${p_r}" "${p_g}" "${p_b}" "${p_a}") css_bg_hex=$(gen_hex "${json}" 'background_color') # css_nav_hex=$(gen_hex "${json}" 'nav_color') css_p_hex=$(gen_hex "${json}" 'color') for c in ./chrome/*.css;do css_name=$(basename "${c}") sed "s/\[\[\[BACKGROUNDHEX\]\]\]/${css_bg_hex}/" "${c}" | tee "${browser_profile_dir}/chrome/${css_name}" done for pc in "${browser_profile_dir}/chrome/"*.css;do css_name=$(basename "${c}") sed -i "s/\[\[\[COLORHEX\]\]\]/${css_p_hex}/" "${pc}" done # sed "s/\[\[\[BACKGROUNDHEX\]\]\]/${css_bg_hex}/" ./chrome/userChrome.css | tee "${browser_profile_dir}/chrome/userChrome.css" # sed "s/\[\[\[BACKGROUNDHEX\]\]\]/${css_bg_hex}/" ./chrome/userChrome.css | tee "${browser_profile_dir}/chrome/userChrome.css" # echo "${css_bg_rgba}" # echo "${css_bg_hex}" fi # if [[ -L "${browser_profile_dir}/user.js" ]];then # rm "${browser_profile_dir}/user.js" # fi # if [[ -f "${profile}/user.js" ]];then # echo "joining js files" # cat "./js/betterfox.js" "./js/global.js" "${profile}/user.js" | tee "${browser_profile_dir}/user.js" > /dev/null # fi done