From abb451bee92ae588d7501c9aff34331f4b853ef4 Mon Sep 17 00:00:00 2001 From: Steveo Date: Sun, 15 Feb 2026 15:25:12 +1000 Subject: [PATCH 1/3] Optimize data fetching and cube refresh performance --- js/api-manager.js | 39 ++++++++------------------------------- js/object-renderer.js | 32 +++++++++++++++++++++++++++----- js/ui-controller.js | 14 +++----------- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/js/api-manager.js b/js/api-manager.js index 4f92dc3..861a951 100644 --- a/js/api-manager.js +++ b/js/api-manager.js @@ -99,7 +99,7 @@ function getExchangeRate() { // Check if coin is a privacy coin - if not, chop head off - checkIfPrivacyCoin(processedData.coinId, processedData.coinSymbol); + updatePrivacyCoinIndicator(processedData.coinSymbol, processedData.isPrivacyCoin); // Dispatch custom event instead of relying on localStorage polling @@ -128,7 +128,7 @@ function getExchangeRate() { function extractCoinData(data) { try { - const { id, symbol, image, links, market_cap_rank, market_data } = data; + const { id, symbol, image, links, market_cap_rank, market_data, categories = [] } = data; return { coinId: id, @@ -144,7 +144,8 @@ function extractCoinData(data) { coinSymbol: symbol.toUpperCase(), coinRank: Number.isFinite(market_cap_rank) ? `#${market_cap_rank}` : "", coinThumb: image.thumb, - coinURL: links.homepage[0] + coinURL: links.homepage[0], + isPrivacyCoin: categories.includes('Privacy Coins') }; } catch (error) { console.error("Error extracting coin data:", error); @@ -231,33 +232,9 @@ function logCoinData(coinData) { const cachedPrivacyElement = (() => document.getElementById("isPrivacyCoin"))(); -async function checkIfPrivacyCoin(coinId, coinSymbol) { - try { - const url = `${API_CONFIG.BASE_URL}/coins/${coinId}?x_cg_demo_api_key=${API_CONFIG.API_KEY}`; - const response = await fetch(url); - - if (!response.ok) { - throw new Error(`Failed to fetch coin data for: ${coinId}`); - } - - const coinData = await response.json(); - const categories = coinData.categories || []; - const isPrivacy = categories.includes('Privacy Coins'); - - // Log to console (not Xbox) - - console.log(`${coinSymbol} - is privacy coin: ${isPrivacy}`); - - // Update HTML element - - cachedPrivacyElement && (cachedPrivacyElement.style.display = isPrivacy ? "block" : "none"); - - return isPrivacy; - } catch (error) { - console.error("Error checking privacy coin status:", error); - cachedPrivacyElement && (cachedPrivacyElement.style.display = "none"); - return false; - } +function updatePrivacyCoinIndicator(coinSymbol, isPrivacyCoin) { + console.log(`${coinSymbol} - is privacy coin: ${isPrivacyCoin}`); + cachedPrivacyElement && (cachedPrivacyElement.style.display = isPrivacyCoin ? "block" : "none"); } // Create a predictive search @@ -449,4 +426,4 @@ async function loadCoinsList() { // Export for use in other modules -window.getExchangeRate = getExchangeRate; \ No newline at end of file +window.getExchangeRate = getExchangeRate; diff --git a/js/object-renderer.js b/js/object-renderer.js index 847ce37..4efd5eb 100644 --- a/js/object-renderer.js +++ b/js/object-renderer.js @@ -160,6 +160,7 @@ let mouseDown = false, let dragSpeedX = 0, dragSpeedY = 0; let ambientLight, pointLight; +let cachedEnvMap; // Cube rotation mappings for navigation buttons @@ -303,7 +304,7 @@ function getUserLevel(id, fallback = 0) { return Math.min(10, Math.max(0, v)); } -function createCubeGeometry(size, detail) { +function createCubeGeometry(size) { const roundLevel = getUserLevel("rNumber", 0); const smoothLevel = getUserLevel( "smoothnessLevel", @@ -334,10 +335,14 @@ function createCubeGeometry(size, detail) { // Function to load a HDRI image and create an environment map non GPS function createEnvironmentMap() { + if (cachedEnvMap) { + return cachedEnvMap; + } + const textureLoader = new THREE.TextureLoader(); - const envMap = textureLoader.load("img/pc-reflection-2.jpg"); - envMap.mapping = THREE.EquirectangularReflectionMapping; - return envMap; + cachedEnvMap = textureLoader.load("img/pc-reflection-2.jpg"); + cachedEnvMap.mapping = THREE.EquirectangularReflectionMapping; + return cachedEnvMap; } // Shoving these material settings on to the 3D object @@ -675,6 +680,21 @@ function renderTextWithoutTitle( // Update these please +function disposeCube(targetCube) { + if (!targetCube) return; + + targetCube.geometry?.dispose(); + + const materials = Array.isArray(targetCube.material) + ? targetCube.material + : [targetCube.material]; + + materials.forEach((material) => { + material?.map?.dispose(); + material?.dispose?.(); + }); +} + function refreshCube() { if (!cube) { createCube(); @@ -692,8 +712,10 @@ function refreshCube() { // Remove the old cube and create a new one, because it's fun and trending to be new - scene.remove(cube); + const oldCube = cube; + scene.remove(oldCube); createCube(); + disposeCube(oldCube); // Apply the saved rotation to the new cool cube diff --git a/js/ui-controller.js b/js/ui-controller.js index 82690ea..dbd3182 100644 --- a/js/ui-controller.js +++ b/js/ui-controller.js @@ -38,6 +38,7 @@ function initializeUI() { setupPlayPauseToggle(); setupURLManagement(); setupThemeControls(); + setupMusicMuteToggle(); setupClipboardCopy(); setupPanelDragging(); setupBackgroundObserver(); @@ -176,20 +177,12 @@ function setupGetStatsButton() { const currentCoin = document.getElementById("coin")?.value; if (!currentCoin) return; - const exchangeRate = await window.getExchangeRate(currentCoin); - console.log(`Exchange Rate for ${currentCoin}: ${exchangeRate}`); + await window.getExchangeRate(); + console.log(`Exchange Rate updated for ${currentCoin}`); updateURLParam("coin", currentCoin); - if (window.coinSymbol) { - await window.getExchangeRate(window.coinSymbol); - console.log(`Button Press - Coin Symbol: ${window.coinSymbol}`); - updateURLParam("msg", window.coinSymbol); - const textInput = document.getElementById("textInput"); - if (textInput) { - textInput.value = window.coinSymbol; - } } } catch (error) { console.error("Error occurred:", error); @@ -268,7 +261,6 @@ function setupMusicMuteToggle() { }); } -setupMusicMuteToggle(); function setupThemeButtons() { const goldButton = document.getElementById("goldTheme"); const blackButton = document.getElementById("blackTheme"); From cf98cd69dd56b0d6cb9910e516dd82492cbb4c47 Mon Sep 17 00:00:00 2001 From: QuirkyRobots Date: Wed, 18 Feb 2026 18:58:01 +1000 Subject: [PATCH 2/3] Test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8fb268f..648e890 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +CXTST ## v4.1 * New rounding option added From 8f6a5fb3729f319828176d6d08c4cc568d4888c7 Mon Sep 17 00:00:00 2001 From: QuirkyRobots Date: Wed, 18 Feb 2026 19:01:44 +1000 Subject: [PATCH 3/3] Test 2 --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 581a614..40b6c21 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - +