diff --git a/files/assets/js/award_modal.js b/files/assets/js/award_modal.js index d5d45756e..b91e4d69c 100644 --- a/files/assets/js/award_modal.js +++ b/files/assets/js/award_modal.js @@ -1,5 +1,5 @@ document.getElementById('awardModal').addEventListener('show.bs.modal', function (event) { - document.getElementById("awardTarget").action = event.relatedTarget.dataset.url; + document.getElementById("awardTarget").action = event.relatedTarget.dataset.url; }); // TODO: Refactor this ugly shit who wrote this lmao @@ -9,7 +9,7 @@ function vote(type, id, dir) { const scoretexts = document.getElementsByClassName(type + '-score-' + id); for (let i=0; i= 200 && xhr.status < 300 && response && !response.error; - const slotsResult = document.getElementById("casinoSlotsResult"); - slotsResult.classList.remove("text-success", "text-danger"); + const succeeded = + xhr.status >= 200 && xhr.status < 300 && response && !response.error; + const slotsResult = document.getElementById("casinoSlotsResult"); + slotsResult.classList.remove("text-success", "text-danger"); - if (succeeded) { - const { game_state, gambler } = response; - const state = JSON.parse(game_state); - const reels = Array.from(document.querySelectorAll(".reel")); - const symbols = state.symbols.split(","); + if (succeeded) { + const { game_state, gambler } = response; + const state = JSON.parse(game_state); + const reels = Array.from(document.querySelectorAll(".reel")); + const symbols = state.symbols.split(","); - for (let i = 0; i < 3; i++) { - reels[i].innerHTML = symbols[i]; - } + for (let i = 0; i < 3; i++) { + reels[i].innerHTML = symbols[i]; + } - slotsResult.style.visibility = "visible"; - slotsResult.innerText = state.text; + slotsResult.style.visibility = "visible"; + slotsResult.innerText = state.text; - if (state.text.includes("Won")) { - if (state.text.includes("Jackpot")) { - slotsResult.classList.add("text-warning"); - } else { - slotsResult.classList.add("text-success"); - } - } else if (state.text.includes("Lost")) { - slotsResult.classList.add("text-danger"); - } + if (state.text.includes("Won")) { + if (state.text.includes("Jackpot")) { + slotsResult.classList.add("text-warning"); + } else { + slotsResult.classList.add("text-success"); + } + } else if (state.text.includes("Lost")) { + slotsResult.classList.add("text-danger"); + } - updatePlayerCoins(gambler); - } else { - slotsResult.style.visibility = "visible"; - slotsResult.innerText = response.error; - slotsResult.classList.add("text-danger"); + updatePlayerCoins(gambler); + } else { + slotsResult.style.visibility = "visible"; + slotsResult.innerText = response.error; + slotsResult.classList.add("text-danger"); - console.error(response.error); - } + console.error(response.error); + } - document.getElementById("casinoSlotsBet").disabled = false; - document.getElementById("casinoSlotsPull").disabled = false; + document.getElementById("casinoSlotsBet").disabled = false; + document.getElementById("casinoSlotsPull").disabled = false; } // Blackjack // When the casino loads, look up the "blackjack status" of a player to either start a new game or continue an existing game. if ( - document.readyState === "complete" || - (document.readyState !== "loading" && !document.documentElement.doScroll) + document.readyState === "complete" || + (document.readyState !== "loading" && !document.documentElement.doScroll) ) { - checkBlackjackStatus(); + checkBlackjackStatus(); } else { - document.addEventListener("DOMContentLoaded", checkBlackjackStatus); + document.addEventListener("DOMContentLoaded", checkBlackjackStatus); } function checkBlackjackStatus() { - const xhr = new XMLHttpRequest(); - xhr.open("get", "/casino/blackjack"); - xhr.onload = handleBlackjackStatusResponse.bind(null, xhr); - xhr.send(); + const xhr = new XMLHttpRequest(); + xhr.open("get", "/casino/blackjack"); + xhr.onload = handleBlackjackStatusResponse.bind(null, xhr); + xhr.send(); } function handleBlackjackStatusResponse(xhr) { - let response; + let response; - try { - response = JSON.parse(xhr.response); - } catch (error) { - console.error(error); - } + try { + response = JSON.parse(xhr.response); + } catch (error) { + console.error(error); + } - const succeeded = - xhr.status >= 200 && xhr.status < 300 && response && !response.error; + const succeeded = + xhr.status >= 200 && xhr.status < 300 && response && !response.error; - if (succeeded) { - if (response.active) { - updateBlackjack(response.game_state); - } - } else { - console.error("error"); - } + if (succeeded) { + if (response.active) { + updateBlackjack(response.game_state); + } + } else { + console.error("error"); + } } // When starting a new game or taking an action in an existing one, a new state will be returned, and the DOM must be updated. function updateBlackjack(state) { - const { player, dealer, status } = state; - const lettersToSuits = { - S: "♠️", - H: "♥️", - C: "♣️", - D: "♦️", - "?": "?", - }; - const suitsToColors = { - "♠️": "black", - "♥️": "red", - "♣️": "black", - "♦️": "red", - "?": "black", - }; + const { player, dealer, status } = state; + const lettersToSuits = { + S: "♠️", + H: "♥️", + C: "♣️", + D: "♦️", + "?": "?", + }; + const suitsToColors = { + "♠️": "black", + "♥️": "red", + "♣️": "black", + "♦️": "red", + "?": "black", + }; - // Clear everything. - Array.from(document.querySelectorAll(".playing-card")).forEach((card) => { - card.innerText = ""; - card.style.color = "unset"; - card.classList.remove("dealt"); - }); + // Clear everything. + Array.from(document.querySelectorAll(".playing-card")).forEach((card) => { + card.innerText = ""; + card.style.color = "unset"; + card.classList.remove("dealt"); + }); - // Show dealer cards. - const dealerSlots = Array.from( - document.querySelectorAll('.playing-card[data-who="dealer"]') - ); - for (let i = 0; i < dealer.length; i++) { - const slot = dealerSlots[i]; + // Show dealer cards. + const dealerSlots = Array.from( + document.querySelectorAll('.playing-card[data-who="dealer"]') + ); + for (let i = 0; i < dealer.length; i++) { + const slot = dealerSlots[i]; - if (slot) { - // Technically, the dealer can use more than 5 cards, though it's rare. - // In that case, the result message is good enough. - // Thanks, Carp. 🐠 - slot.classList.add("dealt"); + if (slot) { + // Technically, the dealer can use more than 5 cards, though it's rare. + // In that case, the result message is good enough. + // Thanks, Carp. 🐠 + slot.classList.add("dealt"); - if (i > 0 && status === "active") { - break; - } + if (i > 0 && status === "active") { + break; + } - const rank = dealer[i][0]; - const suit = lettersToSuits[dealer[i][1]]; - const card = rank + suit; - slot.innerText = card; - slot.style.color = suitsToColors[suit]; - } - } + const rank = dealer[i][0]; + const suit = lettersToSuits[dealer[i][1]]; + const card = rank + suit; + slot.innerText = card; + slot.style.color = suitsToColors[suit]; + } + } - // Show player cards. - const playerSlots = Array.from( - document.querySelectorAll('.playing-card[data-who="player"]') - ); - for (let i = 0; i < player.length; i++) { - const slot = playerSlots[i]; - const rank = player[i][0]; - const suit = lettersToSuits[player[i][1]]; - const card = rank + suit; - slot.innerText = card; - slot.style.color = suitsToColors[suit]; - slot.classList.add("dealt"); - } + // Show player cards. + const playerSlots = Array.from( + document.querySelectorAll('.playing-card[data-who="player"]') + ); + for (let i = 0; i < player.length; i++) { + const slot = playerSlots[i]; + const rank = player[i][0]; + const suit = lettersToSuits[player[i][1]]; + const card = rank + suit; + slot.innerText = card; + slot.style.color = suitsToColors[suit]; + slot.classList.add("dealt"); + } - updateBlackjackActions(state); + updateBlackjackActions(state); - if (status !== "active") { - revealBlackjackResult(state); - } + if (status !== "active") { + revealBlackjackResult(state); + } } function revealBlackjackResult(state) { - const blackjackResult = document.getElementById("casinoBlackjackResult"); - const lookup = { - bust: ["Bust. Didn't work out for you, did it?", "danger"], - push: ["Pushed. This whole hand never happened.", "secondary"], - insured_loss: ["Lost, but at least you had insurance.", "secondary"], - lost: ["Lost. That was pathetic.", "danger"], - won: ["Won. This time.", "success"], - blackjack: ["Blackjack! Must be your lucky day.", "warning"], - }; - const [resultText, resultClass] = lookup[state.status]; + const blackjackResult = document.getElementById("casinoBlackjackResult"); + const lookup = { + bust: ["Bust. Didn't work out for you, did it?", "danger"], + push: ["Pushed. This whole hand never happened.", "secondary"], + insured_loss: ["Lost, but at least you had insurance.", "secondary"], + lost: ["Lost. That was pathetic.", "danger"], + won: ["Won. This time.", "success"], + blackjack: ["Blackjack! Must be your lucky day.", "warning"], + }; + const [resultText, resultClass] = lookup[state.status]; - blackjackResult.style.visibility = "visible"; - blackjackResult.innerText = resultText; - blackjackResult.classList.add(`text-${resultClass}`); + blackjackResult.style.visibility = "visible"; + blackjackResult.innerText = resultText; + blackjackResult.classList.add(`text-${resultClass}`); } function buildBlackjackAction(id, method, title, fullWidth = false) { - return ` + return ` - - - - + + + + + - -
-
- Blackjack -
-
-
Give us a moment to fix things.
-
+ +
+
+ Blackjack +
+
+
+
+ +
+
+
+
+
+ Dealer +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Player +
+
+
+
+
+
+ +
+
+
+
Enter Bet
+
+ +
+
+ +
+
+ + +
+
+ + +
+
+
+ +
+ +
+
+
+
+
+
{% include "lottery.html" %}
+ {% endblock %} -
{% include "lottery.html" %}
-{% endblock %} diff --git a/files/templates/comments.html b/files/templates/comments.html index d6704d7df..4b1c4d51f 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -324,7 +324,7 @@ {% endif %} - {{score}} + {{score}} {% if voted==-1 %} @@ -336,7 +336,7 @@ - {{score}} + {{score}} @@ -348,7 +348,7 @@ - {{score}} + {{score}} @@ -383,7 +383,7 @@ {% endif %} {% if v and request.path.startswith('/@') and v.admin_level < 2 %} @@ -436,7 +436,7 @@ diff --git a/files/templates/settings.html b/files/templates/settings.html index 935e98da0..6882b4387 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -166,7 +166,7 @@ - {% if request.path == '/settings/security' %} + {% if request.path == '/settings/security' %}