Darshee245 commited on
Commit
786a044
Β·
verified Β·
1 Parent(s): c91e4ec

Update frontend/script.js

Browse files
Files changed (1) hide show
  1. frontend/script.js +43 -1
frontend/script.js CHANGED
@@ -1970,4 +1970,46 @@ window.checkTrueFalseAnswer = function(selected) {
1970
  function showTrueFalseResults(container) {
1971
  var percentage = Math.round((tfScore / (tfQuestions.length * 10)) * 100);
1972
  container.innerHTML = '<div class="game-results-large"><div class="results-emoji">' + (percentage >= 70 ? 'πŸ†' : 'πŸ“š') + '</div><h2>True or False Complete!</h2><div class="final-score-large">Score: ' + tfScore + '/' + (tfQuestions.length * 10) + '</div><div class="score-percentage-large">' + percentage + '%</div><div class="results-buttons"><button class="play-again-btn" onclick="selectGame(\'true-false\')">πŸ”„ Play Again</button><button class="back-to-games-btn" onclick="showGameSelectionScreen()">← Back to Games</button></div></div>';
1973
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1970
  function showTrueFalseResults(container) {
1971
  var percentage = Math.round((tfScore / (tfQuestions.length * 10)) * 100);
1972
  container.innerHTML = '<div class="game-results-large"><div class="results-emoji">' + (percentage >= 70 ? 'πŸ†' : 'πŸ“š') + '</div><h2>True or False Complete!</h2><div class="final-score-large">Score: ' + tfScore + '/' + (tfQuestions.length * 10) + '</div><div class="score-percentage-large">' + percentage + '%</div><div class="results-buttons"><button class="play-again-btn" onclick="selectGame(\'true-false\')">πŸ”„ Play Again</button><button class="back-to-games-btn" onclick="showGameSelectionScreen()">← Back to Games</button></div></div>';
1973
+ }
1974
+
1975
+ // ================= FIX: Handle /api/config and /api/predict calls =================
1976
+ // If any part of your frontend calls /api/config or /api/predict,
1977
+ // redirect them to /api/chat
1978
+
1979
+ // Override fetch to handle /api/config and /api/predict
1980
+ const originalFetch = window.fetch;
1981
+ window.fetch = function(url, options) {
1982
+ // If the URL is /api/config, return mock config
1983
+ if (typeof url === 'string' && url.includes('/api/config')) {
1984
+ return Promise.resolve(new Response(JSON.stringify({
1985
+ status: "success",
1986
+ config: {
1987
+ api_url: "/api/chat",
1988
+ version: "2.0",
1989
+ features: {
1990
+ audio: true,
1991
+ video: true,
1992
+ reports: true,
1993
+ learning: true,
1994
+ games: true
1995
+ }
1996
+ }
1997
+ }), {
1998
+ headers: { 'Content-Type': 'application/json' }
1999
+ }));
2000
+ }
2001
+
2002
+ // If the URL is /api/predict, redirect to /api/chat
2003
+ if (typeof url === 'string' && url.includes('/api/predict')) {
2004
+ // Modify the URL to use /api/chat instead
2005
+ const newUrl = url.replace('/api/predict', '/api/chat');
2006
+ return originalFetch(newUrl, options);
2007
+ }
2008
+
2009
+ // Otherwise, use the original fetch
2010
+ return originalFetch(url, options);
2011
+ };
2012
+
2013
+ console.log("βœ… Cortexa JS Full Version Loaded Successfully!");
2014
+ console.log("πŸ”— API URL:", API_URL);
2015
+ console.log("πŸ’‘ /api/config and /api/predict requests are now handled automatically!");