Giter Club home page Giter Club logo

mfp-keto-userscript's People

Contributors

aikar avatar cenh avatar karbassi avatar lantrix avatar surye avatar tolgaek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mfp-keto-userscript's Issues

fats not showing on daily totals pie chart

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!)

mfp-keto-user

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?

No accounting for Sugar Alcohol

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.

Numbers are still off

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!:
screen shot 2019-02-11 at 5 25 33 pm
screen shot 2019-02-07 at 1 04 25 am

Logging me off after editing/saving note in MFP

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.

Net carb graphical error

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!

mfp error

Works in FF, not in Chrome

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?

Creating a Personal Food item creates issue with Net Carbs

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.

mfp script

Additional calories - feature request

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?

The script has suddenly stopped working today

I have just reinstalled the script and reopened my browser but no joy.

Also it shows the script as installed but then says no script running. What should I do?

image

The net carbs option is not showing up on the columns:

image

Windows 10 error

Net carbs doesn't show up in MFP after Windows10 upgrade. Re-instillation didn't make any difference. What's next?

No mobile app

There is no mobile app version of this, so I'm working on one.

feature request

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!

IPhone?

Can this work on the MFP App on my iPhone?

How to resolve the negative net carb issue mentioned in FAQ

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

Stopped working on Chrome today

Script has worked for me for over a year. Stopped working today. Chrome Version 71.0.3578.98 (Official Build) (64-bit) Tried reinstall.

Net Carb in myfitness pal

I downloaded the code for google chrome on several of my computers and for some reason on my computer at work it started putting the net carb column at the front of the food diary and therefore not calculating, is there some way to fix this?
netcarb

Net Carbs not adding correctly

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:

image

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:

image

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?

Delete Widgets disappear

[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.

Version 1.16 - Net Carbs Columns Appear, But No Values (ed: NEVER MIND - found/fixed MFP problem)

I just downloaded the MyFitnessPal Percentages and Net Carbs script, today (February 8, 2019).

  1. Some of the instructions on your webpage (URL https://perfectketo.com/myfitnesspal-net-carbs/) are out-of-date due to changes on the MFP website (in particular, (a) an additional step to get to the 'Diary Settings' page in MFP, and (b) not reflecting changes to the current TamperMonkey Version 4.8 behavior when invoked from its icon in the Chrome ribbon menu). I was able to work around the missing/misguided steps.
  2. Upon installation completion, the 'Net Carbs' column appears, as expected, on the MFP 'Food Diary' page. However, the individual meal items reflect only an 'NaN' value for all items, regardless of actual NetCarb content (which causes your script to fail the if-else at line 173), and the Daily 'Totals' row in the bottom-most summary section shows a value of 0.

Script not functioning

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.

Image of issue

Confirmation I'm using latest version of script

-Aaron

Upgrade problems.

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:

screenshot_071016_034707_pm

With the script running I cannot save water consumption or food notes; also water consumption in ml won't save - shows NaN

Here's a video of the issues I'm having while the script is running: http://screencast.com/t/g5j05F4V3NL

With the script running:

  1. Water consumption in ml shows NaN
  2. I cannot save water consumption
  3. I cannot save food notes
  4. When I log in, sometimes I get a white screen with one line of text at the top (1:32 of the video)

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".

Problem calculating Net Carbs

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.

Was working until yesterday -- a few issues

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.

NaNs even with the right columns

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

Net carbs amounts are off.

Hi I'm noticing today that the net carb amounts are adding in additional amounts for items that have not been entered.

image
image

Thanks.

Script not running

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 */

/*


  • Thanks to kt123 and Wickity for the fixes.

/
/

*/

/*

  • TODO: Gracefully handle missing required columns.
    /
    /

    if (window.top !== window.self) {
    return; // do not run in frames
    }
    /
    /

    if (typeof unsafeWindow != 'undefined')
    {
    (function page_scope_runner() {
    // If we're not already running in the page, grab the full source
    // of this script.
    var my_src = "(" + page_scope_runner.caller.toString() + ")();";
    // Create a script node holding this script, plus a marker that lets us
    // know we are running in the page scope (not the Greasemonkey sandbox).
    // Note that we are intentionally not scope-wrapping here.
    var script = document.createElement('script');
    script.setAttribute("type", "application/javascript");
    script.textContent = my_src;
    document.body.appendChild(script);
    })();
    return;
    }
    */
    function exec(fn) {
    var script = document.createElement('script');
    script.setAttribute("type", "application/javascript");
    script.textContent = '(' + fn + ')();';
    document.body.appendChild(script); // run the script
    document.body.removeChild(script); // clean up
    }

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;">&nbsp;</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!

Addition of Net Carbs a Tad Off

Net carbs is showing 11g and should be 10g
screen shot 2015-09-11 at 2 40 53 pm

Net carbs is showing 18g and should be 16g. Any suggestions on how to get the correct calculations?
screen shot 2015-09-11 at 2 41 02 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.