From 09d2d629991b8308a4045e98fc67aa567b32a78a Mon Sep 17 00:00:00 2001 From: Spicy_Marinara Date: Wed, 15 Oct 2025 02:03:54 +0200 Subject: [PATCH] Make all Info Box fields editable even when not generated - always show widgets with placeholder values --- index.js | 204 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 144 insertions(+), 60 deletions(-) diff --git a/index.js b/index.js index e465652..d838c2a 100644 --- a/index.js +++ b/index.js @@ -2054,74 +2054,72 @@ function renderInfoBox() { `; - // Weather widget - emoji with forecast text - if (data.weatherEmoji) { - html += ` -
-
${data.weatherEmoji}
- ${data.weatherForecast ? `
${data.weatherForecast}
` : ''} -
- `; - } + // Weather widget - always show (editable even if empty) + const weatherEmoji = data.weatherEmoji || '🌀️'; + const weatherForecast = data.weatherForecast || 'Weather'; + html += ` +
+
${weatherEmoji}
+
${weatherForecast}
+
+ `; - // Temperature widget - thermometer visual - if (data.temperature) { - const tempPercent = Math.min(100, Math.max(0, ((data.tempValue + 20) / 60) * 100)); - const tempColor = data.tempValue < 10 ? '#4a90e2' : data.tempValue < 25 ? '#67c23a' : '#e94560'; - html += ` -
-
-
-
-
-
+ // Temperature widget - always show (editable even if empty) + const tempDisplay = data.temperature || '20Β°C'; + const tempValue = data.tempValue || 20; + const tempPercent = Math.min(100, Math.max(0, ((tempValue + 20) / 60) * 100)); + const tempColor = tempValue < 10 ? '#4a90e2' : tempValue < 25 ? '#67c23a' : '#e94560'; + html += ` +
+
+
+
+
-
${data.temperature}
- `; - } +
${tempDisplay}
+
+ `; - // Time widget - clock visual - if (data.timeStart) { - // Parse time for clock hands - const timeMatch = data.timeStart.match(/(\d+):(\d+)/); - let hourAngle = 0; - let minuteAngle = 0; - if (timeMatch) { - const hours = parseInt(timeMatch[1]); - const minutes = parseInt(timeMatch[2]); - hourAngle = (hours % 12) * 30 + minutes * 0.5; // 30Β° per hour + 0.5Β° per minute - minuteAngle = minutes * 6; // 6Β° per minute - } - html += ` -
-
-
-
-
-
-
-
-
${data.timeStart}
-
- `; + // Time widget - always show (editable even if empty) + const timeDisplay = data.timeStart || '12:00'; + // Parse time for clock hands + const timeMatch = timeDisplay.match(/(\d+):(\d+)/); + let hourAngle = 0; + let minuteAngle = 0; + if (timeMatch) { + const hours = parseInt(timeMatch[1]); + const minutes = parseInt(timeMatch[2]); + hourAngle = (hours % 12) * 30 + minutes * 0.5; // 30Β° per hour + 0.5Β° per minute + minuteAngle = minutes * 6; // 6Β° per minute } + html += ` +
+
+
+
+
+
+
+
+
${timeDisplay}
+
+ `; html += '
'; - // Row 2: Location widget (full width) - if (data.location) { - html += ` -
-
-
-
πŸ“
-
-
${data.location}
+ // Row 2: Location widget (full width) - always show (editable even if empty) + const locationDisplay = data.location || 'Location'; + html += ` +
+
+
+
πŸ“
+
${locationDisplay}
- `; - } +
+ `; $infoBoxContainer.html(html); @@ -2319,7 +2317,7 @@ function updateInfoBoxField(field, value) { const lines = lastGeneratedData.infoBox.split('\n'); let dateLineFound = false; let dateLineIndex = -1; - + // Find the date line for (let i = 0; i < lines.length; i++) { if (lines[i].includes('πŸ—“οΈ:')) { @@ -2328,7 +2326,7 @@ function updateInfoBoxField(field, value) { break; } } - + const updatedLines = lines.map((line, index) => { if (field === 'month' && line.includes('πŸ—“οΈ:')) { const parts = line.split(','); @@ -2401,6 +2399,92 @@ function updateInfoBoxField(field, value) { } } + // If editing weather but no weather line exists, create one + if ((field === 'weatherEmoji' || field === 'weatherForecast')) { + let weatherLineFound = false; + for (const line of updatedLines) { + // Check if this is a weather line (has emoji and forecast, not one of the special fields) + if (line.match(/^[^:]+:\s*.+$/) && !line.includes('πŸ—“οΈ') && !line.includes('🌑️') && !line.includes('πŸ•’') && !line.includes('πŸ—ΊοΈ') && !line.includes('Info Box') && !line.includes('---')) { + weatherLineFound = true; + break; + } + } + + if (!weatherLineFound) { + const dividerIndex = updatedLines.findIndex(line => line.includes('---')); + if (dividerIndex >= 0) { + let newWeatherLine = ''; + if (field === 'weatherEmoji') { + newWeatherLine = `${value}: Weather`; + } else if (field === 'weatherForecast') { + newWeatherLine = `🌀️: ${value}`; + } + // Insert after date line if it exists, otherwise after divider + const dateIndex = updatedLines.findIndex(line => line.includes('πŸ—“οΈ:')); + const insertIndex = dateIndex >= 0 ? dateIndex + 1 : dividerIndex + 1; + updatedLines.splice(insertIndex, 0, newWeatherLine); + } + } + } + + // If editing temperature but no temperature line exists, create one + if (field === 'temperature') { + const tempLineFound = updatedLines.some(line => line.includes('🌑️:')); + if (!tempLineFound) { + const dividerIndex = updatedLines.findIndex(line => line.includes('---')); + if (dividerIndex >= 0) { + const newTempLine = `🌑️: ${value}`; + // Find last non-empty line before creating position + let insertIndex = dividerIndex + 1; + for (let i = 0; i < updatedLines.length; i++) { + if (updatedLines[i].includes('πŸ—“οΈ:') || updatedLines[i].match(/^[^:]+:\s*.+$/)) { + insertIndex = i + 1; + } + } + updatedLines.splice(insertIndex, 0, newTempLine); + } + } + } + + // If editing time but no time line exists, create one + if (field === 'timeStart') { + const timeLineFound = updatedLines.some(line => line.includes('πŸ•’:')); + if (!timeLineFound) { + const dividerIndex = updatedLines.findIndex(line => line.includes('---')); + if (dividerIndex >= 0) { + const newTimeLine = `πŸ•’: ${value} β†’ ${value}`; + // Find last non-empty line before creating position + let insertIndex = dividerIndex + 1; + for (let i = 0; i < updatedLines.length; i++) { + if (updatedLines[i].includes('πŸ—“οΈ:') || updatedLines[i].includes('🌑️:') || updatedLines[i].match(/^[^:]+:\s*.+$/)) { + insertIndex = i + 1; + } + } + updatedLines.splice(insertIndex, 0, newTimeLine); + } + } + } + + // If editing location but no location line exists, create one + if (field === 'location') { + const locationLineFound = updatedLines.some(line => line.includes('πŸ—ΊοΈ:')); + if (!locationLineFound) { + const dividerIndex = updatedLines.findIndex(line => line.includes('---')); + if (dividerIndex >= 0) { + const newLocationLine = `πŸ—ΊοΈ: ${value}`; + // Insert at the end (before any empty lines) + let insertIndex = updatedLines.length; + for (let i = updatedLines.length - 1; i >= 0; i--) { + if (updatedLines[i].trim() !== '') { + insertIndex = i + 1; + break; + } + } + updatedLines.splice(insertIndex, 0, newLocationLine); + } + } + } + lastGeneratedData.infoBox = updatedLines.join('\n'); // Update the message's swipe data