// TODO: Refactor this ugly shit who wrote this lmao function vote(type, id, dir) { const upvotes = document.getElementsByClassName(type + '-' + id + '-up'); const downvotes = document.getElementsByClassName(type + '-' + id + '-down'); const scoretexts = document.getElementsByClassName(type + '-score-' + id); for (let i=0; i= price && kind != "grass") buy1.disabled=false; else buy1.disabled=true; const buy2 = document.getElementById('buy2') if (coins >= price && kind != "benefactor") buy2.disabled=false; else buy2.disabled=true; let ownednum = Number(document.getElementById(`${kind}-owned`).textContent); document.getElementById('giveaward').disabled = (ownednum == 0); document.getElementById('kind').value=kind; if (document.getElementsByClassName('picked').length > 0) { document.getElementsByClassName('picked')[0].classList.toggle('picked'); } document.getElementById(kind).classList.toggle('picked') if (kind == "flairlock") { document.getElementById('notelabel').innerHTML = "New flair:"; document.getElementById('note').placeholder = "Insert new flair here, or leave empty to add 1 day to the duration of the current flair. 100 characters max."; document.getElementById('note').maxLength = 100; } else { document.getElementById('notelabel').innerHTML = "Note (optional):"; document.getElementById('note').placeholder = "Note to include in award notification"; document.getElementById('note').maxLength = 200; } } function buy(mb) { const kind = document.getElementById('kind').value; url = `/buy/${kind}` if (mb) url += "?mb=true" const xhr = createXhrWithFormKey(url); xhr[0].onload = function() { let data try {data = JSON.parse(xhr[0].response)} catch(e) {console.error(e)} success = xhr[0].status >= 200 && xhr[0].status < 300; showToast(success, getMessageFromJsonData(success, data), true); if (success) { if (kind != "lootbox") { document.getElementById('giveaward').disabled=false; let owned = document.getElementById(`${kind}-owned`) let ownednum = Number(owned.textContent) + 1; owned.textContent = ownednum } const currency = mb ? "bux" : "coins"; document.getElementById(`user-${currency}-amount`).innerText = parseInt(document.getElementById(`user-${currency}-amount`).innerText) - global_price; } }; xhr[0].send(xhr[1]); } function giveaward(t) { const kind = document.getElementById('kind').value; postToast(t, t.dataset.action, { "kind": kind, "note": document.getElementById('note').value }, () => { let owned = document.getElementById(`${kind}-owned`) let ownednum = Number(owned.textContent) - 1; owned.textContent = ownednum if (ownednum == 0) document.getElementById('giveaward').disabled=true; } ); } const awardtabs = document.getElementsByClassName('award-tab'); const awardsections = document.getElementsByClassName('award-section'); function switchAwardTab() { for (const element of awardtabs) element.classList.toggle('active') for (const element of awardsections) element.classList.toggle('d-none') }