Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgiuffrida/3e2b97aa96558cd6d4664e3e55a59496 to your computer and use it in GitHub Desktop.
Save mgiuffrida/3e2b97aa96558cd6d4664e3e55a59496 to your computer and use it in GitHub Desktop.
heartharena.net deck tracker
function start() {
for (let el of Array.from(document.querySelectorAll('li.deckCard'))) {
el.addEventListener('click', function() {
draw(el.querySelector('span.name').textContent.toLowerCase());
});
}
}
function draw(name) {
let costReduced = false;
for (var el of Array.from(document.querySelectorAll('li.deckCard'))) {
if (el.querySelector('span.name').textContent.toLowerCase() == name.toLowerCase()) {
if (!costReduced) {
let cost = el.querySelector('span.mana').textContent;
reduceMana(parseInt(cost));
costReduced = true;
}
if (el.querySelector('span.quantity') && el.querySelector('span.quantity').textContent.length && el.querySelector('span.quantity').textContent.trim() != '1')
el.querySelector('span.quantity').remove();
else
el.remove();
}
}
}
function reduceMana(cost) {
if (cost > 7)
cost = 7;
let manaBar = document.querySelector('li[data-cost="' + cost + '"] .bar .fill');
let height = parseInt(manaBar.style.height);
if (height > 0) {
let newHeight = height - 10;
manaBar.style.height = newHeight + '%';
}
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment