Created
January 17, 2019 15:40
-
-
Save Anachron/beeb4473a0b72bd61e1fe5219aa6a602 to your computer and use it in GitHub Desktop.
Script to generate Firefox-Color themes on the fly using base0x
This file contains 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
#!/usr/bin/env sh | |
# https://github.com/mozilla/FirefoxColor/blob/2b5cdf55754eaebcf29b367100964372b80d0a45/src/preset-themes/default.json | |
# https://github.com/mozilla/FirefoxColor/blob/2b5cdf55754eaebcf29b367100964372b80d0a45/src/web/index.js#L43-L51 | |
# https://github.com/masotime/json-url/blob/master/src/main/index.js#L11-L23 | |
# https://github.com/RGBboy/urlsafe-base64/blob/master/lib/urlsafe-base64.js#L31-L61 | |
ffc_c() { | |
msgpack-cli encode | lzma -c | base64 | sed 's|+|-|g; s|/|_|g' | |
} | |
ffc_d() { | |
sed 's|-|+|g; s|_|/|g' | base64 -d | lzcat | msgpack-cli decode | |
} | |
hex2rgb(){ | |
h=$(echo "${1}" | tr -d '#' | tr '[:lower:]' '[:upper:]') | |
r=$(printf '%s' "${h}" | cut -c 1-2) | |
g=$(printf '%s' "${h}" | cut -c 3-4) | |
b=$(printf '%s' "${h}" | cut -c 5-6) | |
printf '{"r":%d,"g":%d,"b":%d}' "0x${r}" "0x${g}" "0x${b}" | |
} | |
ffc_g() { | |
#test -f "${1}" && thm=$(cat "${1}") || thm=$(cat) | |
tb=$(hex2rgb "${base01}") # toolbar | |
tbt=$(hex2rgb "${base07}"); | |
ac=$(hex2rgb "${base03}") # background | |
tc=$(hex2rgb "${base07}"); tbf=$(hex2rgb "${base05}") | |
tbft=$(hex2rgb "${base02}"); tl=$(hex2rgb "${base02}") | |
pop=$(hex2rgb "${base02}"); popt=$(hex2rgb "${base07}") | |
cat << EOL | |
{"title:": "default", "colors": { | |
"toolbar": ${tb}, "toolbar_text": ${tbt}, | |
"accentcolor": ${ac}, "textcolor": ${tc}, | |
"toolbar_field": ${tbf}, "toolbar_field_text": ${tbft}, | |
"tab_line": ${tl}, "popup": ${pop}, "popup_text": ${popt} | |
}, "images": {}} | |
EOL | |
} | |
ffc_o() { | |
test -f "${1}" && thm=$(cat "${1}") || thm=$(cat) | |
cmp=$(printf '%s' "${thm}" | ffc_c) | |
xdg-open "https://color.firefox.com/?theme=${cmp}" | |
} | |
test "$#" -gt 0 || exit 1 | |
act="${1}"; shift | |
case "${act}" in | |
c*) ffc_c ${@};; | |
d*) ffc_d ${@};; | |
g*) ffc_g ${@};; | |
o*) ffc_o ${@};; | |
esac | |
# base64-encode | |
# return buffer.toString('base64') | |
# .replace(/\+/g, '-') // Convert '+' to '-' | |
# .replace(/\//g, '_') // Convert '/' to '_' | |
# .replace(/=+$/, ''); // Remove ending '=' | |
# base64-decode | |
# base64 += Array(5 - base64.length % 4).join('='); | |
# base64 = base64 | |
# .replace(/\-/g, '+') // Convert '-' to '+' | |
# .replace(/\_/g, '/'); // Convert '_' to '/' | |
#compress(json) { | |
# const packed = pack ? (await LOADERS.msgpack()).encode(json) : JSON.stringify(json); | |
# const compressed = await ALGORITHMS[algorithm].compress(packed); | |
# const encoded = encode ? (await LOADERS.safe64()).encode(compressed) : compressed; | |
# return encoded; | |
#} | |
#decompress(string) { | |
# const decoded = encode ? (await LOADERS.safe64()).decode(string) : string; | |
# const decompressed = await ALGORITHMS[algorithm].decompress(decoded); | |
# const unpacked = pack ? (await LOADERS.msgpack()).decode(decompressed) : JSON.parse(decompressed); | |
# return unpacked; | |
#} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment