Bobbit6k
TTypebot
•Created by Bobbit6k on 4/23/2024 in #help-and-questions
Override Value of a {{Variable}}
Hi Guys:
how to override the value of a {{Variable}}?
This is my (stupid) script.
The {{Test}} variable is not updated, but when i output it in console it is :-/.
What i'm doing wrong?
Thanks!
(function() {
const apiDomain = {{LinkImmo}}; // DO NOT TOUCH
const url =
{{Test}} = jsonResponse; console.log("Test is " + {{Test}}); return {{Test}}; }) .catch(error => { console.error('Error processing:', error); return 'Error retrieving data'; }); })();
https://corsproxy.io/?${encodeURIComponent(apiDomain)}
;
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.text();
})
.then(htmlContent => {
const pattern = /<script id="NEXT_DATA" type="application/json">\s({.?})\s*</script>/s;
const matches = htmlContent.match(pattern);
if (!matches) {
console.error('JSON content not found in HTML');
return 'Error retrieving data';
}
const jsonContent = matches[1];
const data = JSON.parse(jsonContent).props.pageProps.detailData.realEstate.properties[0];
const keysToExclude = ['adLinks', 'cadastrals', 'caption', 'defaultDescription', 'features', 'ga4features', 'id', 'income', 'land', 'multimedia', 'reference', 'rent', 'roomForRent', 'typologyValue'];
keysToExclude.forEach(key => delete data[key]);
const jsonResponse = Object.entries(data).map(([key, value]) => {
if (typeof value === 'object' && value !== null) {
return ${key}\t${JSON.stringify(value)}
;
}
return ${key}\t${value}
;
}).join('\n');
{{Test}} = jsonResponse; console.log("Test is " + {{Test}}); return {{Test}}; }) .catch(error => { console.error('Error processing:', error); return 'Error retrieving data'; }); })();
8 replies