PageSourceSearch

https://dynamic-salmiakki-095693.netlify.app/data-clearing-fix.js

js dynamic-salmiakki-095693.netlify.app collected 2026-10-03 10:40:29 UTC 4,703 bytes, 101 lines download raw bytes

1// Data Clearing Fix for Fancy UI and Relationship Panel Issues
2// This function clears all previous data and UI state for fresh searches
3
4function clearAllPreviousDataAndUI() {
5    console.log('🧹 [DataClearing] Clearing previous fancy UI data and infoboxes (optimized)');
6    
7    // More selective clearing - only remove stale infoboxes, not all UI elements
8    const infoboxSelectors = [
9        '.wikipedia-infobox',           // Main infobox class from main.js
10        '.infoboxes-container',         // Container class from main.js  
11        '.fancy-ui-preview',            // Fancy UI container from fancy-ui-preview.js
12        '.infobox-json-display'         // JSON display from infobox-json-extractor.js
13    ];
14    
15    let removedCount = 0;
16    infoboxSelectors.forEach(selector => {
17        const elements = document.querySelectorAll(selector);
18        elements.forEach(el => {
19            // Only remove if it's not currently being updated (has loading state)
20            if (!el.classList.contains('updating') && !el.classList.contains('streaming')) {
21                console.log('🗑️ [DataClearing] Removing stale infobox element:', el.className || el.id, selector);
22                el.remove();
23                removedCount++;
24            } else {
25                console.log('⏸️ [DataClearing] Preserving active element:', el.className || el.id);
26            }
27        });
28    });
29    
30    console.log(`🗑️ [DataClearing] Removed ${removedCount} stale infobox elements (preserved active ones)`);
31    
32    // Clear global infobox data storage but preserve conversation state
33    if (window.currentInfoboxData) {
34        console.log('🗑️ [DataClearing] Clearing currentInfoboxData');
35        window.currentInfoboxData = null;
36    }
37    
38    // Don't clear lastSearchData as it may be needed for follow-up queries
39    // window.lastSearchData = null; // COMMENTED OUT to preserve context
40    
41    // Clear wikipediaMetadata only if it's from a previous search
42    if (window.wikipediaMetadata && !window.wikipediaMetadata.isCurrentSearch) {
43        console.log('🗑️ [DataClearing] Clearing old wikipediaMetadata');
44        window.wikipediaMetadata = null;
45    }
46    
47    // Clear any cached JSON data
48    if (window.extractedInfoboxData) {
49        window.extractedInfoboxData = null;
50    }
51    
52    // Only close relationship panel if it's not actively being used
53    const existingPanel = document.querySelector('.relationship-info-panel');
54    if (existingPanel && !existingPanel.classList.contains('active')) {
55        console.log('🗑️ [DataClearing] Removing inactive relationship panel');
56        existingPanel.remove();
57    }
58    
59    // Don't clear relationship map data if it's currently active
60    if (window.relationshipMapInstance && !window.relationshipMapInstance.isActive) {
61        console.log('🗑️ [DataClearing] Clearing inactive relationship map visualization');
62        if (typeof window.relationshipMapInstance.clearVisualization === 'function') {
63            window.relationshipMapInstance.clearVisualization();
64        }
65        if (typeof window.relationshipMapInstance.hideRelationshipInfo === 'function') {
66            window.relationshipMapInstance.hideRelationshipInfo();
67        }
68    }
69    
70    console.log('✅ [DataClearing] Optimized data clearing completed - preserved active UI state');
71}
72
73// Enhanced clearing function specifically for JSON extraction
74function clearAllPreviousDataBeforeExtraction() {
75    console.log('🧹 [DataClearing] Pre-extraction clearing of stale infoboxes (selective)');
76    
77    // More selective DOM clearing before JSON extraction
78    const staleInfoboxes = document.querySelectorAll('.wikipedia-infobox:not(.updating), .infoboxes-container:not(.streaming), .fancy-ui-preview:not(.active)');
79    let preExtractionRemovedCount = 0;
80    
81    staleInfoboxes.forEach(el => {
82        // Check if this infobox contains old data by looking at its content
83        console.log('🗑️ [DataClearing] Pre-extraction removing:', el.className || el.id);
84        el.remove();
85        preExtractionRemovedCount++;
86    });
87    
88    console.log(`🗑️ [DataClearing] Pre-extraction removed ${preExtractionRemovedCount} elements`);
89    
90    // Clear any remaining cached data
91    if (window.extractedInfoboxData) {
92        console.log('🗑️ [DataClearing] Clearing cached extraction data');
93        window.extractedInfoboxData = null;
94    }
95    
96    console.log('✅ [DataClearing] Pre-extraction clearing completed');
97}
98
99// Make functions globally available
100window.clearAllPreviousDataAndUI = clearAllPreviousDataAndUI;
101window.clearAllPreviousDataBeforeExtraction = clearAllPreviousDataBeforeExtraction;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.