Skip to content

Instantly share code, notes, and snippets.

@onatbas

onatbas/user.js Secret

Last active December 30, 2023 17:21
Show Gist options
  • Save onatbas/74a745c45a5436adc7a5aa804811f43e to your computer and use it in GitHub Desktop.
Save onatbas/74a745c45a5436adc7a5aa804811f43e to your computer and use it in GitHub Desktop.
CarbManagerPro with Tampermonkey
// ==UserScript==
// @name Carb Manager Pro
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Carb Manager Pro Features
// @author You
// @match https://my.carbmanager.com/*
// @icon https://www.google.com/s2/favicons?domain=carbmanager.com
// @grant GM_getResourceText
// ==/UserScript==
(function () {
'use strict';
var tickTime = 300;
var msgCount = 0;
var matched = false;
var bignote = false;
var superfoods = [
{ name: "Natto", search: "Natto" },
{ name: "Vitamin", search: "[vV]itamin|VITAMIN" },
{ name: "Fiber", search: "[fF]iber" },
// {name: "Nuts", search: "Mixed [Nn]ut"},
{ name: "Avocado", search: "[aA]vocado|Breakfast Cholesterol Taco" },
{ name: "Beans", search: "[bB]ean|Breakfast Cholesterol Taco" },
{ name: "Salt", search: "[sS]alt|[tT]uz" },
{ name: "Greens", search: "[sS]alata|[gG]reens|[sS]alad|^\\W+Kale\\W+$|^\\W+Lettuce\\W+$" },
{ name: "Olive Oil", search: "Pepper Avocado|[oO]live [oO]il|Cholesterol Taco|[yY]aglar" },
{ name: "Fish", search: "([fF]ish|[tT]una|[cC]od|[sS]almon|[bB]alik|[hH]addock|[bB]ream|[mM]ackerel)" },
{ name: "Yag. Unsaturated (Mono,Poly)", search: "[yY]aglar" }
];
var github = `
<div style="padding: 20px;" class="daily-card__content my-custom-notes" data-v-562ea3e6="">
<!--<p id="sporgunumu"></p>-->
<!--<b>Hatirlatmalar</b>-->
<ul><span id="superfood"></span></ul>
<b>Notlar</b>
<ul>
<li> <a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:e19718a532509572a6dbc592b348452b">Natto</a>
: Damar sagligi icin her gun bir tane.
</li>
<li>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:04f1d387030d1326647c1531d865a49a">Mixed Nuts</a>
-->
<a href="https://www.healthline.com/nutrition/8-benefits-of-nuts#TOC_TITLE_HDR_6">Because benefits</a>
</li>
<li>Beans/Legumes (
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:ug:b4228dfedd33442bbbbc6be26b7ee619">Cholesterol Taco</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:md:72a6b6445a21e6576d2095387f35cb94">Red Kidney Beans</a>
)</li>
<li>Avocado : (
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:ug:b4228dfedd33442bbbbc6be26b7ee619">Cholesterol Taco</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:ug:db958675bf544395aeb6efe45f3e56f0">Pepper Avocado</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:ug:c46683bfd3a048bca80a01134b660ef3">Garlic Bread, Egg & Avocado</a>
)</li>
<li>
Fish : (
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:8f09c2e7bdbde84baac4cf5a6cee1fea">Tuna</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:12a3942c10a919b05b7c2b94f85a4e1a">Cod</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:75330968c1de489d69f29b80cfb69a91">Salmon</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:4d689adbd0c96c3c5f3b3de4171c7f53">Bream</a>
)</li>
<li>2 gunde 1 balik mutlaka!.</li>
</ul>
<b>Shortcuts</b>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:2034621adbf63662f2b46d69e732bb6a">Coffee</a>,
<a href="https://www.bizcalcs.com/cal/Body-Fat-Navy.php">Fat%</a>
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:nb:51c36a9d97c3e69de4b07393">Lite Salt</a>,
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:nb:5d5263995561ed21067215cd">Protein Shake</a>,
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:ug:b1f1213aceba40f2a694aeb373ac4890">Protein Icecegi</a>,
<a href="https://my.carbmanager.com/daily-log?dialog=food-detail:cc:e19718a532509572a6dbc592b348452b">Natto</a>,
<a href="https://my.carbmanager.com/goals/progress?tab=WEIGHT">Kilo</a>,
<a href="https://my.carbmanager.com/goals/progress?tab=ENERC_KCAL">Kalori</a>
<ul>
<li>5000mg <a href="https://my.carbmanager.com/goals/progress?tab=NA">Sodium</a>: Cured Meats, Cheeses, Canned Tuna, Mustard, broth, table salt</li>
<li>1000mg <a href="https://my.carbmanager.com/goals/progress?tab=K">Potassium</a>: Raw spinach, Avocado, Mushrooms, Salmon, Steak, Pork loin, Lite Salt</li>
<li>300mg <a href="https://my.carbmanager.com/goals/progress?tab=MG">Magnesium</a>: Raw spinach, Avocado, Sprouts, Seaweed, Coffee, Almonds, Wild Fish</li>
</ul>
</div>
`;
var customCss = `
@media (min-width: 1200px){
.daily-card {
display: inline-block;
width: 33%;
vertical-align: top;
margin: 0px !important;
padding-left: 10px;
}
.my-custom-notes{
min-width: 33% !important;
#avisibility: hidden !important;
#aposition: absolute !important;
}
.my-custom-notes:hover{
height: auto !important;
}
.notes{
position: relative;
top: 5px;
}
.notes label, .notes label *{
height: 95% !important;
display: block;
}
.water-box-container-new{
position: relative !important;
top: -10px !important;
}
.my-custom-notes, .notes, .water-box-container-new, .daily-log-button {
margin-top: none !important;
margin: auto;
height: 200px;
display: inline-block !important;
width: 30% !important;
border: 1px solid #dfdfdf;
border-radius: 10px;
margin: 10px;
padding: 10px;
background-color: #ffffff;
vertical-align: top;
}
}
.food-nutrition{
justify-content: end !important;
}
.food-details__col--nutrition{
display: block !important;
width: 50%;
margin: 0 0 0 auto !important;
position: relative;
top: -60px;
left: -25px;
height: 0px;
//For somereason this just efects the first item..
}
.planned-item{
height: 0px;
padding: 0px !important;
}
.planned-item button{
position: relative;
top: -25px;
left: -10px;
height: 30px;
width: 280px;
padding: 5px;
}
.planned-item .q-btn__wrapper{
position: relative;
top: -10px;
height: 40px;
}
.food-item--greyed-out{
background-color: rgb(234, 255, 242) !important;
}
.food-details{
-webkit-box-flex: 0;
flex: 0;
width: 100%;
display: block !important;
}
.planned-item__hint{
font-size: 0px !important;
This food has been planned but has not yet been added to your log. Would you like to add it now?
}
.bignote{
font-size: 22px;
font-family: 'Times New Roman';
font-style: italic;
font-weight: bold;
color: #dd4444;
min-height: 100% !important;
}
.in-deapth-details{
visibility: hidden;
position: absolute;
top: 0px;
}
`;
function message(msg, priority) {
if (priority > 0)
console.log(msgCount++, msg);
}
function createElementFromHTML(htmlString) {
var div = document.createElement('div');
div.innerHTML = htmlString.trim();
return div.firstChild;
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
function getElementByXpath(xpath, parent) {
let results = [];
let query = document.evaluate(xpath, parent || document,
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0, length = query.snapshotLength; i < length; ++i) {
results.push(query.snapshotItem(i));
}
return results;
}
function process(msg, xpath, fn) {
message(msg);
var query = getElementByXpath(xpath);
for (let e = 0; e < query.length; e++) {
try {
fn(query[e]);
} catch (error) {
message(error, 10);
}
}
}
function processDisabled(msg, xpath,fn){
message("This piece is disabled: " +msg);
}
function execute() {
//Your code here...
message("**********************");
// getElementByXpath('//*[@id="content"]/div[1]/div/div[1]/nav/div/div[1]/ul/li[2]').innerHTML = "";
// getElementByXpath('//*[@id="content"]/div[1]/div/div[1]/nav/div/div[1]/ul/li[3]').innerHTML = "";
// getElementByXpath('//*[@id="content"]/div[1]/div/div[1]/nav/div/div[1]/ul/li[5]').innerHTML = "";
// getElementByXpath('//*[@id="content"]/div[1]/div/div[1]/nav/div/div[1]/ul/li[6]').innerHTML = "";
// getElementByXpath('//*[@id="content"]/div[1]/div/div[1]/nav/div/div[1]/ul/li[7]').innerHTML = "";
//==============================================================================================
processDisabled("Remove premium components...",
'//*[@class="premium-component__wrapper"]',
e => e.remove());
//==============================================================================================
processDisabled("Remove premium component slots......",
'//*[@class="premium-component__slot"]',
e => {
e.parentNode.classList.remove("premium-component--disable");
e.style = e.style.filter = "";
});
//==============================================================================================
process("Remove time button, after clicking it...",
'//*[contains(@class, "food-serving-form__clear-button")]',
e => {
e.click();
e.remove();
});
//==============================================================================================
process("Remove recipe image size restrictions......",
'//*[@class="recipe-step__fig"]',
e => {
e.classList.remove("recipe-step__fig");
e.style = "max-width: 500px;"
});
//==============================================================================================
processDisabled("Enable all disabled stuff...",
'//*[@disabled]',
e => e.removeAttribute('disabled'));
//==============================================================================================
process("Make models bigger.",
'//*[contains(@class, "cm-modal__inner")]',
e => e.style = "min-width: 80%;");
//==============================================================================================
process("Open Advanced Settings..",
'//*[contains(text(), "Show Advanced")]',
e => e.click());
//==============================================================================================
process("Turn Log food to Plan food.",
'//span[contains(text(), "Log Food")]', e => {
e.parentNode.click();
process("", '//div[contains(text(), "Plan Food")]',
f => f.click());
})
//==============================================================================================
process("Turn actual to planned...",
'//span[contains(text(), "Actual")]', e => {
e.parentNode.click();
process("", '//div[contains(text(), "Planned")]',
f => f.click());
});
/* process("Turn net values to consumed...",
'//span[contains(text(), "Net Values")]', e => {
e.parentNode.click();
process("", '//div[contains(text(), "Consumed")]',
f => f.click());
});
*/
//==============================================================================================
processDisabled("Remove unnecessary stuff...",
'//*[contains(@class, "premiumCta")]',
e => e.remove());
//==============================================================================================
process("Remove Carb manager widget...",
'//h3[contains(text(), "Join the Carb Manager Challenge Today!")]',
e => e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.remove());
//==============================================================================================
process("Remove daily log..",
'//section[contains(@class, "daily-log__section--log-buttons")]',
e => e.remove());
//==============================================================================================
process("Daily Steps",
'//*[contains(@class, "daily-steps")]',
e => e.remove());
//==============================================================================================
process("Exercise List",
'//*[contains(@class, "exercise-list__box")]',
e => e.remove());
//==============================================================================================
process("Delete in depth details", '//*[contains(@class, "in-depth-details")]',
e => e.remove()
);
//==============================================================================================
process("Add exercise",
'//*[contains(@class, "add-exercise")]',
e => e.remove());
//==============================================================================================
message("Reposition water-box");
var query = getElementByXpath('//*[contains(@class, "water-box-container-new")]');
if (query.length == 0) {
var insertInto = getElementByXpath('//*[contains(@class, "daily-log__meal-card")]');
if (insertInto.length > 0) {
insertInto = insertInto[0];
var toBeInserted = 0;
toBeInserted = getElementByXpath('//*[contains(@class, "daily-log-completed")]')[0];
insertInto.insertBefore(toBeInserted, insertInto.firstChild);
var aside = getElementByXpath('//aside')[0];
toBeInserted = aside.childNodes;
for (let e = toBeInserted.length - 1; e > 0; e--) {
insertInto.insertBefore(toBeInserted[e], insertInto.firstChild);
};
toBeInserted = getElementByXpath('//*[contains(@class, "water-box")]')[0].parentNode.parentNode;
insertInto.insertBefore(toBeInserted, insertInto.firstChild);
aside.parentNode.removeChild(aside);
toBeInserted.classList.add("water-box-container-new");
}
}
//==============================================================================================
processDisabled("Close Flash Sale Popup..");
if (getElementByXpath('//*[contains(@class, "paywall-dialog--orange")]').length > 0 ||
getElementByXpath('//*[contains(@class, "paywall--wave-puddle")]').length > 0) {
getElementByXpath('//*[contains(@class, "cm-modal-bar__cross-icon")]')[0].parentNode.click();
}
processDisabled("Close the new version of paywall");
if (getElementByXpath('//*[contains(@class, "paywall-content")]').length > 0) {
getElementByXpath('//*[contains(@class, "paywall__btn-close__icon-cross")]')[0].parentNode.click();
}
//==============================================================================================
processDisabled("Is it sports day? Disabled", '//*[@id="sporgunumu"]', e => {
var gun = (new Date()).getDay();
var exercised = getElementByXpath('//textarea').filter(textarea => textarea.value.match(/[sS]por [tT]amam/)).length;
if (!exercised) {
e.style = "padding: 20px; font-size: 30px; border: 1px solid red; border-radius: 8px; text-align: center;";
e.innerHTML = "🙇UTAN KENDINDEN SPOR YAP SISKO!.🛋️";
}
else {
e.style = "padding: 20px; font-size: 20px; border: 1px solid green; border-radius: 8px; text-align: center;";
e.innerHTML = "🏋️🧘‍♂️DINLENMEYI HAKET 🥦🧈🥩";
}
switch (gun) {
case 8:
//case 2: case 3: case 5: case 6:
e.innerHTML = "🏋️💥Freeletics day.. 🥵🔥";
break;
}
});
//==============================================================================================
process("Make notes bigger..", '//textarea', e => {
if (!e.edited) {
e.classList.add("bignote");
}
});
//==============================================================================================
/*
process("Make a container in the top.", '//*[contains(@class, "swiper-wrapper")]', swipeContainer => {
var testElement = '<div data-v-b9851d26="" data-v-0ec74468="" class="swiper-slide" data-v-a77e3c0e="" role="group" aria-label="2 / 3" style="width: 475px; margin-right: 24px;"><div data-v-ac55e7c2="" data-v-67a866ae="" data-v-0ec74468="" class="chart-card" data-v-b9851d26=""><div data-v-7e987c62="" data-v-ac55e7c2="" class="stretched-card chart-card__bg stretched-card__slide"><div data-v-ac55e7c2="" data-v-7e987c62="" class="chart-card__wrapper"><div data-v-67a866ae="" data-v-7e987c62="" class="slider__body"><h1>Hello World</h1></div></div></div></div></div>';
if (!swipeContainer.edited) {
swipeContainer.edited = true;
swipeContainer.insertBefore(createElementFromHTML(testElement), swipeContainer.childNodes[0]);
}
});
*/
//==============================================================================================
message("Add my custom notes..");
if (getElementByXpath('//*[contains(@class, "my-custom-notes")]').length == 0) {
var waterBox = getElementByXpath('//*[contains(@class, "daily-notes-button__icon")]');
console.log("waterBox.length : " + waterBox.length);
if (waterBox.length > 0) {
waterBox = waterBox[0].parentNode;
var instruction = github;//GM_getResourceText("github");//.split("\n")[1].replace(/^document.write\('/, "").replace(/.\)$/, "").replaceAll(/\\n/g, "").replaceAll(/\\/g, "");
var node = createElementFromHTML(instruction);
console.log(createElementFromHTML(instruction));
node.appendChild(createElementFromHTML(instruction));
waterBox.parentNode.insertBefore(createElementFromHTML(instruction), waterBox);
var actualWater = getElementByXpath('//*[contains(@class, "water-box-container-new")]')[0];
waterBox.parentNode.insertBefore(actualWater, waterBox);
}
};
//==============================================================================================
process("Superfood kontrol", '//span[@id="superfood"]', e => {
function findSuperfoods(superfoodContainer) {
var capturedInTextArea = getElementByXpath('//textarea').filter(textarea => textarea.value.match(new RegExp("(" + superfoodContainer.name + "|" + superfoodContainer.search + ") [tT]amam")));
var capturedInFoods = getElementByXpath('//*[@class="food-name"]').filter(textarea => textarea.innerHTML.match(new RegExp(superfoodContainer.search)));
if (capturedInTextArea.length > 0)
return capturedInTextArea;
console.log(superfoodContainer.name);
console.log(capturedInFoods);
return capturedInFoods;
}
var planPass = getElementByXpath('//textarea').filter(textarea => textarea.value.match(/[Ss]uper(food)?(lar)?(ler)? [tT]amam/)).length > 0;
if (planPass) {
e.innerHTML = "✅";
} else {
e.innerHTML = "";
superfoods.forEach(superfoodContainer => {
e.innerHTML += findSuperfoods(superfoodContainer).length == 0 ?
("<li>" + "❌" + superfoodContainer.name + "</li>") : "";
// ("<li>" + "✅" + superfoodContainer.name + "</li>");
});
if (e.innerHTML.length == 0) {
e.innerHTML = "<h3 style=\"color: #ff0000;\">SUPER GUN!</h3>";
}
}
});
//==============================================================================================
}
function loop() {
msgCount = 0;
setTimeout(loop, tickTime);
try {
execute();
} catch (e) { console.log(e) };
}
document.documentElement.style.setProperty('--app-container-width', '100%');
addGlobalStyle(customCss);
loop();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment