diff --git a/README.md b/README.md index d40ec41..5b58d57 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,6 @@ A minimal new tab page for Chrome This is essentially a clone of Momentum Dash., which can be found here: https://momentumdash.com/ -I made this to add extra personalization and extra features. \ No newline at end of file +I made this to add extra personalization and extra features. + +Weather icons by Climacons - http://adamwhitcroft.com/climacons/ \ No newline at end of file diff --git a/css/style.css b/css/style.css index a73f92a..87cb86e 100644 --- a/css/style.css +++ b/css/style.css @@ -43,17 +43,48 @@ body { overflow-x: hidden; } +.weather .weather_icon { + max-width: 50px; + max-height: 50px; + filter: invert(1); +} + +.weather .weather_icon, +.weather .weather_high, +.weather .weather_low { + display: inline-block; +} + +.weather .weather_high { + font-size: 24px; +} + +.weather .weather_low { + font-size: 16px; +} + +.weather .weather_location_container { + margin-top: -14px; +} + .widget_outer { position: absolute; transition: opacity 200ms linear; + opacity: .3; } .widget_outer.bottom_right { padding: 150px 20px 20px 150px; bottom: 0; right: 0; + text-align: right; +} - opacity: .3; +.widget_outer.top_right { + padding: 20px 20px 150px 150px; + top: 0; + right: 0; + text-align: right; } .widget_outer:hover { diff --git a/icons/weather/0.svg b/icons/weather/0.svg new file mode 100644 index 0000000..a75c08a --- /dev/null +++ b/icons/weather/0.svg @@ -0,0 +1,13 @@ + + + + diff --git a/icons/weather/1.svg b/icons/weather/1.svg new file mode 100644 index 0000000..a75c08a --- /dev/null +++ b/icons/weather/1.svg @@ -0,0 +1,13 @@ + + + + diff --git a/icons/weather/10.svg b/icons/weather/10.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/10.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/11.svg b/icons/weather/11.svg new file mode 100644 index 0000000..c7d0cc2 --- /dev/null +++ b/icons/weather/11.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/12.svg b/icons/weather/12.svg new file mode 100644 index 0000000..c7d0cc2 --- /dev/null +++ b/icons/weather/12.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/13.svg b/icons/weather/13.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/13.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/14.svg b/icons/weather/14.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/14.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/15.svg b/icons/weather/15.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/15.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/16.svg b/icons/weather/16.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/16.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/17.svg b/icons/weather/17.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/17.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/18.svg b/icons/weather/18.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/18.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/19.svg b/icons/weather/19.svg new file mode 100644 index 0000000..d5015e2 --- /dev/null +++ b/icons/weather/19.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/2.svg b/icons/weather/2.svg new file mode 100644 index 0000000..a75c08a --- /dev/null +++ b/icons/weather/2.svg @@ -0,0 +1,13 @@ + + + + diff --git a/icons/weather/20.svg b/icons/weather/20.svg new file mode 100644 index 0000000..d5015e2 --- /dev/null +++ b/icons/weather/20.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/21.svg b/icons/weather/21.svg new file mode 100644 index 0000000..d5015e2 --- /dev/null +++ b/icons/weather/21.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/22.svg b/icons/weather/22.svg new file mode 100644 index 0000000..d5015e2 --- /dev/null +++ b/icons/weather/22.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/23.svg b/icons/weather/23.svg new file mode 100644 index 0000000..fe4a387 --- /dev/null +++ b/icons/weather/23.svg @@ -0,0 +1,18 @@ + + + + diff --git a/icons/weather/24.svg b/icons/weather/24.svg new file mode 100644 index 0000000..fe4a387 --- /dev/null +++ b/icons/weather/24.svg @@ -0,0 +1,18 @@ + + + + diff --git a/icons/weather/25.svg b/icons/weather/25.svg new file mode 100644 index 0000000..3bf11e1 --- /dev/null +++ b/icons/weather/25.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/26.svg b/icons/weather/26.svg new file mode 100644 index 0000000..3ca9a4c --- /dev/null +++ b/icons/weather/26.svg @@ -0,0 +1,11 @@ + + + + diff --git a/icons/weather/27.svg b/icons/weather/27.svg new file mode 100644 index 0000000..ee057b3 --- /dev/null +++ b/icons/weather/27.svg @@ -0,0 +1,16 @@ + + + + diff --git a/icons/weather/28.svg b/icons/weather/28.svg new file mode 100644 index 0000000..c1fc09c --- /dev/null +++ b/icons/weather/28.svg @@ -0,0 +1,20 @@ + + + + diff --git a/icons/weather/29.svg b/icons/weather/29.svg new file mode 100644 index 0000000..ee057b3 --- /dev/null +++ b/icons/weather/29.svg @@ -0,0 +1,16 @@ + + + + diff --git a/icons/weather/3.svg b/icons/weather/3.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/3.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/30.svg b/icons/weather/30.svg new file mode 100644 index 0000000..c1fc09c --- /dev/null +++ b/icons/weather/30.svg @@ -0,0 +1,20 @@ + + + + diff --git a/icons/weather/31.svg b/icons/weather/31.svg new file mode 100644 index 0000000..a3d7f86 --- /dev/null +++ b/icons/weather/31.svg @@ -0,0 +1,11 @@ + + + + diff --git a/icons/weather/32.svg b/icons/weather/32.svg new file mode 100644 index 0000000..00eaf5f --- /dev/null +++ b/icons/weather/32.svg @@ -0,0 +1,19 @@ + + + + diff --git a/icons/weather/33.svg b/icons/weather/33.svg new file mode 100644 index 0000000..a3d7f86 --- /dev/null +++ b/icons/weather/33.svg @@ -0,0 +1,11 @@ + + + + diff --git a/icons/weather/34.svg b/icons/weather/34.svg new file mode 100644 index 0000000..5c141fe --- /dev/null +++ b/icons/weather/34.svg @@ -0,0 +1,16 @@ + + + + diff --git a/icons/weather/35.svg b/icons/weather/35.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/35.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/36.svg b/icons/weather/36.svg new file mode 100644 index 0000000..00eaf5f --- /dev/null +++ b/icons/weather/36.svg @@ -0,0 +1,19 @@ + + + + diff --git a/icons/weather/37.svg b/icons/weather/37.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/37.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/38.svg b/icons/weather/38.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/38.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/39.svg b/icons/weather/39.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/39.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/4.svg b/icons/weather/4.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/4.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/40.svg b/icons/weather/40.svg new file mode 100644 index 0000000..c7d0cc2 --- /dev/null +++ b/icons/weather/40.svg @@ -0,0 +1,14 @@ + + + + diff --git a/icons/weather/41.svg b/icons/weather/41.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/41.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/42.svg b/icons/weather/42.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/42.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/43.svg b/icons/weather/43.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/43.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/44.svg b/icons/weather/44.svg new file mode 100644 index 0000000..c1fc09c --- /dev/null +++ b/icons/weather/44.svg @@ -0,0 +1,20 @@ + + + + diff --git a/icons/weather/45.svg b/icons/weather/45.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/45.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/46.svg b/icons/weather/46.svg new file mode 100644 index 0000000..e885198 --- /dev/null +++ b/icons/weather/46.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/47.svg b/icons/weather/47.svg new file mode 100644 index 0000000..0e9b2c6 --- /dev/null +++ b/icons/weather/47.svg @@ -0,0 +1,12 @@ + + + + diff --git a/icons/weather/5.svg b/icons/weather/5.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/5.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/6.svg b/icons/weather/6.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/6.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/7.svg b/icons/weather/7.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/7.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/8.svg b/icons/weather/8.svg new file mode 100644 index 0000000..77fbd77 --- /dev/null +++ b/icons/weather/8.svg @@ -0,0 +1,17 @@ + + + + diff --git a/icons/weather/9.svg b/icons/weather/9.svg new file mode 100644 index 0000000..724bb2f --- /dev/null +++ b/icons/weather/9.svg @@ -0,0 +1,13 @@ + + + + diff --git a/js/main.js b/js/main.js index 1ee169e..072e391 100644 --- a/js/main.js +++ b/js/main.js @@ -9,10 +9,29 @@ var settings = { }, "notes": { "default": "Type notes here" + }, + "weather_location": { + "default": "New York", + "allowNewlines": false, + "maxCharacters": 30 } } }; +var weather = { + timeUpdated: "", + location: "10016", + + city: "", + currently: "", + image: "", + low: "", + high: "", + temp: "", + todayCode: "", + wind: {} +}; + // Load in all data into prefs object chrome.storage.sync.get(Object.keys(settings.contentTypes), function (result) { let keys = Object.keys(settings.contentTypes); @@ -21,11 +40,32 @@ chrome.storage.sync.get(Object.keys(settings.contentTypes), function (result) { if (result.hasOwnProperty(key)) { prefs[key] = result[key]; } else { - saveSetting(settings.contentTypes[key].default, key); + saveSetting(settings.contentTypes[key].default, key, true); } } }); +// Load in weather data from local store +chrome.storage.local.get(Object.keys(weather), function (data) { + let keys = Object.keys(weather); + let dataExists = false; + for (i in keys) { + key = keys[i]; + if (data.hasOwnProperty(key)) { + dataExists = true; + weather[key] = data[key]; + } + } + + if ( + !dataExists || // if we've never gotten the weather before + weather.timeUpdated < moment().format("x")-360000 // or if the weather data is outdated + ) { + console.log("Getting weather data..."); + getAndUpdateWeather(weather.location); + } +}); + $( document ).ready(function() { var interval = setInterval(function() { var momentNow = moment(); @@ -46,6 +86,7 @@ $( document ).ready(function() { // initialize displays $('.name').html(prepTextForDisplay(prefs.name)); $('.notes').html(prepTextForDisplay(prefs.notes)); + updateWeatherDisplay(); // fade in $('.centered_box, .wallpaper').fadeIn(); @@ -115,7 +156,11 @@ $( document ).ready(function() { newDisplayText = prepTextForDisplay(htmlDecode(newSaveText)); el.html(newDisplayText); - saveSetting(newSaveText, contentType); + if (contentType == "weather_location") { + getAndUpdateWeather(newSaveText); + } else { + saveSetting(newSaveText, contentType, true); + } }); /* @@ -126,11 +171,18 @@ $( document ).ready(function() { */ }); -function saveSetting(newText, key) { +function saveSetting(newText, key, isSync) { prefs[key] = newText; newSetting = {}; newSetting[key] = newText; - chrome.storage.sync.set(newSetting, function() {}); + + if (isSync) { + storageType = "sync"; + } else { + storageType = "local"; + } + + chrome.storage[storageType].set(newSetting, function() {}); return newText; } @@ -154,4 +206,46 @@ function htmlEncode(value){ function htmlDecode(value) { return $('
').html(value).text(); +} + +function getAndUpdateWeather(location) { + $.simpleWeather({ + location: location, + unit: 'f', + woeid: '', + success: function(weather) { + console.log("Weather received! Updating..."); + updateWeather(weather); + updateWeatherDisplay(); + }, + error: function(error) { + console.log(error); + $('.weather_location_container').effect("highlight", {color: "ff9595"}, 2000); + } + }); +} + +function updateWeather(weatherObj) { + let keys = Object.keys(weatherObj); + for (i in keys) { + key = keys[i]; + + if (weatherObj.hasOwnProperty(key)) { + weather[key] = weatherObj[key]; + saveSetting(weather[key], key, false); + } + } + + // finally, update time updated + weather.timeUpdated = moment().format("x"); + saveSetting(weather.timeUpdated, "timeUpdated", false); +} + +function updateWeatherDisplay() { + if (weather.city != "") { + $('.weather .weather_high').html(weather.high+"°"); + $('.weather .weather_low').html(weather.low+"°"); + $('.weather .weather_icon').attr("src", "/icons/weather/"+weather.todayCode+".svg"); + $('.weather .weather_location').html(weather.city); + } } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 584dd9e..7df0b9d 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "chrome_url_overrides" : { "newtab": "newtab.html" }, - "content_security_policy": "script-src 'self' https://code.jquery.com https://maxcdn.bootstrapcdn.com https://cdnjs.cloudflare.com; object-src 'self'", + "content_security_policy": "script-src 'self' https://query.yahooapis.com https://code.jquery.com https://maxcdn.bootstrapcdn.com https://cdnjs.cloudflare.com; object-src 'self'", "permissions": [ "storage" ] diff --git a/newtab.html b/newtab.html index 720b14b..9ca0da5 100644 --- a/newtab.html +++ b/newtab.html @@ -3,8 +3,12 @@ + + + + @@ -30,9 +34,17 @@ +