surye / mfp-keto-userscript Goto Github PK
View Code? Open in Web Editor NEWMyFitnessPal Keto Script
MyFitnessPal Keto Script
I get this message: Daily Totals by Calories (This is whatyou use for your macro ratios)Net CarbsProtein9%
but no fats showing.
Running this in FireFox and using version1.10.
Any help for a complete beginner would be appreciated (I didn't even know this was possible!)
I've put my food plan for today, and i got this :
http://i.imgur.com/XH8B3Zr.png
or you can see it on my myfitnesspal (same nickname) for today.
I tried to install the mfp-keto-userscript on my laptop. It appears to have installed yet I cannot see anything new (no pie chart, etc.) I am not paying for MFP. Did I do something wrong?
This might be unavoidable, but it doesn't seem like this takes into account the amount of sugar alcohol in the foods against the net carb count.
Hi, I installed the updated script and now I am getting a 6% daily goal for net carbs, when it is set on MFP to 5%. The net carb totals are incorrect, also -- so far today I've had 21 g fiber, 22 g carbs, so it should read 1 net carb but says I had 4 net carbs.
Just to test things a bit, I set my carb goals to 0%, and net carb goals came back as 1% -- so it was still 1% off. I set it back to 5%, and it reads a 6% goal.
Here are the screen shots, thanks in advance for your reply!:
When I have this enabled on MyFitnessPal, I get logged off after saving a food note in the diary. If I click "edit note" and click "save note," then the next thing I click on (anything from going to the next day to adding a new food entry) logs me off and sends me to the login screen. Once I log back in, I'm redirected to the link I clicked on (food diary or the next day). I am testing this in Chrome and I don't have the issue when I disable the script, but as soon as I re-enable it, I am having the logging off issue.
Hi, I installed the mfpketo.user.js and there are a number of "not running" yellow triangles in the script. Does anyone have a solution, please? Thanks!
MFP Premium changes have disabled this script from working.
Great script! Works great on the daily diary, however, as I precook 90+% of my meals, all my number crunching happens when creating recipes.
Could this script be expanded to perform identically on that page also?
Some days, seemingly randomly, my net carbs appear to have an erroneous "1" in their field despite not eating that particular meal. The working-as-intended model should probably be the "0" I see otherwise. The "1"s are subtracted somewhere in the backend so it appears to be a wholly graphical issue. Tried uninstalling/reinstalling/updating/etc. Screenshot attached. Thanks!
I'm not sure what I'm doing wrong, if anything, but I cannot get this script to work in Chrome. Set it up in Firefox using Greasemonkey with zero issues. Halp?
Hello, the daily goal is showing 50% carbs 30% fat, and 20% protein no matter how I change it on the website. The food log will always show these percentages.
I added a personal food in MFP with all the nutrition facts, but when I add it to my diary, the script seems to add the amount of Daily Fiber into my Net Carbs daily goal amount. My Net Carb daily goal is 16, but when I add my food item, the goals shoots up to 31, and the only math that adds up is that it's taking the Dietary Fiber in my food and adding it to the daily goal in Net Carbs. Thank you for looking into this!
PS - I should mention that I have messed around with different combinations on my personal food to the same results, i.e. there are really 19g of carbs and 15g of fiber (for 4g of Net Carbs), but same results.
There is currently a paid-for option with MFP to include your workout calories as a deficit to your overall calories. Would there be a way to add these using this script?
Net carbs doesn't show up in MFP after Windows10 upgrade. Re-instillation didn't make any difference. What's next?
Thanks for the script.
Great to have the saturated fat macro column with a percentage total value added.
There is no mobile app version of this, so I'm working on one.
This is great, and I'd like to be able to apply it to the printable diary (http_://www.myfitnesspal.com/reports/printable_diary/_). Unfortunately, adding that page as an include just breaks the page. Could you make it so that this handles the reports as well?
Thanks!
Can this work on the MFP App on my iPhone?
The reason for negative net carb is because many of the food labels already shows net carb, like in Europe, and this is a big problem for users because of the inconsistency - some food labels shows total carbs, where some shows net carbs.
There's a simple way to correct this.
The code can put in a simple logic, that if negative carbs are found, then simply disregard the calculated amount and use the original number of the carb as net carb. Problem solved.
This will make the script much more popular
The net carb show NAN and i dont see anything extra other then that
https://ibb.co/yWHXttK
Script has worked for me for over a year. Stopped working today. Chrome Version 71.0.3578.98 (Official Build) (64-bit) Tried reinstall.
Diary:
http://www.myfitnesspal.com/food/diary/lohikaarme_vaeltaja
http://www.myfitnesspal.com/food/diary/lohikaarme_vaeltaja?date=2017-08-28
See the Mocha Chip entry
http://www.myfitnesspal.com/food/diary/lohikaarme_vaeltaja?date=2017-08-24
Similar issue here with the Simple Truth ice cream
having major problems with layout issues on both chrome and safari in Mac.
See attached image:
The script still works great for displaying. Unfortunately, macro goals can no longer be set in single digit increments.
A few others have noticed that sometimes the Net Carbs total is incorrect. In the total row, it is calculating the Total Net Carbs as TNC = Total Carbs - Total Fibre:
But, as you can see from the image, this results in a negative value, which is obviously wrong.
I think a better calculation would be to simply sum the meal totals for Net Carbs:
This would also tally with the remaining value (5 in my image).
Daily Goal = 19
Net Carbs = 12 + 2 = 14
Remaining = 5
Can the script be updated to calculate the Total Net Carbs this way?
In README.md you suggest installing Greasemonkey for Firefox but it is not compatible with Firefox 57 and above. Please add a not to say that for v57 and above people should install Tampermonkey from https://addons.mozilla.org/firefox/addon/tampermonkey/.
[FIXME] When enabled the final table column in the Food Diary view () disappears. In order to delete a food entry, the script must be toggled off, refresh page (if auto-refresh isn't on), delete item, toggle script back on.
I just downloaded the MyFitnessPal Percentages and Net Carbs script, today (February 8, 2019).
Previously, I've enjoyed using this script for MyFitnessPal. It's great!
Recently tried logging my food and noticed that there is no longer a Net Carbs column! Additionally, MyFitnessPal no longer seems to be tracking % macros.
I confirmed that I am running the updated version of the script, yet am still experiencing this issue. See the picture below.
Confirmation I'm using latest version of script
-Aaron
There is almost certainly something very basic I'm missing - but I have not been able to upgrade to the most recent version to fix the migrating and empty net carbs column.
The readme file directs me to, "Just visit https://github.com/Surye/mfp-keto-userscript/raw/master/mfpketo.user.js and click Upgrade." Unfortunately when I follow the link, there is no "Upgrade" on that page to click. I tried Reinstall (an option that is present) without success. Post re-installing, it operates the same as before (with the Net carbs column ahead of the food item, filled with NaN. I'm using Chrome - and it was working like a charm before the recent MFP changes.
I miss my Net Carbs column (that was working perfectly until MFP broke it). thanks for any guidance you can provide!
ETA: I have done a bit more exploration. It appears I have the most recent version (1.9) installed, based on the update 19 days ago.
I'm still getting this:
Here's a video of the issues I'm having while the script is running: http://screencast.com/t/g5j05F4V3NL
With the script running:
Note at 1:10 of the video I change the water consumption to 200 ml and the food note to "test2" and it looks like it saved but when I log out and log back in at 2:03 of the video it shows water consumption as 850 ml and the food note as "test".
Just noticing today the plug-in is not calculating the Net Carbs properly. I have entered food with 9g Total Carbs and 4g Dietary fiber. The "Net Carbs" column is showing up, but it is displaying 9g for the value, when usually it would show 5g in this case.
It's stating that my net carb goal is 10% when it's actually set at 5% on MyFitnessPal. I tried re-setting the settings. On my computer, I use the site online, so it's not an app issue.
I have consumed 17 grams of fiber today and 18 grams of carbs -- my net carbs are totaled at 13 when they should be at 1, and my daily goal is stating 10% at 31 grams, when it is set to 14 grams at 5% on MyFitnessPal.
Anyway, the numbers are off. It had been working perfectly until yesterday. I hope this can be fixed, I love using this script!!!!
Thank you.
Terrific script, I learned about it a year ago from http://cavemanketo.com/configuring-mfp/ and had been using it actively for 6 months until an injury set me back. Coming back to it, I noticed when I'm logging food in My Fitness Pal, that all my Net Carbs entries say "NaN." I double checked that I had the right columns and I do – Carbs, Fiber, Fat, Protein, and Potassium.
Maybe there is some change they made at MFP that has interfered with this script?
Apologies if this is already a known issue. I'm new to Github. –Aaron
I am writing to report that when the calculations of total net carbs are done at the bottom, they arent calculating the total correctly. Total Net Carbs seem to be missing a few items.
I'm trying to install the MyFitnessPal net carbs script, but I cannot get it to run. I followed all the troubleshooting steps, including recreating the userscript, but it's not working. I also logged out and logged back in several times. I do have some warnings in the script, such as "'google' is not defined". I also have one error, "'carbs' is already defined". I did notice that the URL goes to https, not http as defined in the code. I did try making this adjustment in the script, but it didn't resolve. For reference, here is the latest userscript I created:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @Version 0.1
// @description try to take over the world!
// @author You
// @match http://www.myfitnesspal.com/account/diary_settings
// @grant none
// ==/UserScript==
(function() {
'use strict';
// ==UserScript==
// @name MyFitnessPal Percentages and Net Carbs
// @Version 1.14
// @namespace surye
// @description Adds display of Carb/Protein/Fat percentages to any daily food diary page. Also adds "Real Calories" calcalation based off 4/4/9 algorithm. Based on "MyFitnessPal Percentages and Net Carbs"
// @downloadurl https://github.com/Surye/mfp-keto-userscript/raw/master/mfpketo.user.js
// @include http*://www.myfitnesspal.com/food/diary*
// ==/UserScript==
/* side note - 5/30/65 Carbs/Protein/Fat is a good ratio for fat loss */
/*
/
/
*/
/*
function startRun() {
var script = document.createElement("script");
script.setAttribute("src", "//www.google.com/jsapi");
script.addEventListener('load', function() {
exec(jsapiLoaded);
}, false);
document.body.appendChild(script);
script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js");
script.addEventListener('load', function() {
exec("jQuery.noConflict()");
}, false);
document.body.appendChild(script);
script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = main;
document.body.appendChild(script);
}
startRun();
function jsapiLoaded() {
google.load("visualization", "1", { packages: ["corechart"], "callback": main });
}
function main() {
var calories_i = 0;
var net_carbs_i = 0;
var carbs_i = 0;
var fiber_i = 0;
var protein_i = 0;
var fat_i = 0;
var daily_total_carbs = 0;
var daily_total_protein = 0;
var daily_total_fat = 0;
var net_carb_total = 0;
var net_carb_total_goal = 0;
var header_tr_element = jQuery('.food_container tr.meal_header:first');
var elem_i = 0;
header_tr_element.find('td').each(function() {
var myval = jQuery(this).text().toLowerCase().trim();
if (myval.indexOf('calories') !== -1) { calories_i = elem_i; }
if (myval.indexOf('carbs') !== -1) { carbs_i = elem_i; }
if (myval.indexOf('fiber') !== -1) { fiber_i = elem_i; }
if (myval.indexOf('fat') !== -1) { fat_i = elem_i; }
if (myval.indexOf('protein') !== -1) { protein_i = elem_i; }
elem_i += 1;
});
// Add new column for net carbs
var net_carb_tr_elements = jQuery('tr');
net_carb_tr_elements.each(function() {
var tds = jQuery(this).find('td');
jQuery('<td></td>').insertBefore(tds.eq(carbs_i));
});
// Recalculate offsets
net_carbs_i = carbs_i;
calories_i = calories_i >= net_carbs_i ? calories_i + 1 : calories_i;
carbs_i = carbs_i >= net_carbs_i ? carbs_i + 1 : carbs_i;
fiber_i = fiber_i >= net_carbs_i ? fiber_i + 1 : fiber_i;
protein_i = protein_i >= net_carbs_i ? protein_i + 1 : protein_i;
fat_i = fat_i >= net_carbs_i ? fat_i + 1 : fat_i;
// Set header
header_tr_element.find('td').eq(net_carbs_i).text("Net Carbs");
header_tr_element.find('td').eq(net_carbs_i).addClass("alt");
header_tr_element.find('td').eq(net_carbs_i).addClass("nutrient-column");
// Change to say net carbs
var footer_tr_element = jQuery('tfoot tr');
footer_tr_element.find('td').eq(net_carbs_i).text("Net Carbs");
footer_tr_element.find('td').eq(net_carbs_i).addClass("alt");
header_tr_element.find('td').eq(net_carbs_i).addClass("nutrient-column");
var alreadyCountedFiber = [0];
var alreadyCountedFiberIdx = 0;
var food_tr_elements = jQuery('tr');
food_tr_elements.each(function() {
if($(this).hasClass('bottom')) {
alreadyCountedFiberIdx++;
alreadyCountedFiber[alreadyCountedFiberIdx] = 0;
}
var tds = jQuery(this).find('td');
var carbs = parseFloat(tds.eq(carbs_i).text());
var fiber = parseFloat(tds.eq(fiber_i).text());
//fiber = parseInt(fiber);
//cals = parseInt(cals);
// Find only food rows!
var delete_td = tds.eq(tds.length - 1);
if (delete_td.hasClass('delete')) {
var name = jQuery(this).find('.js-show-edit-food').text().toLowerCase();
tds.eq(net_carbs_i).text(carbs - fiber);
if (name.indexOf("net carbs") !== -1 || (carbs - fiber) < 0) {
alreadyCountedFiber[alreadyCountedFiberIdx] += Number(fiber);
tds.eq(net_carbs_i).text(carbs);
}
}
});
totalAlreadyCountedFiber = 0;
for (var i=0; i < alreadyCountedFiber.length; i++){ totalAlreadyCountedFiber += alreadyCountedFiber[i];}
var bottom_tr_elements = jQuery('.food_container tr.bottom, .food_container tr.total');
var meal_idx = 0;
bottom_tr_elements.each(function() {
if (jQuery(this).hasClass('remaining')) {
return false; /* continue */
}
var tds = jQuery(this).find('td');
var cals = parseFloat(tds.eq(calories_i).text());
if($(this).hasClass('bottom')) {
var carbs = parseFloat(tds.eq(carbs_i).text()) + alreadyCountedFiber[meal_idx];
} else {
var carbs = parseFloat(tds.eq(carbs_i).text());
}
var fiber = parseFloat(tds.eq(fiber_i).text());
var protein = parseFloat(tds.eq(protein_i).text());
var fat = parseFloat(tds.eq(fat_i).text());
var net_carbs = carbs;
// HACK to show net carbs
if (!jQuery(this).hasClass('alt')) {
net_carbs = carbs - fiber;
if (!isNaN(net_carbs)) {
tds.eq(net_carbs_i).text(net_carbs);
} else if (jQuery(this).hasClass("total")) {
tds.eq(net_carbs_i).text("0");
}
} else {
// record goal
net_carb_total_goal = net_carbs - totalAlreadyCountedFiber;
}
/* do nothing if cannot calculate for the row */
if (isNaN(cals) ||
isNaN(carbs) ||
isNaN(protein) ||
isNaN(fat) ||
isNaN(fiber) ||
isNaN(net_carbs) ||
cals === 0) {
meal_idx++;
return true;
}
tds.eq(net_carbs_i).text(net_carbs);
// if (net_carbs == 0 &&
// protein == 0 &&
// fat == 0) {
// return true;
// }
var carb_cals = (net_carbs * 4);
var protein_cals = (protein * 4);
var fat_cals = (fat * 9);
if (jQuery(this).hasClass('total') &&
!jQuery(this).hasClass('alt') &&
daily_total_carbs === 0) {
daily_total_carbs = carb_cals;
daily_total_protein = protein_cals;
daily_total_fat = fat_cals;
net_carb_total = net_carbs - totalAlreadyCountedFiber;
}
var real_cals = carb_cals + protein_cals + fat_cals;
var carb_pct = ((carb_cals / real_cals) * 100).toFixed(2);
var fat_pct = ((fat_cals / real_cals) * 100).toFixed(2);
var protein_pct = ((protein_cals / real_cals) * 100).toFixed(2);
//alert(daily_total_carbs + ", " + daily_total_protein + ", " + daily_total_fat + ", " + net_carb_total);
carb_pct = Math.round(carb_pct);
fat_pct = Math.round(fat_pct);
protein_pct = Math.round(protein_pct);
tds.each(function() {
jQuery(this).append('<div class="myfp_us" style="color:#0a0;font-size:9px;text-align:center;"> </div>');
});
tds.eq(0).find('div.myfp_us').html("");
/*tds.eq(calories_i).find('div.myfp_us').html(real_cals);*/
if (!isNaN(carb_pct)) {
tds.eq(net_carbs_i).find('div.myfp_us').html(carb_pct + "%");
}
if (!isNaN(fat_pct)) {
tds.eq(fat_i).find('div.myfp_us').html(fat_pct + "%");
}
if (!isNaN(protein_pct)) {
tds.eq(protein_i).find('div.myfp_us').html(protein_pct + "%");
}
meal_idx++;
});
var remaining_tr_elements = jQuery('.food_container tr.total.remaining');
remaining_tr_elements.each(function() {
// Show remaining as net carbs
var net_carbs = net_carb_total_goal - net_carb_total - totalAlreadyCountedFiber;
var tds = jQuery(this).find('td');
tds.eq(net_carbs_i).text(parseInt(net_carbs));
// Fix color
tds.eq(net_carbs_i).removeClass("positive");
tds.eq(net_carbs_i).removeClass("negative");
if (net_carbs < 0) {
tds.eq(net_carbs_i).addClass("negative");
} else {
tds.eq(net_carbs_i).addClass("positive");
}
});
if (daily_total_carbs !== 0 ||
daily_total_protein !== 0 ||
daily_total_fat !== 0) {
jQuery('.food_container').append('<div id="google_graph_1"></div>');
var data1 = new google.visualization.DataTable();
data1.addColumn('string', 'Type');
data1.addColumn('number', 'Cals');
data1.addRows(
[
['Net Carbs', daily_total_carbs],
['Protein', daily_total_protein],
['Fat', daily_total_fat]
]
);
var chart = new google.visualization.PieChart(document.getElementById('google_graph_1'));
chart.draw(data1, {
width: 350,
height: 300,
title: 'Daily Totals by Calories (This is what you use for your macro ratios)'
});
document.getElementById('google_graph_1').style.cssFloat = "left";
jQuery('.food_container').append('<div id="google_graph_2"></div>');
var carb_grams = daily_total_carbs / 4;
var pro_grams = daily_total_protein / 4;
var fat_grams = daily_total_fat / 9;
var data2 = new google.visualization.DataTable();
data2.addColumn('string', 'Type');
data2.addColumn('number', 'Grams');
data2.addRows(
[
['Net Carbs (' + carb_grams + 'g)', carb_grams],
['Protein (' + pro_grams + 'g)', pro_grams],
['Fat (' + fat_grams + 'g)', fat_grams]
]
);
var chart2 = new google.visualization.PieChart(document.getElementById('google_graph_2'));
chart2.draw(data2, {
width: 350,
height: 300,
title: 'Daily Totals by Grams'
});
document.getElementById('google_graph_2').style.cssFloat = "right";
}
}
})();
Any advice would be appreciated. Thanks!
see link. Net Carbs: Remaining should be Your Daily Goal: Carbs minus Total: Net Carbs right?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.