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

  • Max says:

    thanks a lot!!!

    ReplyReply
  • Kramer auto Pingback[…] My other topics REPLY QUOTE Posted : 2013-10-08 06:00:09 Subject: Re: DIET PERCENTAGES http://karoshiethos.com/2013/08/13/javascript-bookmarklet-for-enhanced-macro-goals-in-myfitnesspal/ ^Gives you more tweaking ability. What you already have sounds about right though, tbh. If […]

  • Deb says:

    I can not get it to work on my Mac Book either .Bummer it sounds amazing!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    I developed the script on a Mac, id will definitely work for you if you follow all of the steps.

    ReplyReply
  • Kramer auto Pingback[…] with 1g increments as opposed to its 5% increments. Follow the instructions in the link below: http://karoshiethos.com/2013/08/13/j…-myfitnesspal/ This has worked perfectly for me and it syncs to your mobile app also, if you have any problems […]

  • Jason says:

    The script works beautifully with Chrome and updates correctly on the MFP website. However, after I do my sync, I notice the new macros are not reflecting in the MFP iPhone app. 
    Thoughts?
    Thanks

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    The app needs to sync with the server to update the goals. You may want to try shutting it down (Actually terminating the app, not just closing it). I’ve found that this is often the case with or without the script.

    ReplyReply
  • Jason says:

    Thanks for the quick response. I see what happened. For some reason, the Macro changes (only) I made on the website won’t reflect until tomorrow on the MFP app. When I scroll to tomorrow’s goals, I see the updated Macros that I requested. Again, thanks for your help. Your script works perfectly. 

    ReplyReply
  • Fernando says:

    THANK YOU. Work great.

    ReplyReply
  • Kramer auto Pingback[…] alterarem o valor dos macronutrientes ao pormenor (g), pode dar jeito para alguem (para mim deu) http://karoshiethos.com/2013/08/13/j…-myfitnesspal/ SQ 135kg BP 115kg DL 170kg Press 70kg Responder com […]

  • Kramer auto Pingback[…] how to set specific macros with MFP!  (Instead of the default 5% increments…). Check it out here! Posted by Leslie Hylton at 5:51 PM No comments: Email […]

  • Dome Pirate says:

    hey
    first off thanks for doing this. so my issue here is that I am 1. NO computer person and have NO clue how I can integrate that bookmarkk (if that is what I am doing) into mpf.
    i am no english tongue so i am not understanding technical things (not even understanding them in german lol)
    so if I add the link on that bookmark horizontal on top (when i click on it i get on this exact page?) and then switch to mfp site and start the goal- custom…then i click on the bookmark link it leads me back here (which would make sense )
    ahh…thanks for helping a girl 😉

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    It sounds like you are bookmarking this page. What you need to do is drag the blue box with the white text that reads, “MyFitnessPal Macro Enhancements” to your bookmarks bar. Then when you are on the custom goals screen in MFP, click the bookmark.

    ReplyReply
  • Kramer auto Pingback[…] how to set specific macros with MFP!  (Instead of the default 5% increments…). Check it out here! Leslie Hylton at 5:51 PM […]

  • Dome Pirate says:

    thank you. hahaha……. I hope it works now 🙂 

    ReplyReply
  • Lindsay says:

    I can see the script has worked in the the custom goals page but I am not able to save the changes. Every time I hit “change goals” the macros revert back.

    ReplyReply
  • Mel says:

    I downloaded it but nothing seemed to happen…
    Like i dont have have MFP enhancements thing….

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    If you are just using the bookmarklet and not the userscript, you have to click the bookmark every time the page loads. So after you submit your changes and the page loads, you have to click it again. That’s a limitation of the bookmarklet technology. Set you the userscript and the script will always be applied automatically.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    Please re-read the instructions carefully and try again.

    ReplyReply
  • Will Jackson says:

    Hey Rob, when I click the link below the update paragraph I go onto the page and click the install button top right, but my internet tells me I can’t download it because of the potential danger, I’m on chrome, any help?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @will Have you installed Tampermonkey? You need Tampermonkey to run userscripts.

    ReplyReply
  • Will Jackson says:

    Thanks man, but, how can I install tampermonkey?

    ReplyReply
  • Will Jackson says:

    I downloaded tampermonkey and went on the link, although, I’m on the page with just lots of random text, I know I’m dumb but what should I be doing from here?

    ReplyReply
  • Will says:

    I downloaded tampermonkey and went on the link, although, I’m on the page with just lots of random text, I know I’m dumb but what should I be doing from here?

    ReplyReply
  • Will says:

    Hey man could I get any help?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @will If you have Tampermonkey installed correctly, it should fire up and install the script automatically when you hit the install button on the userscript page.

    ReplyReply
  • Andrew says:

    I have installed Tampermonkey, however I’m not sure if I’ve done it properly, how do I find out? Whenever I click install on the userscript page it brings me to a page full of text, and I’m not sure whether its worked or not?

    ReplyReply
  • Andrew says:

    Do I need greasmonkey and firefox too?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @andrew When you go to the custom goals page on MyFitnessPal do you see the enhancements?

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @andrew No, Chrome users need Tampermonkey and FireFox users need Greasemonkey.

    ReplyReply
  • Will Jackson says:

    Oh my god you absoloute lifesaver, if I change my goals on the internet will it correspond with the goals on my iPhone app too? Thanks man!

    ReplyReply
  • Andrew says:

    Nice work bro much appreciated 

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @will Absolutely, I use the iPhone app pretty much exclusively.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @andrew Thanks, enjoy.

    ReplyReply
  • Kamal says:

    Man thanks heaps works like a charm.. your a legend..

    ReplyReply
  • Morgan says:

    when i enter in the grams it all works, but then when i press change goals it says that my macros are out of range and that I need to adjust my goals

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @morgan Make sure your macros actually add up to your calorie total. That error indicates that you have set all three macros to grams, and your gramsxcalories per gram do not equal your calorie total. I typically set my carbs to fill the space left after assigning protein and fat, so I never have to do that math.

    ReplyReply
  • Christina says:

    Thank you SO much for this, Rob!! I greatly appreciate this 🙂

    ReplyReply
  • Tania says:

    Hi Rob!  Will this work in Sarfari (with Mavericks?)???  I’m trying to right click on the link and i’m not seeing the option to add to favorites.  Can you confirm that you’re talking about this link:
    http://karoshiethos.com/2013/08/13/javascript-bookmarklet-for-enhanced-macro-goals-in-myfitnesspal/#sthash.lJjNVkOi.dpuf
     

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @Tania Yes, it works in Safari, but safari does not have an add to bookmarks function in the context (right click) menu, you have to drag the link to your bookmarks bar.

    ReplyReply
  • Anna says:

    I have added the script to the bookmarks but when I go to myfitnesspal and go to the goals, and then click it from the toolbar it just takes me back to this page.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @Anna, it sound like you bookmarked this blog post instead of the script. If you’re using FireFox or Chrome, I recommend installing the userscript. If not, make sure you are adding the blue box with the text, “MyFitnessPal Macro Enhancements” to your bookmarks.

    ReplyReply
  • Crystal says:

    I can’t get this to work either.. on my Safari. The software is OS X 10.9.1
     
    It very well could be me, a little help please 🙂 I really could use to have the appropriate macros in my MFP to help me succeed in my training.
     
    Thanks!!

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    I recorded a quick video on how to use the script in Safari: http://youtu.be/SXeCORIgRX0

    ReplyReply
  • Juk says:

    i added it to the bookmark, and when i click nothing happen. It’s like i didn’t click anything

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    @Juk What browser are you using? Are you on the custom goals screen of MyFitnessPal when you click the bookmark? If you are using FireFox or Chrome, I suggest installing the userscript version instead.

    ReplyReply
  • Michael says:

    I have tried using the javascript on all sites, IE, Chrome and Firefox and can no longer get it to work.
    I used to use it on Firefox previously, where I had it saved as a book mark. Now when I click on it nothing happens.

    ReplyReply
  • Rob Ruchte Rob Ruchte says:

    It’s working for me in Firefox, Chrome, and Safari. I didn’t fire up a VM to check IE, but if the others are working, I’m sure IE is as well. Are you sure you’re on the custom macro goals screen when you click the bookmark? It only works on that page, and will not take you there if you are on another page. I recommend using the userscript with Chrome or FireFox. Have you tried that?

    ReplyReply
  • A says:

    For anyone yet to use this that is having trouble. I misunderstood the directions, driving myself crazy for nothing. You don’t have to install the link. All you have to do is drag the BLUE MFP MACRO ENHANCEMENTS link to your bookmarks and then go to MFP custom goal, go to bookmarks and click on the saved MFP blue link and change your MFP to grams and then enter the grams you want to use. Save and you’re done. I probably like a few others kept mistakenly dragging the blue userscript.org link, which is the WRONG link, everyone. Just an FYI for all those new to using this.

    ReplyReply

  • Leave a Reply

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