From 9bf1406796b0912b2f21a7eaee15cff4f7083f26 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 17 May 2026 23:23:33 +0300 Subject: [PATCH] Auto-deploy: 2026-05-17 23:23:33 --- content.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/content.js b/content.js index 4fd1c95..d838910 100644 --- a/content.js +++ b/content.js @@ -1057,20 +1057,24 @@ Brief honest assessment of this opportunity for my profile` if (!response.ok) throw new Error('API Request failed'); const data = await response.json(); + if (!data.candidates || !data.candidates[0].content) { + throw new Error('API blocked or returned empty response.'); + } let resultText = data.candidates[0].content.parts[0].text; - resultText = resultText.replace(/```json/g, '').replace(/```/g, '').trim(); + resultText = resultText.replace(/```json/gi, '').replace(/```/g, '').trim(); let results; try { - const match = resultText.match(/\[[\s\S]*\]/); - if (match) { - results = JSON.parse(match[0]); + const startIdx = resultText.indexOf('['); + const endIdx = resultText.lastIndexOf(']'); + if (startIdx !== -1 && endIdx !== -1) { + results = JSON.parse(resultText.substring(startIdx, endIdx + 1)); } else { results = JSON.parse(resultText); } } catch(e) { - console.error(resultText); - throw new Error('Failed to parse AI response'); + console.error("AI JSON Parse Error. Raw Response:", resultText); + throw new Error('JSON Error: ' + resultText.substring(0, 80)); } results.forEach(res => {