- Nainstalujte rozšíření co vám umožní vkládat JavaScript do stránek (např. https://chromewebstore.google.com/detail/nbhcbdghjpllgmfilhnhkllmkecfmpld)
- Nahrajte script (
kt-zs.js
) skrze editor rozšíření. Script by měl být vkládaný do URLshttps://www.kaloricketabulky.cz/*
- Na stránce https://moje.zdravestravovani.cz/jidelnicky/ zkopírujte vše od začátku názvu jídla až po jeho hodnoty
- Na stránce https://www.kaloricketabulky.cz/user/diary byste měli vidět nová tlačítka (vedle tlačítka pro přidání jídla). Klikněte na tlačítko pro správný čas/typ jídla.
- Pokud vše fungovalo správně, jídlo by se mělo ihned samo zapsat.
Last active
February 24, 2025 19:15
-
-
Save grongor/1df0d1fbec57fa8bb56bb61bc4d54573 to your computer and use it in GitHub Desktop.
Uživatelský JS script pro kaloricketabulky.cz. Přidává tlačítko pro rychlé přidání jídla z jídelníčku zdravestravovani.cz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
const added = mutation.addedNodes; | |
if (added.length != 1) { | |
return; | |
} | |
added[0].childNodes.forEach(function(btn) { | |
if (btn.nodeName != 'MD-ICON' || btn.innerHTML.trim() != "add_circle") { | |
return; | |
} | |
const clone = btn.cloneNode(true); | |
clone.innerHTML = "playlist_add_check"; | |
clone.style.paddingLeft = "5px"; | |
clone.onclick = onclick_handler; | |
btn.insertAdjacentElement("afterend", clone); | |
}); | |
}); | |
}); | |
observer.observe(document.querySelector('html'), { subtree: true, childList: true}); | |
var parsed_values = null; | |
const dialog_observer = new MutationObserver(dialog_handler); | |
async function onclick_handler(event) { | |
const clipboard = await navigator.clipboard.readText(); | |
const parsed = clipboard.trim().split("\n").map(l => l.trim()).filter(l => l != ""); | |
if (parsed.length != 5) { | |
alert("Failed to parse clipboard; got:\n" + parsed.toString()); | |
return; | |
} | |
parsed_values = parsed; | |
dialog_observer.disconnect(); | |
dialog_observer.observe(document.querySelector('body'), { childList: true }); | |
event.target.previousSibling.click(); | |
} | |
function dialog_handler(mutations) { | |
for (var i = 0; i < mutations.length; ++i) { | |
const added = mutations[i].addedNodes; | |
if (added.length != 1 || !added[0].classList.contains("md-dialog-container")) { | |
continue; | |
} | |
const custom_button = added[0].querySelector("[ng-click='custom()']"); | |
if (custom_button != null) { | |
custom_button.click(); | |
return; | |
} | |
const checkbox = added[0].querySelector("md-checkbox[ng-model='addFoodstuffForm.detailValues']"); | |
if (checkbox == null) { | |
return; | |
} | |
checkbox.click(); | |
dialog_observer.disconnect(); | |
fill_custom_form(added[0]); | |
return; | |
} | |
} | |
function fill_custom_form(form) { | |
const selectors = [ | |
"input[ng-model='addFoodstuffForm.title']", | |
"input[ng-model='addFoodstuffForm.energy']", | |
"input[ng-model='addFoodstuffForm.protein']", | |
"input[ng-model='addFoodstuffForm.carbohydrate']", | |
"input[ng-model='addFoodstuffForm.fat']", | |
]; | |
const values = [parsed_values[0], ...parsed_values.slice(1).map(n => n.replaceAll(/\s+/g, ''))]; | |
for (var i = 0; i < selectors.length; ++i) { | |
const input = form.querySelector(selectors[i]); | |
input.value = values[i]; | |
input.dispatchEvent(new Event('input', { bubbles: true })); | |
} | |
form.querySelector("button.p-button-primary").click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ignore this - used to upload the image 😂
