Last active
August 29, 2015 14:03
-
-
Save glompix/a1cf91d49d022b491aa9 to your computer and use it in GitHub Desktop.
UX improvements for LiveStrong.com's MyPlate.
This file contains hidden or 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
| // ==UserScript== | |
| // @name MyPlate Improvements | |
| // @namespace http://glompix.com/ | |
| // @version 0.1 | |
| // @description A small set of improvements for LiveStrong's MyPlate app. | |
| // @match http://www.livestrong.com/myplate/dashboard/* | |
| // @copyright 2014, Stuart Branham | |
| // ==/UserScript== | |
| var _selectedDate = Date.parse($('#mini-calendar .selected').text()); | |
| var _data = JSON.parse($('#lsapp_widget_foodlog_plan').attr('data-service')); | |
| showFinishOnFinishedDays(); | |
| showCurrentStepOnToday(); | |
| selectNextMealForInput(); | |
| function showFinishOnFinishedDays() { | |
| if (!_selectedDate) { | |
| return; | |
| } | |
| var yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24); | |
| if (_selectedDate <= yesterday) { | |
| $('.steps .on[data-lsapp-step="breakfast"]').each(function() { | |
| showMeal('finish'); | |
| console.log('MYPLATE-IMPROVEMENTS: Breakfast was selected. Fixed that for you.'); | |
| }); | |
| } | |
| } | |
| function showCurrentStepOnToday() { | |
| if (!_selectedDate || !_data || !isToday()) { | |
| return; | |
| } | |
| var targetMeal; | |
| if (_data.data.meals.lunch.consumed_total > 0 && _data.data.meals.dinner.consumed_total > 0) { | |
| targetMeal = 'finish'; | |
| } | |
| else if (_data.data.meals.lunch.consumed_total > 0) { | |
| targetMeal = 'dinner'; | |
| } | |
| else { | |
| targetMeal = 'lunch'; | |
| } | |
| if (_data.data.meals.breakfast.consumed_total === 0) { | |
| targetMeal = 'breakfast'; | |
| } | |
| if (targetMeal) { | |
| console.log('MYPLATE-IMPROVEMENTS: I think "' + targetMeal + '" is the meal you want to look at.'); | |
| showMeal(targetMeal); | |
| } | |
| } | |
| function selectNextMealForInput() { | |
| if (!_selectedDate || !_data || !isToday()) { | |
| return; | |
| } | |
| var meals = ['breakfast', 'lunch', 'dinner', 'snacks']; | |
| for (var i = meals.length - 2; i >= 0; i--) { | |
| var meal = meals[i], | |
| nextmeal = meals[i+1]; | |
| if (_data.data.meals[meal].consumed_total > 0) { | |
| selectMeal(nextmeal); | |
| console.log('MYPLATE-IMPROVEMENTS: I think you want to log "' + nextmeal + '", so I selected it for you.'); | |
| return; | |
| } | |
| } | |
| } | |
| function showMeal(mealname) { | |
| $('.steps [data-lsapp-step="' + mealname + '"]').click(); | |
| } | |
| function selectMeal(mealname) { | |
| $('select[data-lsapp-key="foodLog_when"]').val(mealname); | |
| } | |
| function isToday() { | |
| return _selectedDate.toDateString() === new Date().toDateString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment