Skip to content

Commit

Permalink
Implemented celsius option
Browse files Browse the repository at this point in the history
  • Loading branch information
skoshy committed Jan 8, 2017
1 parent e4daabe commit bc6dec6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ This is essentially a clone of Momentum Dash., which can be found here: https://

I made this to add extra personalization and extra features.

Other icons by Glyph - http://glyph.smarticons.co/
Other icons by Glyph - http://glyph.smarticons.co/

Currently, the weather is obtained by calling my domain (api.k0shy.com) and from there calling Open Weather Map to retrieve the weather data. This is so I can cache weather conditions on my server so I don't need to do excessive API calls to Open Weather Map.

Weather is cached for 1 hour. Absolutely no identifiable data is captured when calling my API.
2 changes: 1 addition & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ h1 {
width: 100%;
position: absolute;
text-align: center;
text-shadow: 0px 0px 30px #333;
text-shadow: 0px 0px 10px #000;
}

.time {
Expand Down
19 changes: 17 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var settings = {
"default": false,
"class": "blur",
"type": "checkbox"
},
"celsius": {
"default": false,
"class": "celsius",
"type": "checkbox"
}
}
};
Expand Down Expand Up @@ -132,6 +137,7 @@ $( document ).ready(function() {
updatePrefsDisplay("notes");
updatePrefsDisplay("custom_image");
updatePrefsDisplay("blur");
updatePrefsDisplay("celsius");
updateWeatherDisplay();

// add in all wallpaper thumbs
Expand Down Expand Up @@ -378,6 +384,8 @@ function updatePrefsDisplay(key) {
} else {
$('.wallpaper').removeClass('blurred');
}
} else if (key == "celsius") {
updateWeatherDisplay();
}
}

Expand All @@ -386,6 +394,10 @@ function removeLinebreaksForDisplay(text) {
// .replace(/<\s*br.*?>/g, " ")
}

function convertToCelsius(fahr) {
return Math.round((fahr - 32) * (5/9));
}

function convertLinebreaksToBrs(text) {
return text.replace(/(?:\r\n|\r|\n)/g, "<br>");
}
Expand Down Expand Up @@ -451,8 +463,11 @@ function updateWeather(weatherObj) {
function updateWeatherDisplay() {
console.log("Updating weather display");
if (weather.weather_location != "") {
$('.weather .weather_high').html(weather.high+"&deg;");
$('.weather .weather_low').html(weather.low+"&deg;");
high = prefs['celsius'] ? convertToCelsius(weather.high) : weather.high;
low = prefs['celsius'] ? convertToCelsius(weather.low) : weather.low;

$('.weather .weather_high').html(high+"&deg;");
$('.weather .weather_low').html(low+"&deg;");
$('.weather .weather_icon').removeClass(function(index, css) {
return (css.match(/(^|\s)wi-owm-\S+/g) || []).join(' ');
}).addClass('wi-owm-'+weather.condition_code);
Expand Down
6 changes: 6 additions & 0 deletions newtab.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ <h1>Preferences</h1>
<div contentEditable data-content-type="weather_location" class="weather_location selectable"></div>
</div>
</div>
<div class="prefs_row">
<div class="label">Use Celsius?</div>
<div class="field">
<input type="checkbox" data-content-type="celsius" class="celsius"/>
</div>
</div>
<div class="prefs_row" style="margin-top: 20px;">
<button class="reset_settings">Reset All Settings</button>
</div>
Expand Down

0 comments on commit bc6dec6

Please sign in to comment.