JavaScript Bookmarklet for Enhanced Macro Goals in MyFitnessPal

 Aug, 13 - 2013   299 comments   ProjectsThings that are broken
Please read this post from Steven at MyFitnessPal regarding the change to allow setting macros by gram, along with other advanced nutrition options as part of their new premium service.

This JavaScript bookmarklet will enhance the macro target section of the custom goal editor  in MyFitnessPal with some advanced features that allow you to set up a more complex macro strategy.

Features:

  • Set percentages in 1% increments
  • Set targets in grams rather than percentage
  • Set one of the three macros to  automatically fill any remaining calories in your daily goal that are not allocated to the other two macros
  • Remember your advanced settings as long as you do not overwrite your changes with the default MFP 5% scheme

Screen Shot 2013-08-13 at 9.22.29 AM
Example – Specify protein in grams, fat as a percentage, fill remaining calories with carbs

 

How To Install The Script

 

The script is available as a userscript for use in browser extensions like Greasemonkey (for FireFox) and Tampermonkey (for Chrome). Running like this, the fix is always there, even after you update, and you never have to manually run anything. You can install the script here:
http://karoshiethos.com/js/MFP_Macro_Fix.user.js

Internet Explorer and Safari users need to add the bookmarklet below to their bookmarks. When you are on the MyFitnessPal custom goal screen, click on the bookmark, and the form will be enhanced with these features. After you save your changes, the form will revert back to the default 5% increments, but your gram counts will be correct. The mobile apps will display your chosen percentages and grams properly. You will need to click the bookmark each time you want to change your macros.

Internet explorer users, right click the link in the blue box below and click “Add to Favorites”. Safari users, drag the link up to your bookmarks bar.

 

MyFitnessPal Macro Enhancements

 

 

How does it work?

The script is a small JavaScript class that adds components and logic, and integrates with the existing logic in the custom goals screen. When you are finished with your changes and submit the form, the grams for each macro are translated into high-resolution percentages (Example: Carb=44.56666666666666%, Protein=30.533333333333335%, Fat=24.9%), which are saved exactly the same way the default 5% increment percentages would be. MyFitnessPal will round the percentages to the nearest 1% when displaying percentages on the website and in the mobile apps, but they appear to use the high resolution percentages for calculating grams. In my testing, the gram counts always come out as specified.

I’m not sure why this functionality is not already available in MyFitnessPal, I think most users who are serious about their diet probably set up their macros by the gram, or in some combination of grams and percentages.

This is a quick fix I put together in my spare time. It may have bugs. If so, I may or may not fix them. I have tested this in Chrome, Firefox, Safari, and IE10 and 11 – it may not work in IE6, IE4 for Mac, NCSA Mosaic, Lynx, etc. in other words, if you are not running an up to date browser, YMMV. If you need help and your questions are not already answered in the comments, you can find me on Twitter at @robruchte or email me at rob.ruchte@gmail.com


Related articles

 Comments 299 comments

  • Kramer auto Pingback[…] genauen justieren der Macros, kannst du dir mal den Link hier anschauen:http://karoshiethos.com/2013/08/13/java … itnesspal/ Nach oben Vorherige Beiträge der letzten Zeit anzeigen: Alle Beiträge1 Tag7 Tage2 […]

  • shaun says:

    works like a charm ..thank you for making the nearly best app the very best app 🙂

    ReplyReply
  • Sandra says:

    Won’t work for me on my Mac (Safari 5.1.9) 🙁

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @Sandra Works for me in 6.0.5. 

    ReplyReply
  • sarah eve says:

    Does’nt work even with you link for chrome…..i download everything but nothing happens

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Are you following the instructions?

    1. Add the bookmark to your bookmarks list
    2. Go to your custom goals
    3. Click the bookmark

    Or just install the userscript in FireFox with Greasemonkey or Chrome with Tampermonkey.

    ReplyReply
  • Kameron Ross says:

    Wow this is great! I was able to use your first update with changing it to 1% but this is what comes up everytime I try to use your new update regarding being able to change macros to grams not percentages….. I even am using greasemonkey.

    “A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.”

    Script: file:///Users/Kameronross/Library/Application%20Support/Firefox/Profiles/fhz5355t.default/gm_scripts/MyFitnessPal_Macro_Fix/MFP_Macro_Fix.user.js:295

    Any suggestions?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Hey Kameron, if you’re comfortable editing the script, go down to line 299 and replace the four instances of 0.00000000000001 with something less precise, like 0.001 and see if that solves your problem. It’s possible that your ratios could cause that loop to run for a long time.

    ReplyReply
  • Kameron Ross says:

    Thanks for the reply! Unfortunately I am not sure how to edit a script. Looks like I will have to use the 1% update for now which is MUCH better than the 5% anyway.

    ReplyReply
  • AC says:

    Hey Rob, I’ve been trying to change the macros in grams and/or percentages through Chrome and Safari but when I click on “Change Goals” to save my changes, the page freezes up. I’ve even tried installing the userscript with Tampermonkey for Chrome. 

    ReplyReply
  • AC says:

    Hi again, Ignore my previous comment! I had to mess around with the amount of grams/calories of my macros to get it to add up PERFECTLY in order for it to not freeze. This script will be helping hundreds of people. Thank you so much!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    I updated the scripts to get around the problem you’re having, if you update from userscripts.org I think it will work for you.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @AC, I posted a new version that I think should solve that hanging problem, grab the latest version and see if it’s smoother.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    I found and fixed the bug that was causing the script to hang in some cases, please grab the latest version if you are using the userscript. If you’re using the bookmarklet, you may need to clear your cache. 

    ReplyReply
  • RDel says:

    I installed the script to tampermonkey, but I’m not seeing anything happen when I open the customize page….feels like I’ve missed something

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    You should see a set of select boxes to the left of the macro percentage selects.

    ReplyReply
  • RDel says:

    Nope. Just the typical pull-down percentage boxes.  I must not have installed it properly or not have the fix running. Kinda new to these modifications
     

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Hmmm. What is the URL of the page that you’re on?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Yeah, it should be working for you there. Make sure the script is enabled, if it is, try uninstalling and reinstalling.

    ReplyReply
  • RDel says:

    bingo!  thanks for your help.

    ReplyReply
  • Chris says:

    this is the greatest thing since sliced bread ….. hnnnnggggg 

    Thank you 🙂 

    ReplyReply
  • Beth says:

    Hey Rob, I’ve found another problem in MFP (of course NOT related to your script because it’s AWESOME!) But when I’m on my ‘Food Diary’ page, I am finding that my “calories remaining” are not adding up to what I manually calculate them to be when I add up all my macros. I found the problem to be in my individual food. Some individual foods were adding up correctly but some would under count calories which in the end would make my remaining calories more. So if i’m using IIFYM, I see i have 200 cals left for the day when in actuality if i add up my remaining macros, I would only have 50 cals left. Is there a way you could make a script that would affect the food diary page, that when clicked would add up your remaining calories from your macros instead of just adding and subtracting calories from your meals? I hope I explained this enough and it’s not too confusing. Thanks!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Hi Beth, that annoys the heck out of me too – I just completely ignore the calorie total in MFP and just go by the macros. This is a great idea, I think it should be possible, I’ll look into it.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    I just posted a userscript that fixes the food diary totals: http://userscripts.org/scripts/show/176827

    ReplyReply
  • Beth says:

    Great! thanks!! I was about to tell you that I couldn’t figure out how to use the Tampermonkey feature and these userscripts but I just figured it out. It’s a pretty cool.

    ReplyReply
  • Warwick says:

    So bloody good! Thanks heaps Rob this is fantastic!

    ReplyReply
  • Sorisx says:

    Sandra, just bookmark the link then click on it. Just did it on mozilla for mac it works

    ReplyReply
  • Dooxy86 says:

    You sir are the master of things! i don’t know how match i can tell you i love you for this….. all the small notes i have on the back on my phone and in front of my computer in order to remember my macros and now i can actually see them exactly how i want it! 

    this is even bigger news for me then Obama coming to Sweden! 

    ReplyReply
  • Stacey says:

    Hmmm so I can’t get it to save….meaning it works and stays at the macros I want when I am in the website but once I leave the site and go back, it returns to the original percentages.  Any help??  This great though!!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @Stacey If you’re using the bookmarklet, you have to click the bookmark each time the page loads, so after you save, you have to run it again. If you install the userscript, the page will always have the enhancements.

    ReplyReply
  • Stacey says:

    Okay got it thanks Rob.

    ReplyReply
  • Lourdes says:

    My only question is when i set my macros in grams, it continues giving me an error “Macros are out of range, please adjust your choices to meet your total of ### calories” is there an auto populate for the calories? I have tried changing the about of calories to make it work, but i wont work. Thank You

    ReplyReply
  • Lourdes says:

    I figure it out I set my amount of fat in g, and protein in g, and then used the <> for carbohydrates and it works wonders! to fix the calories. Thank You, I am so excited to continue using MyFitnessPal. You are awesome!

    ReplyReply
  • Cheurice says:

    I’m no javascript pro, but I was able to figure this out and make it work for me using your firefox bookmark add-on…thing. For other non-pros like myself, even though I added the link to my bookmarks, it did not work until I clicked the menu button and made sure my javascript was enabled. Then I refreshed my “Custom goals” page, clicked the bookmarked link again, and it worked. Thanks so much!!!!!!!!!!!!!

    ReplyReply
  • Farrah says:

    You are a such a wonderful soul! Thank you so much! :]

    ReplyReply
  • Charae Duong says:

    this is such a bummer!  I cant figure it out

    ReplyReply
  • Charae Duong says:

    I have a macbookpro
     

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @Charae You have two options.

    1. Drag the blue bookmark link in this page to your bookmarks bar, then when you are on the custom goals screen, click the bookmark in your bookmarks bar.
    2. In FireFox, install the Greasemonkey extension, or in Chrome, install the Tampermonkey extension, then install the userscript from here: http://userscripts.org/scripts/show/176696. After that, whenever you go to the custom goals screen on myfitnesspal.com, the enhancements will be there.

    ReplyReply
  • Judy says:

    Thank you so much!

    ReplyReply
  • […] special shout out to Rob Ruchte for creating this awesome script. Seriously awesome […]

  • Alexis says:

    I can’t get this to work on my macbook pro.  Help?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @alexis Where are you running into trouble?

    ReplyReply
  • […] in terms of tracking your macros (MFP uses percentages for macros, but I’ve found a way to circumvent this) and giving you free reign over how many other nutrients you want to be tracking (MFP only […]

  • mai says:

    This is seriously awesome. I love it and thanks so much for providing it. And Lourdes, thanks for the tip on figuring out the calories for MFP to accept the changes!

    ReplyReply
  • […] 55% or 60%.  For the first couple of weeks, I rounded my numbers but then found this nifty little script that would let me get my split dead on target.  I know a lot of people I follow on Instagram […]

  • Eric says:

    Ok, maybe im just dumb, but i can not get this to work.
    Is internet explorer not supported?
    I added the link to my bookmarks in IE, went to the custom goals in MFP, clicked on the favorite, and it just brings me to this page?
    Help, anyone?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    It sounds like you bookmarked this page instead of the script. Drag the big blue link to your bookmarks bar.

    ReplyReply

  • Leave a Reply

    Your email address will not be published. Fields with * are mandatory.