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

  • Aaron says:

    This is wonderful and it boggles my mind why myfitnesspal hasn’t implemented this themselves. Great job!

    ReplyReply
  • Marie says:

    I follow all the instructions fine and it works. I can change them all to the grams I want and click save but the minute I move away from the goals screen my macros go back to % again. I’ve tried it several times. Has anyone else had this problem? Is there any way to fix it?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @marie That’s just how bookmarklets work. To alter the page again after it reloads, you must click the bookmark again. Your macros are saved correctly. To have the changes applied permanently, install the userscript version as outlined in the post.

    ReplyReply
  • Alienman says:

    Thank you so much for this! I’ve shared this with the keto community on reddit. 

    ReplyReply
  • Nikki says:

    Can someone walk me through this. I just have no clue how to do this

    ReplyReply
  • Kramer auto Pingback[…] recalculated my macros and added them to myfitnesspal using this wonderful browser bookmarklet which lets you add exact percentages to MFP instead of being stuck with 5% […]

  • Kramer auto Pingback[…] an app called MyFitnessPal. It's great. Well, it's great after you use Google Chrome to download this script that overwrites how you enter your information. In the original app you are only able to enter your […]

  • connie says:

    It doesn’t work for me! I’m using Firefox on Mac, and each time I click the script, I get “502 Bad Gateway”. What am I doing wrong? Please help.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @connnie Are you sure you added the bookmark bar correctly? Are you on the custom goals screen when you run it? http://www.myfitnesspal.com/account/change_goals_custom

    ReplyReply
  • Pascal says:

    Hey, it works for but the macros are shown pretty wired as e.g. instead of 375g of carbs he is showing me 374.667.000.000.000.000g either in Chrome or as my Android App. Do you have any fix for this?
     

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @pascal Where are you seeing this? MFP rounds the grams everywhere that I have seen.

    ReplyReply
  • Pascal says:

    I was seeing this in my diary but I fixed it seems like that the script is not working for the german site of mfp. I Just tried it with the english one and it worked now he shows it corecctly on both sites german and english. So everything is fine now.
    And also thank you for the nice script 😉

    ReplyReply
  • Alyssa says:

    this. is AMAZING.

    ReplyReply
  • Andres says:

    Hi Rob,
    I have Greasemonkey installed in my Firefox. Greasemonkey is enabled and the userscript for Myfitnesspal is also enabled. However, when I get to the Custom Goal screen, nothing changes…ie I can only see the 5 % increments.
    Also, how does one save the goal on this screen, there is no Save button.
    Any help is appreciated.

    ReplyReply
  • Julia says:

    Wow this is frustrating. I’ve installed TamperMonkey and the script installed fine by clicking on “Install” in Userscripts. When I go to http://www.myfitnesspal.com/account/change_goals_custom
    the Tampermonkey toolbar icon says that the script is enable. I went into the Tampermonkey dashboard and enabled it just to be sure. 
    No matter what I do, the custom boxes aren’t showing up. I’ve restarted Chrome, refreshed over and over, and nothing’s changing. 
    What am I doing wrong?

    ReplyReply
  • Skoota says:

    Doesn’t seem to work anymore. Been using it for a while but, now nothing happens. Help please!!!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    MFP just made some changes to the custom goals screen that broke the script. I’ve updated the scripts accordingly. If you are using the bookmarklet, you may need to clear your browser cache to load the new version.

    ReplyReply
  • Sam says:

    Hi Rob,
    I have bookmarked the script and accessed the macro page (shows 1% increments). However, every time I go to save the changes it comes up with this message “Macros are out of range, please adjust your choices to meet your total of 1,890 calories”
    Grrr – can you offer any assistance please?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Make sure your macros equal your calorie goal. If you’re using 1% increments for all three, make sure your percentages total 100. Or you can set your carbs to fill and set percentages for your protein and fat and forget about the math.

    ReplyReply
  • steve says:

    Hi Rob,
    I installed your script today in firefox. It works fine for the MFP webiste, but I cannot get the changes to take affect on the IOS mobile apps. I have an iPhone on IOS6 and and iPad on IOS7. i have synched several times, logged out/in. and even reinstalled the apps. I saw in the comments above it displayed correctly for tommorow and not today, but that is not it either. None of my goals have changed, total calories, and macros are off.
    This was all done today for the first time, so should be using your latest script without needing clear browser cache.
    Its not a huge concern to me just wanted to let you know.
    Thank you
     

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Looks like MFP is having some problems, if the goal changes are reflected on the web, the script is working. None of the changes I make to my goals (including total calories) are being synced to my mobile apps. I’ve seen this happen before a few times.

    ReplyReply
  • steve says:

    Yeah they are definetly having a problem. Any changes i make from the webiste do not reflect in the mobile app. However, if i make a change via the iPhone app(new feature) it will change the web. Must be a result of the new feature they added.
    There is a thread about it here.
     
    http://www.myfitnesspal.com/topics/show/1241001-can-t-edit-macro-goals-on-website

    ReplyReply
  • James says:

    Hi,
    MFP is not syncing with mobiles app…HELP???? Changes on the website work fine. 

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    It’s MFP, not the script.

    ReplyReply
  • Julia says:

    Whew, I thought I just had a bad case of The Dumb. Thanks Rob. Great script!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @julia, you’re welcome. I just had my changes from earlier today sync down to my phone, so it looks like something has been fixed at MFP.

    ReplyReply
  • Stephanie says:

    Rob I wanted to say thanks for the script!  I’ve been using it for the past few weeks on FireFox & Chrome flawlessly.
    Today I needed to tweak my macros and so logged into MFP as usual, went to goals and then opened the script.  Once I got the the macro screen in MFP the option to change to grams was not there, just the old way of percentages in 5% increments.
    i swapped to my other browser and the same issue.  Is this some sort of patch that MFP has made on the script or do I need to uninstall and reinstall the script?
    Thanks in advance for any help!!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Hi Stephanie, MFP changed the custom goals screen in a way that broke the previous version of the script. I posted a new version of the userscript that works with the changes, if you’re using Greasemonkye in FireFox, you will need to install the new version from http://userscripts.org/scripts/show/176696

    In Chrome, Tampermonkey should update the script automatically.

    ReplyReply
  • Stephanie says:

    I was finally able to get it working again!  I tried quite a few things on my end yesterday as anything I did wouldn’t work.  I decided to completely remove Tampermonkey, clear cache/cookies and reinstall everything.  It is now working again like a charm.  Many many thank yous Rob!!

    ReplyReply
  • Christy says:

    Thank you so much for being smart and doing this!!  lol 🙂

    ReplyReply
  • Diana says:

    You are awesome! i’ve been trying to change the macros and it is so frustrating not being able to see how much off or over i am without doing my own math. I changed everything and it worked;however, when i go to my diary it keeps showing what i had before. The total daily goals are off. If i go to my goals and custom, i see the right numbers but it doesnt transfer to my diary. Am i doing something wrong?
    Thank you!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    I always see my changes in my diary and mobile apps, not sure what would be causing your issue. Maybe MFP caches the diary details for some period of time?

    ReplyReply
  • Diana says:

    This is what it looks like, maybe you can see something that i cant. restarted my computer and the same thing happened. hmmm do you have any suggestions?

     
     
     

    ReplyReply
  • joe says:

    best thing ever. thanks so much

    ReplyReply
  • Diana says:

    Got it!!! Yey, i run the script you had about the totals…. OMG YOU ARE AMAZING! SUPER SMART! THANK YOU FOR ANSWERING SO QUICKLY TOO!

    ReplyReply
  • Karla says:

    worked perfectly!  thank you!

    ReplyReply
  • AlliD says:

    Can this be used on an iPhone or can it only be used on the computer?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Only on the computer, but your updated goal settings will be applied to all clients (mobile browsers, native apps, etc)

    ReplyReply
  • Allison says:

    Thank you, Thank you, Thank you!! Worked great!

    ReplyReply
  • Caitlyn says:

    I’ve been using this script for a while now, and although it is still present in GreaseMonkey, MyFitnessPal will not let me change my macro grams. I’ve disabled it, then enabled it again and nothing. I don’t know what to do.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @caitlyn Make sure that you have upgraded to the latest version of the script (1.3). MFP changed the way the goals screen works, so previous versions of the script will not work.

    ReplyReply
  • Celtic Alves says:

    Great idea man! i Love you for what u did here with JS =D
    i just come out with this problem then after  reading some forums i got here. I really aprecciated man good job!! clap clap!! =)

    ReplyReply
  • Carley says:

    Working on an apple computer using safari and I can’t get it to work. Can’t right click on the link and when I click on the update it says it’s in use by too many people. Now what?! 

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @carley I’m not sure what your issue is, I’ve never heard of that before. Here’s a video that shows how to add the bookmark to Safari: http://youtu.be/SXeCORIgRX0

    I recommend using either FireFox or Chrome with one of the extension managers so you don’t have to worry about activating the script when you go to the goals screen.

    ReplyReply
  • Gray says:

    Thank you for the script! It works very well in Chrome using Tampermonkey. You’ve made my tracking near-perfect! I wish MFP would add the ability to set high and low days with varying macros; for now I’ll just use your script to edit my macros every couple of days. Thanks again!
    -Gray

    ReplyReply
  • Scarlette says:

    Hi Rob,
    when I click on the book mark I get an internet explorer error ,can not download unspecified error…now what?  Thank you

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @scarlette What version of Internet Explorer? I recommend using FireFox or Chrome.

    ReplyReply
  • scarlette says:

    IE 8 – but I also tried your updated link for chrome and I get an error “this web page is not available”. Thanks Rob

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    http://userscripts.org/ is down again. That’s where the bookmarklet script is hosted.

    ReplyReply
  • scarlette says:

    Ok dokey I will try again later. Thanks Rob! 
     

    ReplyReply

  • Leave a Reply

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