From 7abbf4b4e0059bb0de07c788e596731c5303b66b Mon Sep 17 00:00:00 2001
From: Lucio Zambon <lucio.zambon@elettra.eu>
Date: Thu, 1 Aug 2024 01:38:14 +0000
Subject: [PATCH] Update talk.js

---
 speech/talk.js | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/speech/talk.js b/speech/talk.js
index b2511d5..672a7a0 100644
--- a/speech/talk.js
+++ b/speech/talk.js
@@ -52,6 +52,7 @@
 	}
 	let keepAlive = false;
 	const ancestor = [];
+	const ancestorName = [];
 	const names = [];
 	let aliveTimer = -1;
 	function startRec() {
@@ -228,11 +229,15 @@
 				// $('#search').hide(); $('#open').hide();
 			}
 			if (mode=='ujive' && locale[lang].ujive.indexOf(tok)==-1) {
+				if (locale[lang].go == tok && txt.split(' ').length<2) return;
+				if (locale[lang].go == tok) tok = txt.split(' ')[1];
+				if (locale[lang].number == tok && txt.split(' ').length<2) return;
 				if (locale[lang].number == tok) tok = txt.split(' ')[1];
-				showLog('ujive1: '+tok+', tok: '+tok);
+				showLog('ujive1, tok: '+tok);
 				if (typeof locale[lang].num[tok] !== 'undefined') tok = locale[lang].num[tok];
-				if (!isNaN(tok)) {ancestor.push(tok); tok = 'n'+ancestor.join('_');}
-				if (locale[lang].back.indexOf(tok)>-1) {ancestor.pop(); showLog('ujive2b: '+tok+', tok: n'+ancestor.join('_')); return;}
+				// let pushed = false; <------------------------------------------------------------------------------------------------------------------
+				if (!isNaN(tok)) {/*pushed = true; ancestor.push(tok);*/ tok = ('n'+ancestor.join('_')+'_'+tok).replace('n_','n');}
+				if (locale[lang].back == tok) {ancestor.pop(); ancestorName.pop(); showLog('ujive2b: '+tok+', tok: n'+ancestor.join('_')); return;}
 				showLog('ujive2: '+tok+', tok: '+tok);
 				if (locale[lang].up.indexOf(tok)>-1) tok = 'up';
 				if (locale[lang].down.indexOf(tok)>-1) tok = 'down';
@@ -242,8 +247,14 @@
 				showLog('ujive4: '+tok+', tok: '+tok);
 				const token = document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: '';
 				const snd = './talk.php?ctree='+tok+token;
-				showLog('ujive: '+tok+', snd: '+snd);
-				fetch(snd).then((response) => {return response.json();}).then((rlocale) => {showLog(rlocale); alert(rlocale);});
+				showLog('ujive: '+tok+', snd: '+snd+', ancestor: '+ancestor.join('/'));
+				fetch(snd).then((response) => {return response.text();}).then((rlocale) => {
+					showLog('resp: '+rlocale+', '+ancestor.join('/'));
+					const res = rlocale.split('_');
+					if (/*!pushed &&*/ !isNaN(res[0]) && res.length>1) {ancestor.push(res[0]); ancestorName.push(res[1]);}
+					$('#ctree').html(ancestorName.join('/'));
+				})
+				.catch( (e) => {console.log('err: '+e+' in '+snd);});
 			}
 			if (locale[lang].ujive.indexOf(tok)>-1) {
 				$('#search').hide(); $('#open').hide(); $('#tree').show(); $('#chart').hide();
@@ -254,6 +265,8 @@
 				fetch(snd).then((response) => {return response.json();}).then((rlocale) => {showLog(rlocale); alert(rlocale);});
 				mode = 'ujive';
 				ancestor.length = 0;
+				ancestorName.length = 0;
+				$('#ctree').html('');
 				txt = txt.replace(tok, '').replace(' ', '');
 			}
 			if (locale[lang].list.indexOf(tok)>-1) {
-- 
GitLab