Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/autonome/airqualitytheme. Firefox theme that changes color based on your local air quality index -
Something went wrong. Try again.
airqualitytheme background.js
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109let state = { key: 'szBpztTSNpAoa8s7S'};
const themes = { 'good': { images: { headerURL: 'good.png' }, colors: { accentcolor: '#00e400', textcolor: '#111', } }, 'moderate': { images: { headerURL: 'moderate.png' }, colors: { accentcolor: '#ffff00', textcolor: '#111', } }, 'sensitive': { images: { headerURL: 'sensitive.png' }, colors: { accentcolor: '#ff7e00', textcolor: '#111', } }, 'unhealthy': { images: { headerURL: 'unhealthy.png' }, colors: { accentcolor: '#ff0000', textcolor: '#111', } }, 'veryunhealthy': { images: { headerURL: 'veryunhealthy.png' }, colors: { accentcolor: '#8f3f97', textcolor: '#111', } }, 'hazardous': { images: { headerURL: 'hazardous.png' }, colors: { accentcolor: '#7e0023', textcolor: '#fff', } }};
(async function() { getAQI(async function(aqi) { let name = await getAQILevelName(aqi); setTheme(name); });})();
async function getAQILevelName(aqi) { let name = ''; if (aqi < 51) name = 'good'; else if (aqi < 101) name = 'moderate'; else if (aqi < 151) name = 'sensitive'; else if (aqi < 201) name = 'unhealthy'; else if (aqi < 251) name = 'veryunhealthy'; else name = 'hazardous'; return name;}
async function getAQI(cb) { navigator.geolocation.getCurrentPosition(async function(position) { let getURL = 'http://api.airvisual.com/v2/nearest_city' + '?key=' + state.key + '&lat=' + position.coords.latitude + '&lon=' + position.coords.longitude; let resp = await fetch(getURL); let json = await resp.json(); let aqi = json.data.current.pollution.aqius; cb(aqi); });}
var currentTheme = '';
function setTheme(theme) { if (currentTheme === theme) { // No point in changing the theme if it has already been set. return; } currentTheme = theme; browser.theme.update(themes[theme]);}