User:Polygnotus/Scripts/Surveys.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 13:
try {
// Look for the surveyData.json content in the module
const jsonMatchjsonStart = moduleText.matchindexOf(/'"resources\/ext\.quicksurveys\.lib\/surveyData\.json":\s*(\[[\s\S]*?\])/');
if (!jsonMatchjsonStart === -1) {
console.log('No survey data found in module');
return [];
}
// Clean upFind the JSONstart stringof - remove any trailing commas before closingthe bracketsarray
letconst jsonStringarrayStart = jsonMatchmoduleText.indexOf('[1]', jsonStart);
jsonStringif = jsonString.replace(/,(\s*[\]}])/g,arrayStart '$=== -1'); {
console.log('RawNo JSONarray found:', jsonString.substring(0,in 200)survey + '...data');
return [];
}
// Find the matching closing bracket
let bracketCount = 0;
let arrayEnd = arrayStart;
for (let i = arrayStart; i < moduleText.length; i++) {
if (moduleText[i] === '[') bracketCount++;
if (moduleText[i] === ']') bracketCount--;
if (bracketCount === 0) {
arrayEnd = i + 1;
break;
}
}
let jsonString = moduleText.substring(arrayStart, arrayEnd);
console.log('Extracted JSON length:', jsonString.length);
console.log('JSON preview:', jsonString.substring(0, 300) + '...');
console.log('Raw JSON found:', jsonString.substring(0, 200) + '...');
const surveyData = JSON.parse(jsonString);
console.log('Found survey data:', surveyData);