JavaScript Bookmarklet for Enhanced Macro Goals in MyFitnessPal
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
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
works like a charm ..thank you for making the nearly best app the very best app 🙂
Won’t work for me on my Mac (Safari 5.1.9) 🙁
@Sandra Works for me in 6.0.5.
Does’nt work even with you link for chrome…..i download everything but nothing happens
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.
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?
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.
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.
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.
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!
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.
@AC, I posted a new version that I think should solve that hanging problem, grab the latest version and see if it’s smoother.
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.
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
You should see a set of select boxes to the left of the macro percentage selects.
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
Hmmm. What is the URL of the page that you’re on?
http://www.myfitnesspal.com/account/change_goals_custom
this what you’re looking for?
Yeah, it should be working for you there. Make sure the script is enabled, if it is, try uninstalling and reinstalling.
bingo! thanks for your help.
this is the greatest thing since sliced bread ….. hnnnnggggg
Thank you 🙂
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!
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.
I just posted a userscript that fixes the food diary totals: http://userscripts.org/scripts/show/176827
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.
So bloody good! Thanks heaps Rob this is fantastic!
Sandra, just bookmark the link then click on it. Just did it on mozilla for mac it works
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!
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!!
@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.
Okay got it thanks Rob.
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
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!
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!!!!!!!!!!!!!
You are a such a wonderful soul! Thank you so much! :]
this is such a bummer! I cant figure it out
I have a macbookpro
@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.
Thank you so much!
[…] special shout out to Rob Ruchte for creating this awesome script. Seriously awesome […]
I can’t get this to work on my macbook pro. Help?
@alexis Where are you running into trouble?
[…] 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 […]
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!
[…] 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 […]
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?
It sounds like you bookmarked this page instead of the script. Drag the big blue link to your bookmarks bar.