malwilley / VirginPulse

// ==UserScript==
// @name         VirginPulse
// @version      0.2.8
// @description  Automatically gets all your daily points
// @author       Malachi Willey
// @match        https://app.member.virginpulse.com/*
// @match        https://zipongo.com/*
// @match        http://www.myfitnesspal.com/*
// @grant        none
// @require      https://code.jquery.com/jquery-2.2.4.min.js
// ==/UserScript==

(function() {
    'use strict';

    console.log("Begin Tampermonkey script");

    var executeWhenExists = function (selector, numElements, action) {
        var check = setInterval(function() {
            if ($(selector).length >= numElements) {
                action();
                clearInterval(check);
            }
        }, 200);
    };

    if (location.hostname == "app.member.virginpulse.com") {
        $(window).bind("load", function() {
            executeWhenExists(".got-it-core-button", 2, function() {
                console.log("Clicking 'check it out' buttons");
                $(".got-it-core-button").click();
                executeWhenExists(".btn-choice-yes", 3, function() {
                    console.log("Clicking 'yes' buttons");
                    $(".btn-choice-yes").click();
                    $('.mood-icon-button5').click();
                    $(".modal-backdrop").hide();
                    executeWhenExists("#healthyhabits-weightinput", 1, function() {
                        console.log("Setting weight to 170");
                        var scope = angular.element($("#healthyhabits-weightinput")).scope();
                        scope.$apply(function() {
                            scope.activity.weight = 170;
                        });
                        $('.btn-tracker').click();

                        window.location.href = "https://member.virginpulse.com/devices/zipongosso";


                    });
                });
            });
        });
    } else if (location.hostname == "zipongo.com") {
        $(window).bind("load", function() {
            var recipes = "recipes";
            if (location.pathname == "/home") {
                executeWhenExists(".recipe-widget-background", 1, function() {
                    $(".recipe-widget-background")[0].click();
                });
            }
            if (location.pathname.indexOf(recipes) > -1) {
                executeWhenExists("[data-reactid='.0.4.2.1.0.0.3.3']", 1, function() {
                    $(".favorite").click(); // favorite
                    $("[data-reactid='.0.4.2.1.0.0.3.3']").click(); // add to grocery list
                    console.log("clicked the add to recipe button");
                    executeWhenExists(".gl-button-green", 1, function() {
                        $(".gl-button-green").click(); 

                        setTimeout(function() {
                            window.location.href = "http://www.myfitnesspal.com/food/add_to_diary?meal=0";
                        }, 500);
                    });
                });
            }

        });
    } else if (location.hostname == "www.myfitnesspal.com") {
        // if not add to diary or login
        $(window).bind("load", function() {
            executeWhenExists("input[type='checkbox']", 1, function() {
                for (var i = 0; i < $("input[type='checkbox']").length; i++) {
                    $("input[type='checkbox']")[i].checked = true;
                }
                $("#add_button_en").click();

            });
        });
    }

})();