/* Load alerts and news articles. */ google.setOnLoadCallback(onStartup); var html; var date_added; var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); function onStartup() { if ($("body").attr("id").indexOf("news_page") != -1) { googleRssFeed(); loadAlerts(); } } /* Retrieve news articles from Google News and parse. */ function googleRssFeed() { var url = "https://news.google.com/news/rss/search/section/q/Flint%20Water%20Crisis/Flint%20Water%20Crisis?hl=en&gl=US&ned=us"; feednami.load(url, function(result) { if (result.error) { console.log(result.error); } else { var html = "

News articles via Google News.

"; var entries = result.feed.entries; entries.forEach(function(entry, index) { date_added = new Date(entry.pubdate_ms); html += '
'; html += '
'; html += '

' + moment(date_added).format('MMMM DD, YYYY - h:mm:ss a') + '

'; html += '
' + entry.summary + '
'; html += '
'; }); $("#news").html(html); if ($("#news .card").length == 0) $("#news").prepend("

There are no news articles available.

"); } }); } /* Retrieve alerts from the database and parse. */ function loadAlerts() { var client = gapi.auth2.getAuthInstance(); client.then(function() { gapi.client.load("storage", "v1").then(function() { var request = gapi.client.storage.objects.get({ "bucket": "h2o-flint.appspot.com", "object": "alerts.json", "alt": "media" }); request.then(function(resp) { html = ""; var js_obj = $.parseJSON(resp.body); var link; var expiration; for (var i=0; i' + alert.title + ''; html += '
'; html += '
'; html += '
' + link + '' + '

' + months[date_added.getMonth()] + ' ' + getDay(date_added) + ", " + date_added.getFullYear() + '  ' + getHours(date_added)[0] + ':' + getSeconds(date_added) + ' ' + getHours(date_added)[1] + '

'; if (alert.expiration.indexOf('0000') != -1) expiration = ''; else expiration = '

Expiration: ' + months[date_expiration.getMonth()] + ' ' + getDay(date_added) + ", " + date_added.getFullYear() + ' ' + getHours(date_added)[0] + ':' + getSeconds(date_added) + ' ' + getHours(date_added)[1] + '

'; html += '

' + alert.body + '

' + expiration + '
'; html += '
'; } $("#alerts").html(html); if ($("#alerts .card").length == 0) $("#alerts").prepend("

There are no alerts available.

"); }); }); }); } function getDay(date) { if (date.getDate() < 10) newDay = "0"+date.getDate(); else newDay = date.getDate(); return newDay; } function getHours(date) { console.log(date); console.log(date.getHours()); if (date.getHours() >= 12) { newHours = date.getHours() - 12; if (newHours == 0) newHours = 12; timeOfDay = "pm"; } else { newHours = date.getHours(); timeOfDay = "am"; } return [newHours, timeOfDay]; } function getSeconds(date) { if (date.getSeconds() < 10) newSeconds = "0"+date.getSeconds(); else newSeconds = date.getSeconds(); return newSeconds; }