Skip to content

Instantly share code, notes, and snippets.

@Freak613
Created July 18, 2018 04:59
Show Gist options
  • Save Freak613/1e2cd7f148ecc5e05cb3b9a90ce1541c to your computer and use it in GitHub Desktop.
Save Freak613/1e2cd7f148ecc5e05cb3b9a90ce1541c to your computer and use it in GitHub Desktop.
MealPal - Roll button
let parent = $$('[infinite-scroll]')[0]; parent.style='display: flex;';let children = [...parent.children]; parent.textContent = ""; let btn = document.createElement('button'); btn.textContent = 'Roll!';btn.style = 'background: #4992dc;border: 1px solid #75a1ce;border-radius: 5px;color: white;font-size: 40px;width: 25%;height: 356.56px;'; btn.onclick = () => {parent.children.length === 1 ? parent.appendChild(children[Math.floor((Math.random()*children.length) + 1)]) : parent.replaceChild(children[Math.floor((Math.random()*children.length) + 1)], parent.lastChild)}; parent.appendChild(btn);
@Freak613
Copy link
Author

Replaces menu list content with Roll button and by pressing - displays one random item from the list.
It's better to scroll list to the end of the page to load all items.

Helps chose when you have too many to chose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment