From 0fe765c3910632d528352965b2e05692eb43f33d Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 9 Apr 2024 16:44:01 +0200 Subject: [PATCH] add commas for coins and mbux --- files/assets/js/casino/game_screen.js | 12 ++++++------ files/assets/js/core.js | 6 ++++++ files/assets/js/userpage_v.js | 18 ++++++++---------- files/templates/casino/game_screen.html | 4 ++-- files/templates/header.html | 8 ++++---- files/templates/userpage/banner.html | 8 ++++---- files/templates/util/html_head.html | 2 +- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/files/assets/js/casino/game_screen.js b/files/assets/js/casino/game_screen.js index 2271efe96..4aff946cc 100644 --- a/files/assets/js/casino/game_screen.js +++ b/files/assets/js/casino/game_screen.js @@ -12,15 +12,15 @@ function initializeGame() { function updatePlayerCurrencies(updated) { if (updated.coins) { - document.getElementById("user-coins-amount").textContent = updated.coins; - document.getElementById("user-coins-amount-mobile").textContent = updated.coins; - document.getElementById("user-coins-amount-casino").textContent = updated.coins; + document.getElementById("user-coins-amount").textContent = formatter.format(updated.coins); + document.getElementById("user-coins-amount-mobile").textContent = formatter.format(updated.coins); + document.getElementById("user-coins-amount-casino").textContent = formatter.format(updated.coins); } if (updated.marseybux) { - document.getElementById("user-bux-amount").textContent = updated.marseybux; - document.getElementById("user-bux-amount-mobile").textContent = updated.marseybux; - document.getElementById("user-bux-amount-casino").textContent = updated.marseybux; + document.getElementById("user-bux-amount").textContent = formatter.format(updated.marseybux); + document.getElementById("user-bux-amount-mobile").textContent = formatter.format(updated.marseybux); + document.getElementById("user-bux-amount-casino").textContent = formatter.format(updated.marseybux); } } diff --git a/files/assets/js/core.js b/files/assets/js/core.js index a42a24b4e..94cb3094b 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -796,3 +796,9 @@ function toggleElement(id, id2) { document.getElementById(id).classList.toggle('d-none'); document.getElementById(id2).focus() } + +const formatter = new Intl.NumberFormat('en-US'); +function change_currency(id, amount) { + const el = document.getElementById(id) + el.textContent = formatter.format(parseInt(el.textContent.replaceAll(',', '')) + amount); +} diff --git a/files/assets/js/userpage_v.js b/files/assets/js/userpage_v.js index 22188fe84..749ffedbe 100644 --- a/files/assets/js/userpage_v.js +++ b/files/assets/js/userpage_v.js @@ -29,11 +29,10 @@ function transferCoins(t, mobile=false) { "reason": document.getElementById(mobile ? "coin-transfer-reason-mobile" : "coin-transfer-reason").value }, () => { - const newcoins = parseInt(document.getElementById("user-coins-amount").textContent) - amount; - document.getElementById("user-coins-amount").textContent = newcoins; - document.getElementById("user-coins-amount-mobile").textContent = newcoins; - document.getElementById("profile-coins-amount-mobile").textContent = parseInt(document.getElementById("profile-coins-amount-mobile").textContent) + transferred; - document.getElementById("profile-coins-amount").textContent = parseInt(document.getElementById("profile-coins-amount").textContent) + transferred; + change_currency("user-coins-amount", -amount) + change_currency("user-coins-amount-mobile", -amount) + change_currency("profile-coins-amount", amount) + change_currency("profile-coins-amount-mobile", amount) } ); } @@ -54,11 +53,10 @@ function transferBux(t, mobile=false) { "reason": document.getElementById(mobile ? "bux-transfer-reason-mobile" : "bux-transfer-reason").value }, () => { - const newbux = parseInt(document.getElementById("user-bux-amount").textContent) - amount; - document.getElementById("user-bux-amount").textContent = newbux; - document.getElementById("user-bux-amount-mobile").textContent = newbux; - document.getElementById("profile-bux-amount-mobile").textContent = parseInt(document.getElementById("profile-bux-amount-mobile").textContent) + amount; - document.getElementById("profile-bux-amount").textContent = parseInt(document.getElementById("profile-bux-amount").textContent) + amount; + change_currency("user-bux-amount", -amount) + change_currency("user-bux-amount-mobile", -amount) + change_currency("profile-bux-amount", amount) + change_currency("profile-bux-amount-mobile", amount) } ); } diff --git a/files/templates/casino/game_screen.html b/files/templates/casino/game_screen.html index a24630b67..5c141a12d 100644 --- a/files/templates/casino/game_screen.html +++ b/files/templates/casino/game_screen.html @@ -46,7 +46,7 @@ coin - {{v.coins}} + {{v.coins|commas}} @@ -56,7 +56,7 @@ marseybux - {{v.marseybux}} + {{v.marseybux|commas}} diff --git a/files/templates/header.html b/files/templates/header.html index 16046ff4a..a3249a3d5 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -341,9 +341,9 @@
{{v.username}}
-
coins{{v.coins}}{% if not FEATURES['MARSEYBUX'] %} Coin{{macros.plural(v.coins)}}{% endif %}
+
coins{{v.coins|commas}}{% if not FEATURES['MARSEYBUX'] %} Coin{{macros.plural(v.coins)}}{% endif %}
{% if FEATURES['MARSEYBUX'] %} -
marseybux{{v.marseybux}}
+
marseybux{{v.marseybux|commas}}
{% endif %}
@@ -420,12 +420,12 @@ diff --git a/files/templates/userpage/banner.html b/files/templates/userpage/banner.html index 553a7e82b..6c2ff7bff 100644 --- a/files/templates/userpage/banner.html +++ b/files/templates/userpage/banner.html @@ -106,11 +106,11 @@ mutes {{u.mute_count}} user{{'s' if u.mute_count != 1 else ''}} - {{u.coins}} + {{u.coins|commas}} coins {% if FEATURES['MARSEYBUX'] %} - {{u.marseybux}} + {{u.marseybux|commas}} marseybux {% endif %} @@ -421,11 +421,11 @@ mutes {{u.mute_count}} user{{'s' if u.mute_count != 1 else ''}} - {{u.coins}} + {{u.coins|commas}} coins {% if FEATURES['MARSEYBUX'] %} - {{u.marseybux}} + {{u.marseybux|commas}} marseybux {% endif %} diff --git a/files/templates/util/html_head.html b/files/templates/util/html_head.html index 51f07f9b0..02bd5aa77 100644 --- a/files/templates/util/html_head.html +++ b/files/templates/util/html_head.html @@ -43,7 +43,7 @@ u.username ~ "'s profile" %} {% set description %} - {{u.coins}} coins - Joined {{u.created_date}} - + {{u.coins|commas}} coins - Joined {{u.created_date}} - {%- if u.stored_subscriber_count >=1 and not u.is_private -%} {{u.stored_subscriber_count}} Followers - {%- endif -%}