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
This is an amazing script! Any chance of combining it with the LeanGains auto MFP updater python script?
Or perhaps a whole new script that understands carb/calorie cycling?
http://www.reddit.com/r/leangains/comments/ny4km/i_made_myfitnesspal_work_with_lg_testers_please/
this is awesome but I am having a serious issue with it. I installed on both safarie as well as firefox. after i enter my numbers under grams i get a pop up script from MFP saying macros are out of range to meet my number of calories 🙁 any suggestions as to how i can prevent this? or do i need to just adjust the calories to what my macros are? ( if thats the case i am screwed hahaha)
i would love your thoughts thanks!
@susan, yes, if you set all three macros to grams, the values you set must add up to your calorie goal. Fat=9cal Carb & Protein=4cal. I suggest setting one of your macros to fill (double arrow), then set your grams for the other two. That way the script figures out the math for you.
@Ophelia Sounds like you are using the bookmarklet and saving your goals without running the bookmarklet after saving the with the bookmarklet. Try using greasemonkey.
@Stephan I’ll look into that, there are a lot of functionality I would like to add to MFP. Thanks for turning me on to it.
Hiya thanks for your reply. Again sorry if it’s a stupid question, but how do I use greasemonkey? I installed it just before I downloaded your program and thought it just did it thing automatically. Sorry again x
Just found this today – awesome for job!
Thank you!!!
Worked great! Followed your instructions for Chrome, no troubles installing. New numbers have carried over to my Android app on Samsung Galaxy S5, for the most part. Under “Nutrition” and under “Diary” tabs all info shows my updated percentages and numbers. But under “Goals”, it still lists the old 5% percentages (my goals are 50%, 23%, 27%). I don’t think this is a problem, just putting it out there as an FYI to other people.
This is excellent. Would you mind if I shared this and linked back to your page on my blog? I know my readers would benefit from this post. Thanks – Erin
I am using Firefox , Greasemonkey is installed and the script is activated.
1 hour ago, the app reduced my calories from 3200 to 3000 and deactivated the script, so that is have to use the 5%-steps.
Anyone having this problem too?
It’s working fine for me.
Wow! Thank you so much!!! You are a genius!!!
I installed this app via tampermonkey in chrome but it’s not working for me :/ mfp stay’s the same
It’s working for me.
Thank you! just did it today on google chrome and it worked just fine.
I sincerely appreciate it.
it doesnt work in chrome. I did everything like you say, still doesnt work
It’s working for me in Chrome. Follow the instructions in the video carefully.
Hi Rob,
I ran the userscript using Tampermonkey with Chrome. Worked a charm. However, after this, I am noticing my MFP has problems calculating the total calories for the day. The actual total calories doesn’t match up to the macros. Help!
Lin
That’s a problem in MFP with or without the script, the script doesn’t have any impact on how MFP calculates your calorie total. MFP does not calculate calories based on the macro nutrients in the food data,it uses to total calories in the food data. So you could have a food record with 1 gram carb, 1 gram fat, and one gram protein (should add up to 17kcal) but the total calories could be listed at 15 kcal, so MFP will log 15kcal. These discrepancies could be due to rounding, or just mistakes in the data.
Thank you. Once I was able to reinstall chrome and download Tampermonkey – this worked absolutely wonderful. Thank you!
Hi Rob,
Thanks for much your time and patience in addressing each and every one of these enquiries, even so long after you put out the original script. The length of this comments thread is testament to that. It certainly is appreciated! You rock! 🙂
Also another question. I am using MFP on android 4.4. When it syncs, it still doesn’t give me the exact macros I entered on MFP using the userscript? Its very close, eg, 48g fat instead of 45g. Total calorie goal is correct. I think it rounded to the nearest 5%. I tried uninstalling and reinstalling MFP, to no avail. Is there anything I can do?
That’s really odd, I’ve never seen that happen. I use iOS, but it’s always exactly what I enter.
Hi Rob,
Thank you so much for sharing this!
I’ve read your response to @susan, but I’m still confused – I’m sorry. I’m getting the same error as she was and can’t work out how to fix it. The macros I’m trying to set are 130g for carbs, 130g for protein & 35g for fats but it won’t let me. I then tried changing the kjs to 1355 (9×35=315 + 4×130=520 + 4×130 = 1355) but it still won’t allow me to save it.
Could you please help me?
Thank you so much!
With kind regards,
Georgie
@susan, yes, if you set all three macros to grams, the values you set must add up to your calorie goal. Fat=9cal Carb & Protein=4cal. I suggest setting one of your macros to fill (double arrow), then set your grams for the other two. That way the script figures out the math for you.
@Georgie That’s odd, I can’t recreate the problem with the macro values that you listed. Do you get the “Macros out of range” message?
Worked like a charm ! Love it
Good stuff man thanks a lot!
Hi Rob,
Thank you for your reply.
Yes, I get the “Macros are out of range, please adjust your choices to meet your total of 1355 calories” when trying to put in 130g for both carbohydrates and protein and 35g for fat.
I cannot for the life of me get it to save!
With kind regards,
Georgie
Thank you. You are awesome!!
Thank you!
NOPE! I added the tampermonkey for chrome extension. It has then gone to the top right corner next to the address bar but it wont work. went back in and out of chrome and myfitnesspal and it does’nt do anything.
My tampermonkey logo is grey and looks like it is inactive
Hi! great great script! very useful, but i keep getting this trouble ,i don’t know if t happens to anyone else too. i did every step in the video for google chrome and after i log my macros and and hit save it i get this: “There was a problem with your request
Sorry, but a server error occurred processing your request. Our team has been notified of the issue.” and it puts crazy big values on my macros. please help. Thank you very much
I haven’t seen that happen, but if you are getting huge numbers in your macros, it sounds like your calorie goal is set to something really high.
Followed your instruction video using GreaseMonkey with FireFox. Worked like a charm. Thank you SO much! 🙂
Worked great, your Awesome man !! thanks for doing this
Any chance you could create something for iOS?
thank you!! what an awesome thing to discover today! 🙂
Yes, there is a way to install the bookmarklet in iOS, but it’s a bit tricky.
Now you can go to the custom goals screen, tap the bookmark, and it will run the script.
installed it on chrome on my macbook and malware came along with it! now i get pop ups that lock up my chrome and safari… great
That’s from something else. All my script does is change the way a form on MyFitnessPal works.
Any chance this will update for a Kindle fire application?
Yes, changes to your goals will be reflected in the Kindle app, just like iOS and Android.
This is awesome, great work thanks for this.
Thank you for this – so helpful!
Hello.
It did not work for me in Chrome. So I had to add in the “user include” in TM edit this line “http://www.myfitnesspal.se/en/account/change_goals_custom”
And it works fine now.
Exhale: Ahhhhh. Thank you =D
Sincerely, thank you! 🙂
Thank you for building this. I find it very helpful. I think I could hack on this a little to add support for fat profile: 50% saturated, 25% PUFA, 25% MUFA, 0% trans fat.
I had no idea something like this existed. For the longest time I had just stuck with the 5% incremental options and did my best to remember what the actual target was I was trying to hit. Thank you, thank you, thank you for creating this!